This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copyright (C) 2011 Yusuke Yamamoto | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * | |
| **/ | |
| @Grab(group='quartz', module='quartz', version='1.5.2') | |
| @Grab(group='org.twitter4j', module='twitter4j-core', version='2.2.5') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <!-- fades well in Firefox and Chrome, hide/show only in Opera, no animation in IE 8 (?) --> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
| <style> | |
| #content { | |
| opacity: 0; | |
| -moz-transition: opacity .5s ease-in-out; | |
| -webkit-transition: opacity .5s ease-in-out; | |
| transition: opacity .5s ease-in-out; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //This is an example of how to scrape the web using PhantomJS and jQuery: | |
| //source: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery | |
| //http://phantomjs.org/ | |
| var page = new WebPage(), | |
| url = 'http://localhost/a-search-form', | |
| stepIndex = 0; | |
| /** | |
| * From PhantomJS documentation: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://groovy.codehaus.org/Using+MockFor+and+StubFor | |
| import groovy.mock.interceptor.* | |
| /*sample data class*/ | |
| class Movie { | |
| // Lots of expensive method calls, etc. | |
| } | |
| /*helper class*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| see: http://crazy4groovy.blogspot.ca/2011/03/yql-for-ebates-stores.html | |
| INTENDED FOR DEMO PURPOSES ONLY | |
| */ | |
| String endpoint = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.ebates.com%2Fstores%2Fall%2Findex.htm%22%20and%20xpath%3D%22%2F%2Fhtml%2Fbody%2Fdiv%2Fdiv%2Fdiv%2Fdiv%2Fdiv%2Fform%2Ftable%2Ftr%5B%40class%3D'store'%5D%2Ftd%5B%40class%3D'storeName'%5D%2Fstrong%2Fa%22" | |
| //println 'getting data...' | |
| def xml = endpoint.toURL().text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getTimeLeft(sDate) { | |
| sDate = sDate || "20 July, 2012"; | |
| var targetTime = (new Date(sDate)).getTime(); | |
| var currentTime = (new Date()).getTime(); | |
| var diffTime = Math.floor(Math.max(targetTime - currentTime, 0) / 1000); | |
| //alert(targetTime+'-'+currentTime+'='+diffTime); | |
| var _seconds = 1, | |
| _minutes = _seconds * 60, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* tested on PhantomJS 1.6 */ | |
| var page = require('webpage').create(), loadInProgress = false, fs = require('fs'); | |
| var htmlFiles = new Array(); | |
| // console.log(fs.workingDirectory); | |
| // console.log(phantom.args[0]); | |
| var curdir = phantom.args[0] || fs.workingDirectory; | |
| var curdirList = fs.list(curdir); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String fName = "X:\\file_cache.temp" | |
| String bakupFileExt = ".bak.${(new Date().format('yyyyMMdd_hhmmss'))}" // if blank, file will be overwritten! | |
| int keepLines = 100000 | |
| File oldF | |
| List lines | |
| try { | |
| oldF = new File(fName) | |
| lines = oldF.readLines() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // No commas | |
| def a = 'tim' | |
| def nocom = match( a ) { | |
| when 'dave' 'Hi Dave' | |
| when 'tim' 'Hi Tim' | |
| otherwise 'none of the above' | |
| } | |
| assert nocom == 'Hi Tim' | |
| // Commas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRandomNumberHigherThanAsync(minimum) { | |
| var someNumber = (Math.random()*20) + minimum; | |
| return { | |
| 'then' : function(cb){ return cb(someNumber); }, | |
| 'val' : someNumber | |
| }; | |
| } | |
| function alertMe(num) { | |
| alert(num); |