Skip to content

Instantly share code, notes, and snippets.

@bruab
bruab / experiment.js
Created March 14, 2016 23:22
Boilerplate code for Google Analytics integration
/* _optimizely_evaluate=force */
$(window).load(function() {
var experimentID = TODO_PASTE_IN_HERE; // ex: 9876543210
try { // wait till window.load so ga exists via segment.io
var cookieName = 'ga_optimizely_' + experimentID;
if (!getCookie(cookieName)) {
setCookie(cookieName, 'sent', 30 * 60); // resend every 30m
@bruab
bruab / calculate_grade.py
Created August 24, 2015 23:29
CS 294 - Grade Calculator Script
#!/usr/bin/env python
import argparse
def get_letter_grade(points):
"""Return letter grade (A-F) based on 100 point scale"""
if points >= 90:
return 'A'
elif points >= 80:
return 'B'
@bruab
bruab / get_lat_long.py
Created July 31, 2015 21:30
Use Python requests and telize API to get latitude and longitude for IP address
#!/usr/bin/env python
import requests
r = requests.get("http://www.telize.com/geoip/46.19.37.108")
json_object = r.json()
print(json_object['latitude'])
print(json_object['longitude'])
@bruab
bruab / remap_hetero_fragments.py
Created July 24, 2015 02:28
For making Hi-C Box and GRAAL play nice together
#!/usr/bin/env python
## Read two GRAALy files and produce a new, improved
## hetero_contacts table using different indices.
## It's complicated.
import sys
INFO_CONTIGS_FILE = "info_contigs.txt"
FRAGMENTS_HETERO_FILE = "fragments_hetero_contacts.txt"
@bruab
bruab / replace_first_column_with_nine_spaces.py
Created March 25, 2015 18:16
Let's take a tab-delimited file and replace its first column with nine spaces. Let's do this ... to all tab-delimited files.
#!/usr/bin/env python3
import sys
# Check command line arg
if len(sys.argv) != 2:
sys.stderr.write("usage: replace_first_column_with_nine_spaces.py <input.tsv>\n")
sys.exit()
# Open file
@bruab
bruab / gist:bb0d409994895d1a717f
Created January 30, 2015 18:27
An effed up Perl configuration
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
[bhall@moana][~]> module list
Currently Loaded Modulefiles:
1) rocks-openmpi
[bhall@moana][~]> echo $PERL5LIB
[bhall@moana][~]> echo $PERL5INC
[bhall@moana][~]> echo $INC
@bruab
bruab / gist:a883d09de34d0f2b6935
Created December 11, 2014 01:48
Writing multiple output files in Python (based on command line argument)
#!/usr/bin/env python
import sys
if len(sys.argv) < 2:
sys.stderr.write("usage: write_two_files.py <filename prefix>\n")
sys.exit()
prefix = sys.argv[1]
@bruab
bruab / gist:7a5ba03fd3188c4a71f5
Created October 1, 2014 00:04
Lep-MAP refactor part 1
elif line.startswith("alleles"):
#this is the second line
alleles = line.strip().split()[1:]
else: # This "else" is currently on line 64
columns = line.split()
individual_info = get_ind_info(columns)
# I chopped out a bunch of stuff here
group = individual_info['group']
@bruab
bruab / Bash_if_grep_count
Created September 4, 2014 01:45
Quick demo of a Bash if statement that depends on how many filenames in the working directory match a string
#!/bin/bash
# we want to know how many files in this directory contain the string 'bar'
number_of_matches=`ls | grep -c bar`
# uncomment the following line to see how many matches you got:
#echo $number_of_matches
# if only one match, let me know
if [[ $number_of_matches -eq 1 ]]