Skip to content

Instantly share code, notes, and snippets.

View jasonLaster's full-sized avatar

Jason Laster jasonLaster

View GitHub Profile
@jasonLaster
jasonLaster / ConsoleTricks.html
Created February 27, 2011 21:47
WebKit Console tricks adapted from CSS Ninja's excellent tutorial http://bit.ly/fi4lnK
<html>
<body>
<script type="text/javascript" charset="utf-8">
// CONSOLE log
var foo = {baz: "tubular", goo: "rad"}, bar = "baz";
console.log("string",1,foo.goo,bar,foo.baz); // string 1 rad baz tubular
console.log(foo)
// CONSOLE Printf
var foo = {baz: "tubular", goo: "rad"}, bar = "baz";
@jasonLaster
jasonLaster / Examples.rb
Created July 31, 2011 04:11
Try methods
def double(num)
return num * 2
end
puts "TRY"
puts nil.try(:to_s, 0) #=> 0
puts 5.try(:to_s, 0) #=> "5"
puts
puts "PTRY"
@jasonLaster
jasonLaster / Reference.md
Created January 24, 2012 21:13
Markdown Reference

Mou

Mou icon

Overview

Mou, the missing Markdown editor for web developers.

Syntax

@jasonLaster
jasonLaster / gist:2296962
Created April 4, 2012 01:27
DERANGEMENT
%% CLOSED-FORM DERANGEMENT
function d = derangements(n)
numerator = (ones(1,n+1)*-1).^(0:n);
denomerator = arrayfun(@factorial, 0:n);
factorial_terms = numerator ./ denomerator;
d = sum(factorial(n) * factorial_terms)
%% RECURSIVE DERANGEMENT
function der = deraangements_rec(n)
der = NaN(1,n);
%% 2.2.20 BREAKS
n = 10^5;
breaks = rand(n,2);
maxbreak = max(breaks')';
minbreak = min(breaks')';
triangles = and(and(minbreak <.5, (1-maxbreak<.5)), (maxbreak - minbreak) < .5);
sum(triangles)/n
%% 2.2.20 BREAKS
n = 10^5;
breaks = rand(n,2);
maxbreak = max(breaks')';
minbreak = min(breaks')';
triangles = and(and(minbreak <.5, (1-maxbreak<.5)), (maxbreak - minbreak) < .5);
sum(triangles)/n
%data
%human_data = ...
%comp_data = ...
% find the number of rounds played
hrounds = size(human_data,1);
crounds = size(comp_data,1);
% find the beginning of the different games
first_col = @(data, ncols) data(data < ncols);
% 7.1 4
if false
px = [1/4 1/4 1/2];
n = 10;
d = nconv(px, n);
x = 1:size(d,2);
disp(sprintf('The distribution for %1.0f games is:', n))
plot(x, d, 'o')
disp(d')
@jasonLaster
jasonLaster / Factorial.py
Created June 15, 2012 19:55
CodeStack -- Factorial Example
# dumb recursive factorial
def fact(n):
if (n <= 1):
return 1
else:
return n * fact(n - 1)
print fact(6)
class decorate():
def __init__(self, func, *a):
self.func = func
def __call__(self, *a):
return self.func(*a)
@decorate
def func(arg):