Skip to content

Instantly share code, notes, and snippets.

View armanbilge's full-sized avatar
😵
Declaring notification bankruptcy. If I forgot your PR please ping me!

Arman Bilge armanbilge

😵
Declaring notification bankruptcy. If I forgot your PR please ping me!
View GitHub Profile
@armanbilge
armanbilge / nexus2newick.py
Last active December 24, 2015 20:59
Converts trees from Nexus format to Newick format. Depends on Dendropy.
#!/usr/bin/env python
import sys
from dendropy import TreeList
NEWICK = 'newick'
NEXUS = 'nexus'
try:
stream = sys.argv[1]
@armanbilge
armanbilge / FlickrSetDownloadr.py
Created December 27, 2013 22:49
Downloads photos from a Flickr set
#!/usr/bin/env python
# FlickrSetDownloadr.py
# Downloads photos from a Flickr set
# Usage: python FlickrSetDownloadr.py [PHOTOSET_ID]
import sys
from collections import deque
try:
from xml.etree.cElementTree import fromstring
except:
@armanbilge
armanbilge / SecretSnowflakeCoordinator.py
Last active January 1, 2016 19:59
Web app that automatically coordinates a Secret Snowflake Gift Exchange
#!/usr/bin/env python
# SecretSnowflakeOrganizer.py
# Web app that automatically coordinates a Secret Snowflake Gift Exchange
COORDINATOR_PASSWORD = 'COORDINATOR_PASSWORD'
DB_HOST = 'DB_HOST'
DB_USER = 'DB_USER'
DB_PASSWORD = 'DB_PASSWORD'
DB_NAME = 'DB_NAME'
GMAIL_USER = 'EMAIL'
@armanbilge
armanbilge / GoogleContactsExtracter.py
Created January 14, 2014 18:49
Python one-liner extracting names and emails from Google Contacts CSV export.
import sys; print '\n'.join([l.split(',')[0] + '\t' + l.split(',')[-5] for l in open(sys.argv[1])]);
@armanbilge
armanbilge / rrechelon.py
Created June 2, 2014 09:46
Transforms the given matrix to reduced row echelon form.
#!/usr/bin/env python3
import sys
from fractions import Fraction
mult = lambda r,f: [f * x for x in r]
add = lambda r1,r2: [x + y for x,y in zip(r1,r2)]
def print_matrix(m):
for r in m: print('\t'.join(str(x) for x in r))
@armanbilge
armanbilge / auto_mailer.py
Last active August 29, 2015 14:02
My go-to python script for automatic mail jobs
#!/usr/bin/python
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
gmail_user = "[email protected]"
next_poisson <- function(lambdas) {
lambda <- sum(lambdas)
t <- rexp(1, rate = lambda)
i <- sample(length(lambdas), 1, prob = lambdas / lambda)
return(c(t, i))
}
duplication <- function(s) {
i <- sample(length(s), 1, prob = s / sum(s))
s[i] <- s[i] + 1
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\frenchspacing
\begin{document}
\begin{tabular}{l c l}
from string import ascii_lowercase as alphabet
f = lambda i: alphabet[i] if i < 26 else alphabet[i / 26 - 1] + alphabet[i % 26]
public static void main(String... args) throws IOException, Importer.ImportException {
final TreeModel tree = new TreeModel(new NewickImporter("(a:1,b:1);").importNextTree());
final SimpleAlignment alignment = new SimpleAlignment();
alignment.setDataType(Nucleotides.INSTANCE);
alignment.addSequence(new Sequence(new Taxon("a"), "A"));
alignment.addSequence(new Sequence(new Taxon("b"), "C"));
final PatternList patterns = new SitePatterns(alignment);
final SiteModel siteModel = new GammaSiteModel(new GTR(new Variable.D(1, 1), new Variable.D(1, 1), new Variable.D(1, 1), new Variable.D(1, 1), new Variable.D(1, 1), new Variable.D(1, 1), new FrequencyModel(Nucleotides.INSTANCE, new double[]{0.25, 0.25, 0.25, 0.25})));
final TreeLikelihood likelihood = new TreeLikelihood(patterns, tree, siteModel, new DefaultBranchRateModel(), null, true, false, true, true, false);
final Variable<Double> var = tree.createNodeHeightsParameter(true, true, false