Skip to content

Instantly share code, notes, and snippets.

View taterbase's full-sized avatar

George Shank taterbase

View GitHub Profile
class Array
def to_h
arr = self.collect do | val |
[ self.index(val), val]
end
Hash[arr]
"use strict";
Number.prototype.times = function ( fn ) {
var i;
for ( i = 0 ; i < this ; ++i)
fn();
};
<!Doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function(){
var htmlStr = String($('#js-item-template').html())
$('.js-item').remove();
@taterbase
taterbase / test.md
Created December 7, 2012 05:03
Test Readme

#LOL

@taterbase
taterbase / stringsymmetry.js
Created November 16, 2012 04:51
String Symmetry
function symmetryPoint ( S ) {
var length = S.length;
if(length === 1)
return 0;
if(length % 2 === 0)
return -1;
var midpoint = Math.floor(length / 2);
var fString = S.substring(0, midpoint);
@taterbase
taterbase / ricechess.js
Created November 16, 2012 04:24
Rice and chess
function rice_chessboard ( A ) {
return checkPath(A[0][0], 0, 0, A)
}
function checkPath(val, x, y, board){
if(board[x + 1] && board[x][y+1]){ //If there is room
var possibility1 = checkPath(val + board[x][y+1], x, (y+1), board);
var possibility2 = checkPath(val + board[x+1][y], (x+1), y, board);
return possibility1 > possibility2 ? possibility1 : possibility2;
@taterbase
taterbase / equilibrium.js
Created November 16, 2012 03:55
Equilibrium
function equi ( A ) {
var N = A.length;
for(var val in A){
if(check(val, A))
return val;
}
return false
}
@taterbase
taterbase / regex-interpolation.js
Created October 23, 2012 05:16
Regex for matching interpolated string var
//Finds all instances of #{} style interpolation like #{variable}
string.match(/#{[^}\r\n]*}/g);
@taterbase
taterbase / fun.js
Created September 25, 2012 00:16
Wat
(function(fn){
fn(fn);
}(function(fn){
fn(fn)
}));
@taterbase
taterbase / index.html
Created August 15, 2012 15:48 — forked from anonymous/index.html
A web page created at CodePen.io.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- IF PEN IS PRIVATE -->
<!-- <meta name="robots" content="noindex"> -->
<!-- END -->