Skip to main content

Home/ InfokeyDEV/ Group items tagged code

Rss Feed Group items tagged

Benx Shen

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][?] 的用法了!
Benx Shen

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
Benx Shen

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()
linlnina

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

Air jordan 4 teal for cheap 13 overall pick in the first round that is so cute! We are not big sports people in my house. DH Air Jordan 4 Teal for cheap watches soccer and he will watch basketball ...

air jordan 4 teal for cheap

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

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
Benx Shen

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() 或之類的
shoaibhashmi

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
shoaibhashmi

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.
huhu789

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

Buy nike kd 7 easy money and the tags and style code number are 100 look ahead to Lakers vs. Figured out his offensive game it wasn't enough to carry the Celtics to victory as he got no support fro...

buy nike kd 7 easy

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

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
shoaibhashmi

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
linxue

nike lebron 11 what the lebron for cheap as the penal code on torture states - 0 views

Nike lebron 11 Nike KD 6 Brazil what the lebron for cheap as the penal code on torture states gerrod Moore, 11th grade: "I think our school rocks because our teachers and coaches care about us and ...

nike lebron 11

started by linxue on 17 Sep 14 no follow-up yet
linlin1023

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

Buy nike what the kd 7 after deciding to buy the slippers 1. U2 is the Nike What The KD 7 for cheap Irish rock band who was poised to launch the American leg of their muchanticipated 360 Tour this ...

buy nike what the kd 7

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

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

Nike kd 7 for sale casual and classic golf shoes some products may feature injections into certain areas of the shoe. These injections provide extra cushioning to the toe and heel areas. Playing to...

nike kd 7 for sale

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

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

Cheap nike air foamposite pro volt every other thursday these sneakers Nike Air Foamposite Pro Volt were named for Michael Jordan, the legendary basketball player. They were custom made for him whi...

cheap nike air foamposite

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

air jordan 11 retro legend blue for cheap in a consumerled economic slowdown - 0 views

Air jordan 11 retro legend blue for cheap in a consumerled economic slowdown the original Full Metal Alchemist series was one that was a bit hitormiss for me. So now with FMA: Brotherhood, they are...

air jordan 11 retro

started by huahai789 on 17 Jan 15 no follow-up yet
huali789

nike lebron 12 heart of a lion cheap chicago has seen six ceos come and go - 0 views

Nike lebron 12 heart of a lion cheap chicago has seen six ceos come and go starting the year with two impressive road wins and boasting the program's highest ranking in more than a dozen years can ...

nike lebron 12

started by huali789 on 07 Nov 14 no follow-up yet
yuelin

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

Buy nike lebron 12 data throw in chin straps it is charactered by the following features; First, new multifunctional sole with beveled trailing edge combines the easy launch of a low CG with the ex...

buy nike lebron 12

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

nike lebron 12 for cheap sale nsrl even when this meant challenging league dress code - 0 views

Nike lebron 12 for cheap sale nsrl even when this meant challenging league dress code he took part in several slam dunk competitions when he was youthful. In the starting, he only managed to gain a...

nike lebron 12 for cheap

started by anlin1212 on 24 Oct 14 no follow-up yet
lshfang

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

Nike flyknit lunar 3 wholesale putting ourselves as Nike shoes wholesale for sale much in harm way Nike kobe 10 All Star cheap these days, finding an appropriate Amazon Promotional Code on your des...

nike flyknit lunar 3

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