Skip to content

Instantly share code, notes, and snippets.

View gartenfeld's full-sized avatar

David Rosson gartenfeld

View GitHub Profile
@gartenfeld
gartenfeld / keypress.js
Last active August 29, 2015 14:11
Keypress for international keyboards.
$('body').keypress(
function (e) {
console.log(
String.fromCharCode( e.which )
);
}
);
@gartenfeld
gartenfeld / set_env.sh
Created December 22, 2014 05:13
Setting OpenShift ENV variables.
rhc set-env VARIABLE1=VALUE1 VARIABLE2=VALUE2 -a app_name
@gartenfeld
gartenfeld / csv.py
Last active August 29, 2015 14:12
Reading from the columns of a CSV file.
import csv
f = open(csv_file.csv)
# Read the CSV format, each row will become an array
rows = csv.reader(f)
for row in rows
variable_a = row[0] # The first column
variable_b = row[1] # The second column, etc.
@gartenfeld
gartenfeld / process_csv.py
Created December 30, 2014 18:24
Processing a CSV file.
import csv
import codecs
import re
def load_dictionary(csv_file, idx, lbl):
d = {}
f = open(csv_file, encoding="utf-8")
s = csv.reader(f)
for r in s:
i = r[idx] # Read index
@gartenfeld
gartenfeld / pentagram.py
Created December 31, 2014 09:08
Generate a hash string using HashIDs.
from hashids import Hashids
hashids = Hashids(salt='vt', min_length=5, alphabet='abcdefghijkmnopqrstuvwxyz')
for i in range(12000,12100):
print (hashids.encrypt(i))
@gartenfeld
gartenfeld / nano_render.js
Last active August 29, 2015 14:12
Replacing template markers with a span wrap.
oldText = $('.tag').html();
newText = oldText.replace(/\{(.+?)\}/g, '<span class="x">$1</span>');
$('.tag').replaceWith(newText);
@gartenfeld
gartenfeld / .bash_profile
Last active August 29, 2015 14:12
Settings for Terminal.
# Enable tab completion
source ~/git-completion.bash
# colors!
# blue="\[\033[0;34m\]"
# purple="\[\033[0;35m\]"
# For background, add \[\033[48;5;256m\]
blue="\[\033[38;5;32m\]"
purple="\[\033[38;5;198m\]"
green="\[\033[0;32m\]"
@gartenfeld
gartenfeld / multi_find.py
Last active November 8, 2022 02:38
BeautifulSoup with multiple criteria.
soup.find_all('div', {'class': ['first', 'second']})
soup.find_all(lambda tag: tag.name=="div" and
tag.get("id")=="examples_box" and
tag.get("class") == "term-subsec")
new_string = re.sub(r' +',' ',old_string)
>>> a=13.946
>>> print(a)
13.946
>>> print("%.2f" % a) # It seems just this will do.
13.95
>>> round(a,2)
13.949999999999999
>>> print("%.2f" % round(a,2))
13.95
>>> print("{0:.2f}".format(a))