Skip to content

Instantly share code, notes, and snippets.

PREFIX='http://mediastream2.brown.edu/media/_definst_/vreserves/harrison_ampa2610/mp4:'
for i in `seq 1 36`
do
file=`curl http://brown.edu/cis/sta/dev/harrison_ampa2610/lecture_$i.html | grep mp4 | awk '{print substr($2, 2, length($2)-3)}'`;
ffmpeg -i $PREFIX$file/playlist.m3u8 -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $file
done
@vivekn
vivekn / crawler.py
Created January 5, 2016 11:50
Crawl and Download Varadhan's lecture notes on probability, measure theory and large deviations. Requires (gevent, bs4)
import gevent
from gevent import monkey
monkey.patch_all()
from bs4 import BeautifulSoup
from urllib2 import urlopen
from os import mkdir, path
BASE = 'http://math.nyu.edu/faculty/varadhan'
def mkpath(url):
@vivekn
vivekn / tt.py
Created September 20, 2014 17:38
from collections import defaultdict
tweets = open('tweets.txt.aa').read().lower().split()
target = open('tweets.txt.ab').read().lower().split()
#Mapping from term to number of tweets
doc_ctr = defaultdict(int)
for tweet in tweets:
for word in set(tweet.split()):
package autocorrect
import scala.collection.mutable.Map
import scala.collection.mutable.ArrayBuffer
class BKTree(val str: String) {
var children: Map[Int, BKTree] = Map[Int, BKTree]()
def add(word: String): Unit = {
val dist = Utils.levenshtein(str, word)
if (children contains dist) children(dist) add word
@vivekn
vivekn / bktree.scala
Last active January 4, 2016 16:19
BKTree
package com.vivekn.bktree
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.Map
class BKTreeNode(str: String) {
var children: Map[Int, BKTreeNode] = Map[Int, BKTreeNode]()
def add(word: String) : Unit = {
val dist = WordUtils.levenshtein(str, word)
@vivekn
vivekn / Regex.scala
Created January 19, 2014 06:49
Codesprint Regex problem - generate a string that matches a regex in Scala
import java.util.HashMap
import scala.collection.mutable.Set
object Solution {
class Node (var isTerm: Boolean = false) {
var children: HashMap[String, Array[Node]] = new HashMap[String, Array[Node]]()
}
def splitTokens(regex: String) : (String, String, Char) = {
@vivekn
vivekn / merge.sh
Last active December 24, 2015 11:19
svn merge to trunk
svn sw $1
lines=`svn merge --accept postpone $2|grep -y "conflict"|wc -l`
if [ lines -eq 0 ]
then
svn ci -m "Merged Trunk"
svn sw $1
svn up
lines2=`svn merge --reintegrate $2|grep -y "conflict"|wc -l`
if [ lines2 -eq 0 ]
then
@vivekn
vivekn / cmd.sh
Created September 15, 2013 19:58
Shell script to create/edit a shell command
sudo touch /usr/local/bin/$1
sudo vim /usr/local/bin/$1
sudo chmod +x /usr/local/bin/$1
@vivekn
vivekn / stism.py
Last active December 17, 2015 17:39
Spatio temporal ISM
from math import sqrt, log, pi
from random import random
import numpy as np
def build_st_ism(frames, r, s):
nframes = len(frames)
M, N = frames[0].shape
patches = map(ism, get_patches(frames, r, s))
spatial_ism = stitch_space(patches, nframes, M, N, r, s)
slices = map(ism, get_slices(frames))
@vivekn
vivekn / perms.py
Created March 25, 2012 14:02
CodeDef - Permutations
def permg(seq):
"""
Returns a generator of permutations for a sequence.
"""
if len(seq) <= 1:
yield seq
else:
for perm in permg(seq[1:]):
for i in range(len(seq)):
yield perm[:i] + seq[0:1] + perm[i:]