Skip to content

Instantly share code, notes, and snippets.

View underhilllabs's full-sized avatar

Bart Lantz underhilllabs

View GitHub Profile
@underhilllabs
underhilllabs / remove-pass.bash
Created February 20, 2012 01:33
Remove passwords from files
# take password out of all java files and all git history
git filter-branch -f --tree-filter 'git ls-files -z "*.java" |xargs -0 perl -p -i -e "s#Secr3tpassw0rd#xXxXxXxXxXx#g"' -- --all
git gc --aggressive --prune
# use -f to force push if already on github
git push -f github master
@underhilllabs
underhilllabs / tags.bash
Created February 27, 2012 06:16
vim navigation with tags
# create a tags file
ctags *.java
# inside vim, jump to where function under cursor is defined
^[
# this will open the functions definition. When you want to return:
^T
# You can hop to several function definitions, say 3, then return with:
@underhilllabs
underhilllabs / RavelryClientSignin.java
Created February 28, 2012 17:46 — forked from knitfaced/RavelryClientSignin.java
snippet to connect to the Ravelry API
private String createShopSearchQuery() throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
String jsonAction = "http://api.ravelry.com/shops/search.json?";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
Calendar now = Calendar.getInstance();
String timestamp = df.format(now.getTime());
String searchTerm = "yarn";
int shop_type_id = 1;
String query = jsonAction;
query += "access_key=" + urlEncode(ACCESS_KEY);
@underhilllabs
underhilllabs / git-split-subpath.bash
Created March 3, 2012 19:14
Split a subtree of a git repository into a separate repo.
#########################################################
#
# classes is a git repository with many class projects
# I want to split one of those projects into its own repo
# and I want preserve the commit history
#
# The super top-level repo is classes.git
# Within classes.git is a sub-directory "networks/project2"
# we want to create a new repository with just the history of
# "networks/project2"
@underhilllabs
underhilllabs / book.test
Created March 26, 2012 00:59
book.test
<?php
/**
* Tests that link to parent node not shown if user doesn't have access to parent.
*/
function testParentAccess() {
// Create new book.
$nodes = $this->createBook();
$book = $this->book;
@underhilllabs
underhilllabs / projectEulerProb19.py
Created April 21, 2012 03:33
Project Euler Problem 19
#!/usr/bin/python
# return true if this year is a leap year
def checkLeap(inYear):
if(year % 4 == 0):
if (year % 100 == 0 and year % 400 != 0):
return False
else:
return True
else:
@underhilllabs
underhilllabs / numberToWord.py
Created April 21, 2012 04:58
Python function to translate a number to a word
def numWords(num):
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
iwords = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
twords = ["","teen","twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
myStr = ""
huns = ""
# if over a thousand, first mod with 1000 to get next lower magnitude
@underhilllabs
underhilllabs / sieve.py
Created April 21, 2012 06:40
Sieve of Eratosthenes
def sieve(MAX):
# list of primes
primes = []
# list of all numbers, non-primes will be slowly zeroed out
nums = []
# start with first prime
prime = 2
# populate list from 0 to MAX
nums = [i for i in range(MAX+1)]
# zero out 1, non-prime
@underhilllabs
underhilllabs / delicious_scuttle_export.py
Created April 22, 2012 18:31
Export delicious bookmarks into a scuttle site
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# code originally from Michael Klier
# -- licensed unded CC-NC-SA
# http://www.splitbrain.org/blog/2010-12/12-from_scuttle_to_delicious
#
# 1. change username and password in urls below
# 2. change SCUTTLEDOMAIN to the domain of your scuttle site
@underhilllabs
underhilllabs / exchange_nodes.c
Created May 14, 2012 01:14
Exchange Nodes in a linked list
/* Exchange places of nodes after, the nodes passed in.*/
exchange(struct node *u, struct node *v) {
struct node *x, *y;
x = u->next;
u->next = u->next->next;
y = v->next;
v->next = v->next->next;
y->next = u->next;