Skip to content

Instantly share code, notes, and snippets.

View azalea's full-sized avatar
😂
Enjoy life

Z azalea

😂
Enjoy life
View GitHub Profile
@azalea
azalea / split_then_pairwise_blast.py
Created February 2, 2014 21:14
This code tried to do things the hard way to solve: http://www.biostars.org/p/92205/ by first, the function split_fasta() splits the original fasta file into files containing individual sequence records; second, blast_seq_the_hard_way() iterates over these individual files and feeds their filenames to BLAST. Please note that BLAST can handle mul…
'''This code tried to do things the hard way to solve: http://www.biostars.org/p/92205/ by
first, the function split_fasta() splits the original fasta file into files containing individual sequence records;
second, blast_seq_the_hard_way() iterates over these individual files and feeds their filenames to BLAST.
Please note that BLAST can handle multiple sequences in -query and -subject at the same time, so there is no need
to split the files. This code is just for demonstration purposes.
'''
import os
import re
from Bio.Blast.Applications import NcbiblastpCommandline
@azalea
azalea / replace_extension.sh
Created March 6, 2014 16:31
Replace file extensions in git repository
#!/bin/sh
oldext=".md"
newext=".markdown"
for file in $(git ls-files | grep ${oldext}\$); do
echo processing $file...
filename="${file%.*}"
git mv $file ${filename}$newext
done
@azalea
azalea / linux_one_liners.md
Created March 19, 2014 04:23
Linux one-liners

Find the length of each line in the file

while read line; do echo -n "$line" | wc -c; done< f1
@azalea
azalea / getattr.py
Last active August 29, 2015 14:03
Use getattr() to access any attribute of any class instance
# Say I have such classes A, B, C, ..., Y, and Z that do different things,
# and classes AComment, BComment, CComment, ..., YComment and ZComment
# that record comments on instances of class A, B, ..., Y and Z respectively.
# All XComment classes share the same attributes except one property
# that is is dependent on the class the comment is for.
# e.g. AComment has a property 'a' and BComment has a property 'b'.
class A():
def __init__(self):
print 'init an instance of class A'
@azalea
azalea / gist:1223667
Created September 17, 2011 05:50 — forked from imathis/gist:1104557
FIX for Lion's posix_spawn_ext.bundle: [BUG] Segmentation fault

The segfault problem with posix_spawn is indeed caused by Lion's compiler being LLVM and not GCC by default. However, when I installed RVM, the notes suggested that on Lion you need to add export CC=/usr/bin/gcc-4.2 to your shell startup file (.bashrc or .zshrc as appropriate). I did that, but it seems that's what caused problems: while ruby 1.9.2 needs you to use GCC to install it, using the same compiler for the gems apparently causes breakage.

First, you need to install XCode 4.x, which is now a free (though hefty!) download from the Mac App Store. Without that, you have no gcc, so you won't get anywhere ;-)

Next, what you need to do is clear out your rvm ruby and the associated gems (make sure you are cd'd into your octopress repository then do:

rvm remove ruby-1.9.2 --gems --archive

which will clear everything out so that you can start from scratch. Obviously, if you have other stuff you've installed for other purposes using RVM, be careful with this. If you previously had the export CC li

@azalea
azalea / resplit.py
Created November 29, 2011 07:38
re split
import re
txt = 'abc-def, -g!8hij'
words = re.compile('[^A-z^a-z]+').split(txt)
# Or
words = re.split('[^A-z^a-z]+',txt)
# References:
# http://docs.python.org/library/re.html#re.split
@azalea
azalea / wineTasting.py
Created December 17, 2011 04:13
Facebook Hacker Cup 2011 Round 1A - Wine Tasting
#!/usr/bin/python
import sys
def fac(n):
'''n!'''
if n==0 or n==1:
return 1
else:
return n*fac(n-1)
@azalea
azalea / sieveEratosthenes.py
Created January 8, 2012 08:59
Sieve of Eratosthenes
def sieveEratosthenes(limit):
'''Return all primes below the limit'''
numbers = range(3,limit,2)
primes = [2]
while True:
prime = numbers.pop(0)
primes.append(prime)
for n in range(prime**2, limit, 2*prime):
try:
numbers.remove(n)
@azalea
azalea / buggy_defaultdict.py
Created August 7, 2012 23:04
Bug of defaultdict?
import collections
def dfs(G, s, path=[]):
global explored
explored.add(s)
path.append(s)
for v in G[s]:
if v not in path:
path = dfs(G, v, path)
return path
@azalea
azalea / init.el
Created December 3, 2015 20:09
emacs init.el for Windows
;; Requisites: Emacs >= 24
;; INSTALL PACKAGES
;; --------------------------------------
(prefer-coding-system 'utf-8)
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)