Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
crazy4groovy / TimeAvatar.groovy
Created May 22, 2012 19:26 — forked from mike-neck/TimeAvatar.groovy
inspired by image change script git://gist.github.com/1481409.git written by Yusuke Yamamoto. see https://gist.github.com/1481409
/**
* 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')
@crazy4groovy
crazy4groovy / css3FadeTransition.html
Created June 7, 2012 14:54
simple CSS3 fade-in/out transition
<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;
@crazy4groovy
crazy4groovy / jQueryPhantomScrape
Created June 18, 2012 15:47
Scrape the web using PhantomJS and jQuery
//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:
@crazy4groovy
crazy4groovy / MockFor.groovy
Created June 23, 2012 17:16
Groovy MockFor example
//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*/
@crazy4groovy
crazy4groovy / ebatesScraper.groovy
Created July 11, 2012 19:46
Sites listed on Ebates.com
/*
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
@crazy4groovy
crazy4groovy / timeLeft.js
Created July 12, 2012 01:43
Date Count Down Calculator in JavaScript
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,
@crazy4groovy
crazy4groovy / dirHtmlPageRenderToPng.js
Created July 22, 2012 15:57
PhantomJS script to loop through local directory and render HTML pages as PNG
/* 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);
@crazy4groovy
crazy4groovy / txtFileLineTrim.groovy
Created August 1, 2012 14:41
Keep only X lines from tail of text file, trim off the remainder
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()
@crazy4groovy
crazy4groovy / match.groovy
Created August 1, 2012 18:51 — forked from timyates/match.groovy
match/when implemented with Groovy's GEP-3
// 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
function getRandomNumberHigherThanAsync(minimum) {
var someNumber = (Math.random()*20) + minimum;
return {
'then' : function(cb){ return cb(someNumber); },
'val' : someNumber
};
}
function alertMe(num) {
alert(num);