Skip to content

Instantly share code, notes, and snippets.

View DeaconDesperado's full-sized avatar

Mark Grey DeaconDesperado

  • Spotify
  • NY, New York
View GitHub Profile
@DeaconDesperado
DeaconDesperado / vis.js
Created January 31, 2014 19:49
d3 transition interrupt
'use strict'
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 1200 - margin.left - margin.right,
height = 700 - margin.top - margin.bottom;
var padding = 100;
var x = d3.scale.linear()
.range([padding, width - padding]);
@DeaconDesperado
DeaconDesperado / install.sh
Created November 25, 2013 21:38
Install python on Centos
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local
make && make altinstall
cd /root
wget --no-check-certificate http://pypi.python.org/packages/source/d/distribute/distribute-0.6.27.tar.gz
@DeaconDesperado
DeaconDesperado / Palindrome.java
Created November 7, 2013 04:00
Longest palindromic substring
package com.test;
public class Palindrome{
public static String expandAroundCenter(String s, int c1, int c2) {
int l = c1, r = c2;
int n = s.length();
System.out.println(n);
while (l >= 0 && r <= n-1 && s.charAt(l) == s.charAt(r)) {
l = --l;
@DeaconDesperado
DeaconDesperado / subtree.py
Last active December 27, 2015 10:39
Recursive subtree check
def contains_tree(a,b):
if b is None:
#an empty child tree is always a subtree
return True
return sub_tree(a,b)
def sub_tree(a,b):
if a is None:
#if larger tree is exhausted, return false
return False
@DeaconDesperado
DeaconDesperado / Legos.scala
Created November 4, 2013 17:09
Scala implementation of the legos problem, infinitely recursing!!!
import scala.collection.mutable._
object Legos {
val mod = 1000000007;
def t(width:Int):Int = {
if(width < 0) 0
if(width == 0) 1
t(width-1) + t(width-2) + t(width-3) + t(width-4)
@DeaconDesperado
DeaconDesperado / request.py
Last active December 27, 2015 07:59
Set custom property for encoding on werkzeug request
from werkzeug.wrappers import Request, Response
from werkzeug.formparser import FormDataParser
from werkzeug.serving import run_simple
from werkzeug.utils import cached_property
from werkzeug.datastructures import ImmutableMultiDict
def encode(value):
#Catch encoding errors here
return 'foo!'
@DeaconDesperado
DeaconDesperado / legos.py
Created November 3, 2013 15:36
Hackerrank Lego Blocks solution. Permute all solid walls.
import sys
from random import choice
mod = 1000000007
import math
import marshal
cache = {}
def memoized(f):
"""Memoize any function."""
@DeaconDesperado
DeaconDesperado / Change.scala
Created November 1, 2013 00:39
Permutations of a dollar
object Change extends App {
def permuteCombinations(n:Integer,coins:Array[Integer]):Integer = {
if(n == 0) 1
else if(coins.isEmpty || n < 0) 0
else {
permuteCombinations(n - coins.head, coins) + permuteCombinations(n, coins.tail)
}
}
@DeaconDesperado
DeaconDesperado / schema.md
Last active December 24, 2015 14:29
Bob bee Because TShirts are serious business

#Bob Bee

###SQLFIDDLE

The Customer's table, records identities in one place because a single customer could conceivably place many orders over time

Note that US locality is assumed for state,zips, phone etc

@DeaconDesperado
DeaconDesperado / WordChains.md
Last active December 24, 2015 00:40
A solution to the word chains problem, described below in markdown. Implemented in Python using /usr/share/dict/words as dictionary source.

#Word Chains

Given a source string and a destination string write a program to display sequence of strings to travel from source to destination by changing a word at a time.

Rules for traversing:

  1. You can only change one character at a time
  2. Any resulting word has to be a valid word from dictionary

Example: Given source word CAT and destination word DOG , one of the valid sequence would be