This file contains 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
%load_ext autoreload | |
%autoreload 2 | |
%matplotlib inline | |
%config InlineBackend.figure_format='retina' | |
# Add this to python2 code to make life easier | |
from __future__ import absolute_import, division, print_function | |
from itertools import combinations | |
import string |
This file contains 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
with | |
dau as ( | |
-- This part of the query can be pretty much anything. | |
-- The only requirement is that it have three columns: | |
-- dt, user_id, inc_amt | |
-- Where dt is a date and user_id is some unique identifier for a user. | |
-- Each dt-user_id pair should be unique in this table. | |
-- inc_amt represents the amount of value that this user created on dt. | |
-- The most common case is | |
-- inc_amt = incremental revenue from the user on dt |
This file contains 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
#-*- coding:utf-8 - *- | |
def load_dataset(): | |
"Load the sample dataset." | |
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]] | |
def createC1(dataset): | |
"Create a list of candidate item sets of size one." |
This file contains 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
#!/bin/bash | |
# This script will migrate schema and data from a SQLite3 database to PostgreSQL. | |
# Schema translation based on http://stackoverflow.com/a/4581921/1303625. | |
# Some column types are not handled (e.g blobs). | |
# | |
# See also: | |
# - http://stackoverflow.com/questions/4581727/convert-sqlite-sql-dump-file-to-postgresql | |
# - https://gist.github.com/bittner/7368128 |
This file contains 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
;; notification from org-agenda | |
;; brew install terminal-notifier | |
(defun djcb-popup (title msg &optional) | |
"Show a popup with the msg and the sound" | |
(interactive) | |
(shell-command (concat "terminal-notifier -message " | |
" '" msg "' " | |
"-title " | |
" '"title"' " | |
)) |
This file contains 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 openbabel import OBAtomAtomIter,OBTypeTable | |
# setup typetable to translate atom types | |
typetable = OBTypeTable() | |
typetable.SetFromType('INT') | |
typetable.SetToType('SYB') | |
lig = pybel.readfile('sdf', "xxx.sdf").next() | |
types = [typetable.Translate(a.type) for a in lig.atoms] |
This file contains 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 Bio.PDB | |
# Select what residues numbers you wish to align | |
# and put them in a list | |
start_id = 1 | |
end_id = 70 | |
atoms_to_be_aligned = range(start_id, end_id + 1) | |
# Start the parser | |
pdb_parser = Bio.PDB.PDBParser(QUIET = True) |
This file contains 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
<!-- thanks to https://github.com/Saynah --> | |
<script> | |
var code_show=true; //true -> hide code at first | |
function code_toggle() { | |
$('div.prompt').hide(); // always hide prompt | |
if (code_show){ |
This file contains 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
s = u'(-1.234, 12]' | |
import re | |
print re.findall(r'[+-]?\d+\.*\d*', s) |
This file contains 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 math | |
import pybel | |
def squared_distance(coordsA, coordsB): | |
"""Find the squared distance between two 3-tuples""" | |
sqrdist = sum((a - b)**2 for a, b in zip(coordsA, coordsB)) | |
return sqrdist |
NewerOlder