Skip to content

Instantly share code, notes, and snippets.

@keithshep
keithshep / jscheats.js
Last active May 12, 2016 13:18
Some JavaScript Cheats
// forward slashes don't work well in URI components even when encoded as %2F. Many server side implementations
// still stumble on them. We can encode/decode the string with a simple scheme like:
// 'hi / there / \\ dude / \\f\\b\\\\'.replace(/\\/g, '\\b').replace(/\//g, '\\f').replace(/\\f/g, '/').replace(/\\b/g, '\\');
function encURIComp(str) {
return encodeURIComponent(str.replace(/\\/g, '\\b').replace(/\//g, '\\f'));
}
function decURIComp(str) {
return decodeURIComponent(str).replace(/\\f/g, '/').replace(/\\b/g, '\\');
import csv
import requests
def build_ensembl_biomart_dict(dataset_name, key_attr, val_attr):
# see http://ensembl.org/biomart/martview/ for the web application
biomart_request_url_template = \
'''http://ensembl.org/biomart/martservice?query=''' \
'''<?xml version="1.0" encoding="UTF-8"?>''' \
'''<!DOCTYPE Query>''' \
'''<Query virtualSchemaName="default" formatter="CSV" header="0" uniqueRows="0" count="" datasetConfigVersion="0.6">''' \
@keithshep
keithshep / mongocheats.js
Last active September 22, 2016 16:28
mongo cheats
// remove field from all samples
db.getCollection('samples').update({}, {'$unset': {'viterbi_haplotypes': 1}}, {multi: true})
// initialize fields in all samples
db.getCollection('samples').update({}, {'$set': {'viterbi_haplotypes': {}}}, {multi: true})
// how to slice without getting everything you don't care about
db.getCollection('samples').find(
{'_id': ObjectId("55e9cf1a6606af0e6e5cb5a1")},
{
@keithshep
keithshep / tmux.md
Created October 13, 2015 14:02 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

import itertools
import math
import numpy as np
from scipy import linalg
import matplotlib.pyplot as plt
import matplotlib as mpl
import pylab
from sklearn import mixture
DEBUG = True
PORT = 5000
#MONGO_SERVER = 'localhost'
MONGO_SERVER = 'xyz.ppp.org'
MONGO_PORT = 27017
MONGO_DATABASE = 'xyz_db'
# the following values enumerate all possible shapes you can use for 'level_shapes' in
# the WEB_APP_CONF below
CIRCLE = "circle"
@keithshep
keithshep / haploqa-celeryd
Created January 6, 2016 17:06
example init.d file for starting & stopping celery within a virtualenv
#!/bin/sh
#
# chkconfig: 345 95 05
# description: celery daemon configured to work with the haploqa application
# If we're invoked via SysV-style runlevel scripts we need to follow the
# link from rcX.d before working out the script name.
if [[ `dirname $0` == /etc/rc*.d ]]; then
target="$(readlink $0)"
else
@keithshep
keithshep / .zshrc
Created November 5, 2016 04:58
stuff I've appended to the end of my .zshrc file
# this function echos "true" when the first argument string starts
# with the second
function startswith() {
if [[ "${1[1, ${#2}]}" == "$2" ]]
then
echo 'true'
fi
}
# scan for and process .dirconf properties files where each lines is a
@keithshep
keithshep / tree-table.component.ts
Created July 20, 2017 19:16
Tree-Table implemented with Angular
import {
Component,
ContentChildren,
Input,
QueryList,
TemplateRef,
} from '@angular/core';
@Component({
selector: 'pxa-tree-table',
@keithshep
keithshep / Numpy Distance from Center Map.ipynb
Last active March 28, 2018 15:31
Create a 2D "Distance from Center" Map with numpy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.