Skip to content

Instantly share code, notes, and snippets.

View paralax's full-sized avatar

jose nazario paralax

View GitHub Profile
@paralax
paralax / sequence_alignment.md
Last active August 29, 2015 14:16
sequence alignment challenge

Title DNA and Protein Sequence Alignment

Difficulty Hard

Description

If you are studying a particular pair of genes or proteins, an important question is to what extent the two sequences are similar. To quantify similarity, it is necessary to align the two sequences, and then you can calculate a similarity score based on the alignment.

There are two types of alignment in general. A global alignment is an alignment of the full length of two sequences, for example, of two protein sequences or of two DNA sequences. A local alignment is an alignment of part of one sequence to part of another sequence.

@paralax
paralax / addition_chain.scala
Created March 7, 2015 22:47
addition chain in scala - failing and flailing
import scala.annotation.tailrec
object AdditionChain {
def chain(len:Int, target:Int):List[List[Int]]= {
def inner(len:Int, target:Int, sofar:List[Int]):List[Int] = {
sofar.length == len match {
case true =>
println(sofar)
sofar.head == target match {
case true => sofar
@paralax
paralax / rdfbot.py
Created March 14, 2015 21:37
reddit notification bot
#!/usr/bin/env python
'''RDFBot - an IRC relay of RDF headlines
Written by Andrew Gaul (http://gaul.org/). Tested with Python 2.3 and
python-irclib 0.3.4. This software has been placed into the public domain.
Issues:
* Slashdot's RDF feed sends malformed XML by appending NUL bytes to responses
occasionally. This causes RDFBot to not update until Slashdot returns valid
@paralax
paralax / mcspot_input.txt
Created March 18, 2015 01:07
mcspot challenge input
5000 5000 505
(282, 1181)
(4783, 3971)
(2348, 3611)
(4568, 1147)
(230, 2582)
(3280, 1877)
(1070, 74)
(3184, 4006)
(4071, 2690)
@paralax
paralax / ca_breaches.py
Last active January 26, 2020 22:39
quick and dirty skim over the list of CA breach notices
#!/usr/bin/env python
from collections import Counter
import itertools
import urllib
from BeautifulSoup import BeautifulSoup
import timestring
URL="http://oag.ca.gov/ecrime/databreach/list"
@paralax
paralax / soconnect.d
Created May 13, 2015 15:26
soconnect.d modified
#!/usr/sbin/dtrace -s
/* originally from http://dtracebook.com/index.php/Network_Lower_Level_Protocols:soconnect.d
modified jose@ to show timestamps
*/
#pragma D option quiet
#pragma D option switchrate=10hz
inline int af_inet = 2; /* AF_INET defined in bsd/sys/socket.h */
@paralax
paralax / crappy.scala
Last active August 29, 2015 14:21
reddit 214H solution
import scala.io.Source
import scala.math._
def dist(x:(Double, Double), y:(Double, Double)): Double =
sqrt(pow(x._1-y._1, 2.0) + pow(x._2-y._2, 2.0))
// yields a 3-tuple: distance to travel, closest treat pos, remaining treats
def best(pos:(Double, Double), treats:List[(Double,Double)]): (Double, (Double, Double), List[(Double,Double)])= {
val sorted = treats.map(x => (dist(pos, x),x)).sortBy(_._1)
(sorted.head._1, sorted.head._2, sorted.tail.map(_._2))
@paralax
paralax / sadCycle.scala
Created May 18, 2015 13:14
sad cycle detector
def sadCycle(n:Int, b:Int): List[Int] = {
def transform(n:Int, b:Int): Int =
n.toString.toCharArray.map(x => (x.toInt-48, b)).map(x => scala.math.pow(x._1, x._2)).sum.toInt
def loop(n:Int, b:Int, acc:List[Int]): List[Int] = {
(acc.tail contains acc.head) match {
case true => acc
case false => loop(transform(n, b), b, transform(n, b)::acc)
}
}
@paralax
paralax / soln.scala
Last active August 29, 2015 14:21
20150522_challenge_215_hard_metaprogramming
def parseTable(input:String): Boolean = {
val StringList = """(\[.+])""".r
val StringDouble = """(\d+\.\d+)""".r
val StringInteger = """(\d+)""".r
val StringBoolean = """(True|False)""".r
val StringStringorChar = """(.*)""".r
input match {
case StringList(n) => n.replace(" ", "").split(",").length > 0
case StringDouble(d) => d.toDouble != 0.0
@paralax
paralax / stddev.elm
Created May 25, 2015 16:39
stddev in elm
import List
import String
average : List -> Float
average l = (l |> List.sum |> toFloat ) / (l|> List.length |> toFloat)
stddev : List -> Float
stddev l =
m = average l
sqrt((l |> List.map(\x -> x-m) |> List.map(\x -> x*x) |> List.sum)/(List.length l |> toFloat))