Skip to content

Instantly share code, notes, and snippets.

View dandrews's full-sized avatar
🏠
Working from home

Dan Andrews dandrews

🏠
Working from home
View GitHub Profile
import urllib2
url='http://www.baseball-reference.com/teams/ATL/2012.shtml'
q=urllib2.urlopen(url).read()
current = None
previous = [0,0]
streak=['type', 0]
allstreak=[]
a=q.rsplit('ATL (')
for b in a:
@dandrews
dandrews / multi_array_ex.cpp
Created June 29, 2013 19:29
Example call to Boost/MultiArray library
#include "boost/multi_array.hpp"
#include <cassert>
#include <iostream>
int
main () {
// Create a 3D array that is 3 x 3 x 3
typedef boost::multi_array<double, 3> array_type;
typedef array_type::index index;
require 'rubygems'
require 'mechanize'
FIRST_NAME = 'FIRST_NAME'
LAST_NAME = 'LAST_NAME'
PHONE = 'PHONE'
EMAIL = '[email protected]'
PARTY_SIZE = 2
SCHEDULE_RANGE = { :start_time => '19:00', :end_time => '20:30' }
# coding=UTF-8
from __future__ import division
import nltk
from collections import Counter
# This is a simple tool for adding automatic hashtags into an article title
# Created by Shlomi Babluki
# Sep, 2013
@dandrews
dandrews / init.el
Created October 22, 2013 14:39 — forked from mig/init.el
;; emacs configuration
(push "/usr/local/bin" exec-path)
(add-to-list 'load-path "~/.emacs.d")
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
(setq inhibit-startup-message t)

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

  1. Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

# Put this method in your helper file to render inline SVG
def inline_svg(path)
file = File.open("app/assets/images/#{path}", "rb")
raw file.read
end

I wanted to use inline SVG in a rails app. Two steps were needed to enable this:

  1. Set content type to application/xhtml+xml. I enabled this globally by adding this to application_controller.rb

     before_filter{ response.content_type = 'application/xhtml+xml' }
    
  2. Indicate we're using XHTML in the <html> tag. I enabled this globally in application.html.erb:

For jQuery 1.4 $.param()
See http://benalman.com/news/2009/12/jquery-14-param-demystified/
==========
PHP 5.2.11
==========
# print_r( $_GET );
?a=1&a=2&a=3

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results