Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
hughfdjackson / sleep.js
Created October 4, 2011 12:04
javascript sleep function
// WARNINGS:: This function is *relatively* untested (i.e. there is no formal testing as of yet). Use at your own risk.
// It is normally MUCH better to use setTimeout or requestAnimationFrame than to block in a single-threaded environment, be KIND to your users
// This function is best suited to testing the behaviour of an application when intensive processing occurs
function sleep(ms){
var initial = +new Date()
while(+new Date() < initial + ms){}
}
@hughfdjackson
hughfdjackson / gist:1266494
Created October 6, 2011 04:04 — forked from anonymous/gist:1266473
omatase_ - pastebin.com/DSaZDqvG
{
publishers: {},
fire: function (event) {
for (var i = 0; i < this.publishers[this.uid][event].length; i++) {
// call each listener's function
this.publishers[this.uid][event][i].listener[this.publishers[this.uid][event][i].func]();
}
},
addListener: function (uid, listener, func, event) {
@hughfdjackson
hughfdjackson / gist:1274380
Created October 9, 2011 23:46 — forked from anonymous/gist:1274367
josh99 - pastebin.com/2fbiMMxM
var age, foo;
age = 99;
foo = function() {
return age = 0;
};
foo();
console.log(age); # => 0
------------------------
@hughfdjackson
hughfdjackson / gist:1274397
Created October 10, 2011 00:02
scope craziness
// ON the behaviour of 'var'less variable declaration
// if you do this:
function foo(){
age = 99
}
@hughfdjackson
hughfdjackson / gist:1300007
Created October 19, 2011 23:42 — forked from anonymous/gist:1299957
usman - pastebin.com/1qzEnZiD
<?php
if(isset($_POST['submit1'])) {
$var1=$_POST['submit1']
echo "it works1";
}
echo " ";
if(isset($_POST['submit2'])) {
echo "it works2";
}
@hughfdjackson
hughfdjackson / gist:1300010
Created October 19, 2011 23:44 — forked from anonymous/gist:1299973
usman - usman
<html>
<form action="form.php" method="post">
<input type="submit" id="submit1" name="submit1" value="Click Me1" onclick="document.getElementbyId("submit1").value=itworks1">
<br />
<input type="submit" id="submit2" name="submit2" value="Click Me2" onclick="document.getElementbyId("submit2").value=itworks2">
<br />
<input type="submit" id="submit3" name="submit3" value="Click Me3" onclick="document.getElementbyId("submit3").value=itworks3">
<br />
function colorScheme(r, g, b){
return function(callback){
return callback(r, g, b)
}
}
function darken(darken_by){
return function(r, g, b){
@hughfdjackson
hughfdjackson / gist:1389925
Created November 23, 2011 21:10 — forked from anonymous/gist:1389924
dibs - pastebin.com/BiNQ55LA
...
message: function(x){
return "with for loop this would return. " + x;
},
calculate: function(){
var _this = this
jQuery.each(fees_table, function (i, v) {
//console.dir(v);
$('#multiple_date_select').multiDatesPicker({
numberOfMonths: 3,
dateFormat: 'mm/dd/yy',
altField: '#meeting_dates',
addDisabledDates: json_data.meeting_dates,
minDate: json_data.start_date,
maxDate: json_data.end_date
});
// want to do this
!function(){
var scroll = window.onscroll || function(){}
window.onscroll = function(){
scroll()
instance.scrolled += 1
}
}()