Skip to content

Instantly share code, notes, and snippets.

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)
@bradpauly
bradpauly / custom_file_store.rb
Created August 12, 2012 22:37
simple file store for rails sessions
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
#!/usr/bin/env ruby
require 'kramdown'
require 'date'
source = ARGV[0]
destination = ARGV[1]
Dir.chdir(source) do |dir|
@posts = []
module ActiveSupport
module Benchmarkable
def silence
yield
end
end
end
<!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'));
var countdown = (function(){
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
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){
Function.prototype.cache = function(){
var _cache = {};
this.store = function(n, v){
_cache[n] = v;
return v;
}
this.fetch = function(n) {
if (n in _cache) {
Function.prototype.cache = function(){
var _cache = {};
var key = function(args) {
var sig = 'x', index = args.length;
while (index--) {
sig += args[index].toString();
}
return sig;
}
Function.prototype.cache = function(){
var _cache = {};
// var key = function(args) {
// return 'x' + args.join('');
// }
var key = function(args) {
var sig = 'x', index = args.length;
while (index--) {