Skip to content

Instantly share code, notes, and snippets.

View joedougherty's full-sized avatar

Joe Dougherty joedougherty

View GitHub Profile
@joedougherty
joedougherty / ascendDOMLevels.js
Created March 8, 2012 19:48
Ascend the DOM in jQuery with succinct notation
/*
I found myself needing to traverse the DOM tree upward more than just a few levels in a recent project (mostly due to heavy element nesting).
This function takes two arguments: the element in question and the number of levels to ascend.
Finally, it returns the element that's n levels above the initial element.
Ex: $(this).parent().parent().parent().parent().parent() could be more concisely expressed as ascendDOMLevels($(this), 5).
*/
@joedougherty
joedougherty / gist:2252807
Created March 30, 2012 16:51
SEPTA API sales_locations item Object Structure
/*
Example: to access a location's address, call item.sales_data.ADDRESS;
*/
item
distance: float
location_id: int // ex: 928044
location_lat: string // ex: "39.9562551"
@joedougherty
joedougherty / gist:4063888
Created November 13, 2012 04:11
Example template.php to add js just to front page
<?php
// Be sure to replace THEME_NAME with the name of the current theme
function THEME_NAME_preprocess_html(&$variables) {
if ( drupal_is_front_page() ) {
drupal_add_js( 'path/to/file' );
}
}
import requests
from bs4 import BeautifulSoup
# Set the URL to download
endpoint = 'http://grants.nih.gov/searchGuide/Search_Guide_Results.cfm?Activity_Code=&Expdate_On_After=&OrderOn=ExpirationDate&OrderDirection=ASC&NoticesToo=0&OpeningDate_On_After=&Parent_FOA=All&PrimaryIC=Any&RelDate_On_After=&Status=1&SearchTerms=HIV&PAsToo=1&RFAsToo=1'
# Pull down the HTML from that URL
r = requests.get(endpoint)
page = r.content
function cheat_plus_one($num) {
return eval('return ' . $num .' '. eval('return chr(43);') . ' 1;');
}
@joedougherty
joedougherty / j5_growl.js
Created January 17, 2014 22:23
Node version of Notifier
var growl = require('growl');
var five = require('johnny-five'),
board, button;
board = new five.Board();
board.on("ready", function() {
button = new five.Button(8);
from pprint import pprint
lens_to_test = range(2,26)
lengths = {}
def all_words():
all_words = []
words = '/usr/share/dict/words'
f = open(words,'r')
for w in f.readlines():
@joedougherty
joedougherty / popen.py
Created June 16, 2014 17:29
Capture stdout, stderr, and return code from subprocess.Popen
from subprocess import Popen, PIPE
r = Popen(['/path/to/test.sh'], stdout=PIPE, stderr=PIPE)
stdout, stderr = r.communicate()
result = r.wait()
print(stdout, stderr, result)
@joedougherty
joedougherty / InlineSAS.py
Created August 29, 2014 14:11
InlineSAS
import subprocess, os, tempfile
def callSAS(sas_str):
f = tempfile.NamedTemporaryFile(delete=False)
f.write(sas_str)
f.close()
invocation = ['sas', '-sysin', f.name]
r = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@joedougherty
joedougherty / encode.sas
Created September 15, 2014 20:03
encode.sas
filename pwfile '~/tmp-passwd';
proc pwencode in="&sysparm" out=pwfile; run;
data _null_;
file stdout;
infile pwfile obs=1 length=l;
input @;
input @1 line $varying1024. l;
put line;