Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts

  • jmaglasang 6:01 pm on September 18, 2009 Permalink | Reply
    Tags: JavaScripts   

    Extracting Text Between Words(Pattern) using Regex in JavaScript 

    Below are the ways to extract text between words in javascript:

    Given the String “Name: John Berkins Address: LA, USA”

    
    	var data = "Name: John Berkins Address: LA, USA";
    
    	//using String.indexOf + String.substring
    	var name = data.substring(data.indexOf("Name:")+6,data.indexOf("Address"));
    	var addr = data.substring(data.indexOf("Address:") + 9);
    	alert(name);
    	alert(addr);	
    
    	//using Regex (with the use of Non-Capturing Group(?:)
    	var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
    	var raddr = data.match(/(?:Address:)(.*)/)[1];
    	alert(rname);
    	alert(raddr);
    
    	//Note: the regex  code above may not work if the data contains \n (newline character)
    	//      this is because of the (.+) expression cannot disregards \n chars,
    	//      the workaround is to change it to anoter expression or to remove the \n char before
    	//		the extraction process: h
    	//Example:
    	//
    	//data = data.replace(/\n/g,' ');
    	//var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
    	//var raddr = data.match(/(?:Address:)(.*)/)[1];
    
     
  • jmaglasang 11:43 am on August 12, 2009 Permalink | Reply  

    Generating Unique Strings in Javascript 

    Here is a simple way to generate a unique string in javascript.

        var ts = (new Date()).getTime().toString();
        var url = "ajaxHandler.php?param1=value1&paramn=valuen&t=" + ts;
        //do ajax call...
    

    This method is very helpful for ajax developers, to overcome the problem of cached ajax requests in IE.

     
  • jmaglasang 11:28 am on July 29, 2009 Permalink | Reply
    Tags: ASP NET   

    Setting the Page Title in ASP NET from Server Code 

    Here is a quick n easy way to set the HTML Page Title from the server side, that most developers don’t know yet.

    VBNET:

    Me.Header.Title = "Title Here"

    C#:

    this.Header.Title = "Title Here";
     
  • jmaglasang 1:57 pm on April 30, 2009 Permalink | Reply  

    TextArea SelectedText, SelectionStart, SelectionEnd, SelStart, SelEnd (IE and FireFox) 

    Simple way of getting the html textarea’s selection properties selectedText, selectionStart, selectionEnd:

    Javascript:

     function getTextAreaSelection() {
       var textArea = document.getElementById('textarea1');
       if (document.selection) { //IE
           var bm = document.selection.createRange().getBookmark();
           var sel = textArea.createTextRange();
           sel.moveToBookmark(bm);
    
           var sleft = textArea.createTextRange();
           sleft.collapse(true);
           sleft.setEndPoint("EndToStart", sel);
           textArea.selectionStart = sleft.text.length
           textArea.selectionEnd = sleft.text.length + sel.text.length;
           textArea.selectedText = sel.text;
       }
       else if (textArea.selectionStart){ //FF
          textArea.selectedText = textArea.substring(textArea.selectionStart,textArea.selectionEnd);
       }
    
       alert("Selection Start==> " + textArea.selectionStart + "\n" +
          "Selection End  ==> " + textArea.selectionEnd + "\n" +
          "Selected Text  ==> " + textArea.selectedText + "\n" +
          "TextArea Value ==> " + textArea.value);
     }
    

    HTML:

    <textarea id="textarea1"></textarea> <button onclick="getTextAreaSelection()">Get Selection Info</button>
    
     
    • Jim 7:50 am on September 6, 2009 Permalink | Reply

      What if the selected text is repeated within the content?

      “textArea.value.indexOf” will return the first instance of the selected text, but that may not be the text that is actually selected, they are just the same because they are repeated.

      For example: “My name is Fred, and his name is John.”

      If I select the second instance of “name is”, when I run your function I will get the first. This isn’t a problem if you just want to know the text that is selected, but it is if you want to manipulate it.

    • jmaglasang 1:59 pm on September 10, 2009 Permalink | Reply

      You have a point there them, I have update the code but there is still a little problem, it cannot return the correct caret position in IE.

  • jmaglasang 12:25 pm on July 21, 2008 Permalink | Reply  

    Generating Unique Strings in NET 

    Approach 1:

    String s1 = Guid.NewGuid().ToString();
    String s2 = Guid.NewGuid().Tostring("N");
    String s3 = Guid.NewGuid().ToString("P");
    String s3 = Guid.NewGuid().ToString("D");
    [code]
    
    Approach 2:
    [code]
    String s1 = System.IO.Path.GetRandomeFileName();
    String s2 = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(),null);
    

    Comparison or the 2 Approaches:
    1. Approach1 generates at least 32 characters (0-9 and a-f) letters only.
    Hint: larger size on the database, absolutely unique.
    2. Approach2 Generates at least 8 characters (0-9 and a-z) letters.
    Hint: Good for Captcha, less size on the database,  might have duplicates

     
  • jmaglasang 4:15 am on May 7, 2008 Permalink | Reply
    Tags: ActionScript, Flash   

    Reversing Flash Timeline 

    Just recently, I have encountered a really simple problem that I have hard time figuring out the solution, but in hours of looking for that solution I just found one.

    In the web, if we search for reversing a timeline in flash, we will find mostly solutions that are done using another movie clip, but It doesn’t solve my problem. I only need to reverse the timeline without creating another movie clip.

    Here’s how I figure it out. The solution that worked for me, is to use the setInterval and the clearInterval.

    To do so, create a simple animation/tween, then on the last frame, insert the following action script:

    stop();
    var speed:Number = 40;
    function goto(destination) {
        if (_root._currentframe == destination)
           clearInterval(nIntervals);
        else
           prevFrame();
    }
    var nIntervals = setInterval(goto, speed,15);
    

    In this, example I assumed you have more than 15 frames in your animation, let say you have 60-frame animation, From frame 60 the timeline will reverse play until frame 15.

     
  • jmaglasang 8:12 am on April 11, 2008 Permalink | Reply
    Tags: Virus Tools   

    Flash Disk Virus Cleaner 

    I just found this tool in the web and find it useful, save it with .bat extension then execute. It helps a lot.

    @ECHO OFF
    cls
    echo Zabyer Flash Disk Virus Cleaner v1.0.3
    echo http://www.zabyer.org
    echo Last Updated: October 14, 2007  8:06am
    echo ---------------------------------
    echo Files that will be deleted:
    echo imgkulot, INFO.exe, Desktop.ini, scvhosts.exe
    echo TTM*.vbs, krag.exe, sysdll.exe, RavMon.exe, msv*.dll
    echo and other flash disk pest!!!
    echo ---------------------------------
    echo Resetting Stupid Virus attributes...
    echo (Disarming flash disk pest!)
    attrib -r -h -s -a autorun.*
    attrib -r -h -s -a TTM*.*
    attrib -r -h -s -a imgkulot*.*
    attrib -r -h -s -a RECYCLER\INFO.exe
    attrib -r -h -s -a RECYCLER\Desktop.ini
    attrib -r -h -s -a sysdll.exe
    attrib -r -h -s -a krag.exe
    attrib -r -h -s -a RavMon*.*
    attrib -r -h -s -a msv*.dll
    attrib -r -h -s -a scvhosts.exe
    attrib -r -h -s -a svhost.exe
    attrib -r -h -s -a C:\Windows\svhost.exe
    attrib -r -h -s -a C:\Windows\svhost32.exe
    attrib -r -h -s -a "New Folder".exe
    echo ---------------------------------
    echo Attributes Reset!
    echo Preparing Clean-Up Procedures...
    echo Next step is to delete all the pest.
    echo ---------------------------------
    pause
    echo ---------------------------------
    echo Deleting Stupid Virus...
    echo ---------------------------------
    del autorun.*
    del TTM*.*
    del imgkulot*.*
    del RECYCLER\INFO.exe
    del RECYCLER\Desktop.ini
    del sysdll.exe
    del krag.exe
    del RavMon*.*
    del msv*.dll
    del scvhosts.exe
    del svhost.exe
    del C:\Windows\svhost.exe
    del C:\Windows\svhost32.exe
    del "New Folder".exe
    echo ---------------------------------
    echo Flash Disk Cleaned-Up!
    echo ---------------------------------
    echo Please report for new virus so that this Virus Cleaner will be updated. :)
    echo Send to admin@zabyer.org or camilord@zabyer.org you feedbacks...
    echo ---------------------------------
    pause
    
     
  • jmaglasang 12:20 pm on March 7, 2008 Permalink | Reply  

    Step-by-step Creation of Executable Jar for Java 

    1. Start Command Prompt.
    2. Navigate to the folder that holds your class files:
       C:\>cd\
       C:\>cd java-code
    3. Set path to include JDK’s bin.
    	For example:
    		C:\java-code> SET PATH=%PATH%:c:\Program Files\Java\jdk1.5.0\bin
    4. Compile your class(es):
    		C:\java-code> javac TestForm.java
    		C:\java-code> javac Main.java
    5. Create a manifest file:
    	C:\java-code> echo Main-Class: Main >manifest.txt
    6. Create a jar file:
    	C:\java-code> jar cvfm welcome.jar manifest.txt Main.class TestForm.class
    7. Test your welcome.jar:
    	C:\java-code> welcome.jar
    

    And that’s it we’re done.

     
    • Belfry 2:14 pm on March 19, 2008 Permalink | Reply

      Sir,,

      sir..plss dili gyud cya mogana ang jar… error: could not find the main class.Program will exit

      sir tabang…sir plsss kani na lang gyud pag jar …

    • Agustin 8:35 pm on March 19, 2008 Permalink | Reply

      Sir,,

      Unsa diay possible cause y pagjar namu kay ni error.. ingon “could not find the main class. Program will exit.”

      libug jud sir…
      la me kabalo unsa sunod buhaton

    • Joy 7:08 pm on October 17, 2009 Permalink | Reply

      Sir,unsaon pagpadisplay sa xml data sa jtable? plz. reply…asap.. mao na kng jud na amo kulang sir… plz..
      help us…..

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel