Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
crazy4groovy / gist:1684615
Created January 26, 2012 19:38 — forked from fennb/gist:1124535
node.js proxy server in 20 lines of JS (via http://www.catonmat.net/http-proxy-in-nodejs/)
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, request.headers['host'])
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
});
proxy_response.addListener('end', function() {
@crazy4groovy
crazy4groovy / helloGroovyFX.groovy
Created April 3, 2012 15:55 — forked from deanriverson/helloGroovyFX.groovy
A basic GroovyFX HelloWorld program
@Grab('org.codehaus.groovyfx:groovyfx:0.1')
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
//source: http://pleasingsoftware.blogspot.ca/2012/03/groovyfx-first-official-release.html
//run: groovy -classpath $JAVAFX_HOME/rt/lib/jfxrt.jar helloGroovyFX.groovy
GroovyFX.start {
def sg = new SceneGraphBuilder()
@crazy4groovy
crazy4groovy / gist:2370716
Created April 12, 2012 20:19 — forked from Mottie/gist:1491097
jQuery images loaded function
/*
Check if all images are loaded
- Callback occurs when all images are loaded
- image load errors are ignored (complete will be true)
- Use:
$('.wrap img').imagesLoaded(function(){
alert('all images loaded');
});
*/
@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 / 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
// This is a comparison between Haskell and Groovy based on some simple problems found in the following
// Haskell Introduction:
// http://learnyouahaskell.com/starting-out#ready-set-go
// Ex 1. If we have two lists, [2,5,10] and [8,10,11] and we want to get the products of all the possible
// combinations between numbers in those lists, here's what we'd do.
/* HASKELL */
[ x*y | x <- [2,5,10], y <- [8,10,11]]
@crazy4groovy
crazy4groovy / example.js
Created March 19, 2013 13:33 — forked from kirbysayshi/example.js
Example pub/sub - similar to jQuery.Callbacks()
var s = new Signal(), cb = function(a, b){ console.log('callback', arguments, this); };
s.add(cb);
s.add(cb);
s.dispatch('for', 'science', '!', 1);
s.remove(cb);
s.dispatch('for', 'science', '!', 2);
s.remove(cb);
s.dispatch('for', 'science', '!', 3);
@crazy4groovy
crazy4groovy / README.md
Created March 19, 2013 13:37 — forked from kirbysayshi/README.md
allow it to be used in the browser or nodejs

This Is Absolutely Tiring

Every time I start a node module, or a new JS project, I'm confronted with this same question: how do I structure it to allow it to be used in the browser or nodejs, without requiring a build step, and without getting in the way of my development?

While developing, I typically create some type of [browser-based environment][]; Firebug and Web Inspector are still miles ahead of anything else we've got. Ideally I want to be able to add a file via a script tag, and have that be the only requirement.

As @visionmedia [points out][], this is [ridiculous][].

This gist is meant to compile all of the various ways I've seen of guarding against/for a variety of module systems. Fork it and add your own, I'll try to bring them into this one.

@crazy4groovy
crazy4groovy / PubSub.md
Last active December 15, 2015 20:59 — forked from cowboy/HEY-YOU.md
// Cross browser, backward compatible solution
(function( window, Date ) {
// feature testing
var raf = window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame;
window.animLoop = function( render, element ) {
var running, lastFrame = +new Date;