This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.cache = function(){ | |
var _cache = {}; | |
this.store = function(n, v){ | |
_cache[n] = v; | |
return v; | |
} | |
this.fetch = function(n) { | |
if (n in _cache) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bmw = { color: 'blue', make: 'BMW' }; | |
vw = { color: 'green', make: 'VW' }; | |
function logCar(car){ | |
console.log("I'm a " + car.color + " " + car.make + "!"); | |
} | |
logCar(bmw); | |
function Car(info){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var countdown = (function(){ | |
var index; | |
function log(){ | |
console.log(index); | |
} | |
function iterate(){ | |
log(); | |
if(index>1) setTimeout(iterate, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
Number.prototype.times = function(string){ | |
var result = '', times = this; | |
while(times--) result += string; | |
return result; | |
} | |
console.log(5.times('what')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveSupport | |
module Benchmarkable | |
def silence | |
yield | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'kramdown' | |
require 'date' | |
source = ARGV[0] | |
destination = ARGV[1] | |
Dir.chdir(source) do |dir| | |
@posts = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionDispatch | |
module Session | |
class CustomFileStore < ActionDispatch::Session::AbstractStore | |
def get_session(env, session_id) | |
session_data = {} | |
session_id ||= generate_sid | |
File.open(tmp_file(session_id),'r') do |f| | |
data = f.read | |
session_data = ::Marshal.load(data) unless data.empty? | |
end rescue nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SliderPuzzle | |
def initialize(solved_state = [[0,1,2],[3,4,5]]) | |
@solved = solved_state | |
@current = @solved.map{ |r| r.map{ |c| c } } | |
@y_max = @current.size - 1 | |
@x_max = @current[0].size - 1 | |
@move_count = 0 | |
puts 'Initial, solved.' | |
dump(@solved) |
NewerOlder