Skip to main content

Home/ InfokeyDEV/ Group items tagged code

Rss Feed Group items tagged

12More

Groovy - Regular Expressions - 0 views

  • Groovy supports regular expressions natively using the ~"pattern" expression
    • Benx Shen
       
      Groovy 對於 regexp 的支援有 3 個特殊的表示方式:
      ~"pattern" (create java.util.regex.Pattern)=~ (create java.util.regex.Matcher)==~ (do Matcher.matches() )
  • // lets create a regex Pattern def pattern = ~/foo/ assert pattern instanceof Pattern
  • Groovy also supports the =~ (create Matcher) and ==~ (matches regex) operators.
  • ...6 more annotations...
  • Since a Matcher coerces to a boolean by calling its find method, the =~ operator is consistent with the simple use of Perl's =~ operator, when it appears as a predicate (in 'if', 'while', etc.). The "stricter-looking" ==~ operator requires an exact match of the whole subject string.
  • def matcher = "\$abc." =~ /\$(.*)\./ // no need to double-escape! assert "\\\$(.*)\\." == /\$(.*)\./ matcher.matches(); // must be invoked assert matcher.group(1) == "abc" // is one, not zero
  • def m = "foobarfoo" =~ /o(b.*r)f/ assert m[0][1] == "bar"
  • // lets create a Matcher def matcher = "cheesecheese" =~ /cheese/ assert matcher instanceof Matcher answer = matcher.replaceAll("edam")
    • Benx Shen
       
      以下是一些 groovy regexp 的程式碼,請特別注意劃線的部份!
  • // fancier group demo matcher = "\$abc." =~ "\\\$(.*)\\." matcher.matches(); // must be invoked [Question: is this still true? Not in my experience with jsr-04.] assert matcher.group(1) == "abc" // is one, not zero
    • Benx Shen
       
      這裡需要特別注意的是,如果想要使用 matcher.group() 方法,那麼必須先執行 matcher.matches() 方法呼叫(我記得呼叫 find() 也行)。然而,如果是直接使用 groovy 的語法,那麼就可以直接使用 matcher[0][?] 的用法了!
15More

A re-introduction to JavaScript - MDC - 1 views

  • var name = o && o.getName();
  • var name = otherName || "default";
  • The first argument to apply() is the object that should be treated as 'this'.
  • ...9 more annotations...
  • apply() has a sister function named call, which again lets you set 'this' but takes an expanded argument list as opposed to an array.
  • Closures
  • A closure is the combination of a function and the scope object in which it was created. Closures let you save state - as such, they can often be used in place of objects.
  • An unfortunate side effect of closures is that they make it trivially easy to leak memory in Internet Explorer.
  • The above code sets up the element to turn red when it is clicked. It also creates a memory leak. Why? Because the reference to el is inadvertently caught in the closure created for the anonymous inner function. This creates a circular reference between a JavaScript object (the function) and a native object (el).
  • delete el;
  • var clickHandler = function() { this.style.backgroundColor = 'red'; } (function() { var el = document.getElementById('el'); el.onclick = clickHandler; })();
  • Surprisingly, one trick for breaking circular references introduced by a closure is to add another closure:
  • It's useful to start with an idea of the language's history. JavaScript was created in 1995 by Brendan Eich, an engineer at Netscape, and first released with Netscape 2 early in 1996. It was originally going to be called LiveScript, but was renamed in an ill-fated marketing decision to try to capitalise on the popularity of Sun Microsystem's Java language — despite the two having very little in common. This has been a source of confusion ever since.
  •  
    Chinese new year animals horoscope2016 Happy Chinese new year 2016 messages & quotes Happy new year 2016 greetings for Chinese Chinese new year 2016 funny poems
  •  
    Chinese new year animals horoscope2016
    Happy Chinese new year 2016 messages & quotes
    Happy new year 2016 greetings for Chinese
    Chinese new year 2016 funny poems
3More

Javascript - Event order - 0 views

  • When you use event capturing | | ---------------| |----------------- | element1 | | | | -----------| |----------- | | |element2 \ / | | | ------------------------- | | Event CAPTURING | ----------------------------------- the event handler of element1 fires first, the event handler of element2 fires last. Event bubbling When you use event bubbling / \ ---------------| |----------------- | element1 | | | | -----------| |----------- | | |element2 | | | | | ------------------------- | | Event BUBBLING | ----------------------------------- the event handler of element2 fires first, the event handler of element1 fires last.
  • addEventListener() method explained on the Advanced models page. If its last argument is true the event handler is set for the capturing phase, if it is false the event handler is set for the bubbling phase.
  • In the Microsoft model you must set the event’s cancelBubble property to true. window.event.cancelBubble = true In the W3C model you must call the event’s stopPropagation() method. e.stopPropagation()

air jordan 4 teal for cheap 13 overall pick in the first round - 0 views

started by linlnina on 11 Mar 15 no follow-up yet
1More

TeamViewer 10 Crack License Code+Serial Keygen Premium - 0 views

  •  
    TeamViewer 10 Crack License Code+Serial Keygen Premium Edition is newest as well as amazing software regarding consumers it's very valuable software. It's
3More

Groovy - Groovy Categories - 0 views

  • import groovy.xml.* def html = DOMBuilder.newInstance().html { head { title (class:'mytitle', 'Test') } body { p (class:'mystyle', 'This is a test.') } } use (groovy.xml.dom.DOMCategory.class) { assert html.head.title.text() == 'Test' assert html.body.p.text() == 'This is a test.' assert html.find{ it.tagName == 'body' }.tagName == 'body' assert html.getElementsByTagName('*').grep{ it.'@class' }.size() == 2 }
    • Benx Shen
       
      這裡是一個範例,可以看到透過 DOMCategory 的協助,xml dom 元素的存取直接可以用 "expression" 的方式就可以很方便地取用,而不需要很囉唆地 getElement() 或之類的
1More

CleanMyMac 3.7.1 Crack Mac OS + Activation Code {50MB} - 0 views

  •  
    CleanMyMac 3.7.1 Crack Mac OS + Activation Code best & new version of the Apple MacBook OS Sierra which is the great experienced to cleaning
1More

SpyHunter 4.3 Crack Plus Serial Code Full App Download - 0 views

  •  
    SpyHunter 4.3 Crack Plus Serial Code Full App by "Enigma Software Group" has received a very mixed response over the years. SpyHunter is a useful antivirus.

buy nike kd 7 easy money and the tags and style code number are 100 - 0 views

started by huhu789 on 19 Nov 14 no follow-up yet
1More

VIPRE Advanced Security 10.1.4.33 Crack & Activation Code (Lifetime) Update - 0 views

  •  
    VIPRE Advanced Security 10.1.4.33 Crack & Activation Key Code is professional premium app that secure your email protection and PC malware virus safety
1More

iMobie PhoneClean Pro 3.6.2 [Crack + License Code] Full Free - 0 views

  •  
    iMobie PhoneClean Pro 3.6.2 Crack+License Code & Serial Key is the best cleaner for iPhone users.It is completely easy and comprehensive cleaning solution

buy nike what the kd 7 after deciding to buy the slippers - 0 views

started by linlin1023 on 15 Jun 15 no follow-up yet

nike kd 7 for sale casual and classic golf shoes - 0 views

started by hanhan789 on 08 Jan 15 no follow-up yet

cheap nike air foamposite pro volt every other thursday - 0 views

started by hanhan789 on 18 Dec 14 no follow-up yet

buy nike lebron 12 data throw in chin straps - 0 views

started by yuelin on 21 Oct 14 no follow-up yet

nike flyknit lunar 3 wholesale putting ourselves as much in harm way - 0 views

started by lshfang on 27 Mar 15 no follow-up yet
1 - 20 of 134 Next › Last »
Showing 20 items per page