Skip to content

Instantly share code, notes, and snippets.

View dalmaer's full-sized avatar

Dion Almaer dalmaer

View GitHub Profile
@dalmaer
dalmaer / phantom.example.pizza.js
Created April 11, 2011 01:07
A phantom.js example
if (phantom.state.length === 0) {
phantom.state = 'pizza';
phantom.open('http://www.google.com/m/local?site=local&q=pizza+nyc');
} else {
var list = document.querySelectorAll('div.bf');
for (var i in list) {
console.log(list[i].innerText);
}
phantom.exit();
}
@dalmaer
dalmaer / phantom.example.location.js
Created April 11, 2011 01:09
Phantom.js example with location
var cb = function (data) {
var loc = data.city;
if (data.region_name.length > 0)
loc = loc + ', ' + data.region_name;
console.log('IP address: ' + data.ip);
console.log('Estimated location: ' + loc);
phantom.exit();
};
var el = document.createElement('script');
@dalmaer
dalmaer / my.sample.js
Created April 11, 2011 02:36
An example of my.js usage
scope.ready(function(my, $) {
$('button').on('click', function() {
my('box').setText('Hello World from my.js!')
.addClass('message')
.setLeft(200, {duration: 300});
});
});
@dalmaer
dalmaer / css3d.rotation.sphere.example.js
Created April 11, 2011 02:50
Paul Hayes' example of spheres with CSS
var panels = p || this.panels,
rounds = r || this.rounds,
rotationPerPanel = 360/panels,
rotationPerRound = 360/2/rounds,
yRotation, xRotation,
width = this.panelWidth,
zTranslate = (width/2) / Math.tan(rotationPerPanel * Math.PI/180),
$container = this.el,
$ul, $li, i, j;
@dalmaer
dalmaer / sample.ender.js
Created April 11, 2011 05:37
Sample code for Ender
$.script(['mod1.js', 'mod2.js'], 'base', function () {
// script is ready
});
// event driven. listen for 'base' files to load
$.script.ready('base', function () {
});
$('p').animate({
opacity: 1,
var block_clicks = function() {
var isBlocked = !blockClick;
blockClick = false;
return isBlocked;
};
// The lightbox function first does:
e = e || event;
if (e.ctrlKey || e.shiftKey ||
(e.which && (e.which === 2 || e.which === 3)) ||
Edge::add = (nick, name, complete) {
@client.select 15
user = User.find! {id: nick}
puzzle = Puzzle.find! {name: name}
err, data = client.set! "u:#{user}:p:#{puzzle}"
complete()
}
/* Keyfram-licious animation */
@-webkit-keyframes colors {
0% {background-color: #39f;}
15% {background-color: #F246C9;}
30% {background-color: #4453F2;}
45% {background-color: #44F262;}
60% {background-color: #F257D4;}
75% {background-color: #EDF255;}
90% {background-color: #F20006;}
100% {background-color: #39f;}
amb_run(function(amb, fail){
/* <preamble> */
// utility function to test if two strings are adjacent
function adjacent(str1, str2) {
return str1.charAt(str1.length - 1) == str2.charAt(0);
}
// input data
var w1 = amb([ "the", "that", "a" ]);
var w2 = amb([ "frog", "elephant", "thing" ]);
var w3 = amb([ "walked", "treaded", "grows" ]);
var file = jDataView.createBuffer(
0x10, 0x01, 0x00, 0x00, // Int32 - 272
0x90, 0xcf, 0x1b, 0x47, // Float32 - 39887.5625
0, 0, 0, 0, 0, 0, 0, 0, // 8 blank bytes
0x4d, 0x44, 0x32, 0x30, // String - MD20
0x61 // Char - a
);
// Now we use the DataView as defined in the specification, the only thing that changes is the j before jDataView.