Skip to content

Instantly share code, notes, and snippets.

@benfoxall
benfoxall / gist:942921
Created April 26, 2011 19:27
jQ fail on empty
$.ajax({
url: 'path-to-page.htm',
success:function(data){
if(data == ''){
return this.error();
}
alert('success');
},
error:function(){
alert('error');
@benfoxall
benfoxall / gist:975510
Created May 16, 2011 22:19
Number Generator
Number generator:
- gives a random number between 0 and N
- doesn't repeat numbers
a naive approach:
generate_1
do
@benfoxall
benfoxall / gist:976160
Created May 17, 2011 08:36
Generators.rb
class Generator
def initialize n
@n = n
@sofar = {}
end
def to_a
@n.times
end
@benfoxall
benfoxall / instructions.md
Created May 20, 2011 09:46
apache vhosts
@benfoxall
benfoxall / 21.js
Created June 2, 2011 10:02
21 (Card Game) solution
// a couple of FPish array enhancements
// gives a new array with value pushed on it
Array.prototype.$push = function(v){
var a = this.slice();
a.push(v);
return a;
}
// gives the array without selected indexes
@benfoxall
benfoxall / expanable.css
Created June 13, 2011 13:35
jQuery Expandable
li.closed ul{
display:none;
}
li a {
color:#ccc;
}
li.closed a{
color:#08f;
}
@benfoxall
benfoxall / gist:1079611
Created July 13, 2011 02:33
delta drawing
var y1 = 0, y2 = 0, y3 = 0;
var x1 = 0, x2 = width/2, x3 = width;
_(timestamp.ndeltas()).each(function(delta){
var artist = delta[0];
var v1 = delta[1];
var v2 = delta[2];
var v3 = delta[3];
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Ben Foxall">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
$.ajaxSetup({
cache: true,
jsonpCallback:function(){
var key = this.data;
var h = 0;
for (var i=0; i < key.length; i++) {
h = (h + (key.charCodeAt(i)*i)) % 10000;
}
console.log(h,key);
return '_' + h;
@benfoxall
benfoxall / hide-reveal.html
Created October 14, 2011 16:26
Reveal hidden text (without a flicker)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Ben Foxall">
<!-- Date: 2011-10-14 -->