This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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). | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cheat_plus_one($num) { | |
return eval('return ' . $num .' '. eval('return chr(43);') . ' 1;'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var growl = require('growl'); | |
var five = require('johnny-five'), | |
board, button; | |
board = new five.Board(); | |
board.on("ready", function() { | |
button = new five.Button(8); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
OlderNewer