Skip to content

Instantly share code, notes, and snippets.

val xs = List(1, 2, 3)
xs.??? => List(4, 5, 6)
xs.??? => List(1, -1, 2, -2, 3, -3)
def f(s: String) = {
val xs = s.split("\n").map(_.split(","))
val ys = xs.transpose.map(_.map(_.length).max)
val zs = xs.map(_.zip(ys))
val ls = zs.map(_.map { case (x,y) => x.padTo(y, ' ') }.mkString(" "))
ls.mkString("\n")
}
val s = """aaa,b,cc
|a,bbbbb,c""".stripMargin
var counter = 0
var rdd = sc.parallelize(data)
rdd.foreach(x => counter += x)
@paulcarey
paulcarey / window_funcs.sql
Last active July 11, 2016 23:13
Filtering out duplicates
scratch=# create table pairs (name varchar(5), value integer);
CREATE TABLE
scratch=# insert into pairs values ('a', 1);
INSERT 0 1
scratch=# insert into pairs values ('a', 1);
INSERT 0 1
scratch=# insert into pairs values ('a', 1);
INSERT 0 1
scratch=# insert into pairs values ('a', 11);
INSERT 0 1
@paulcarey
paulcarey / splits.md
Last active August 29, 2015 14:16
The madness of Vim

Vim

Horizontal Split

Vanilla:

sp, ^W s, ^W S, ^W ^S
for JAR in $(ls *.jar); do echo $JAR; jar -tf $JAR | ack 'org.joda.time.DateTime' ; done;
@paulcarey
paulcarey / download_coursera_notes.rb
Created January 12, 2013 14:04
Script to download Coursera lecture notes
require 'restclient'
# Create the list from the course page by running the following JavaScript
# snippet, and copying and paste the results in here. I _think_ the Content-Type
# of the pdfs prevents them from being downloaded directly in JavaScript.
# $('.course-lectures-list ul:eq(2) a[href$="pdf"]').map(function () { return $(this).attr('href') })
urls = ["https://d19vezwu8eufl6.cloudfront.net/compdata/slides%2Flecture3.pdf",
"https://d19vezwu8eufl6.cloudfront.net/compdata/slides%2Ffunctions.pdf",
@paulcarey
paulcarey / create-ack-ignores.sh
Created September 29, 2012 11:57
Auto-generate a list of ignore-dirs for ack from git ls-files
#!/bin/bash
#
# This script serves as a useful base for generating a list of ignore-dirs
# for ack.
# It's slow to run (e.g. 30 sec on a 3000 file project on a 2010 MBA)
# and emits no output until complete.
#
# create the list of dirs tracked by git
@paulcarey
paulcarey / gist:2888330
Created June 7, 2012 11:37
Breadth First Search
data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq)
breadthFirst :: (a -> b) -> Tree a -> [b]
breadthFirst f Empty = []
breadthFirst f t = breadthFirst' f ([], [t])
breadthFirst' :: (a -> b) -> ([b], [Tree a]) -> [b]
breadthFirst' f (bs, []) = bs
breadthFirst' f (bs, as) = bs ++ breadthFirst' f (bsForAs, nextAs)
where (bsForAs, nextAs) = breadthFirst'' f as
@paulcarey
paulcarey / (+ $ _)
Created May 10, 2012 08:48
jQuery and Underscore Bookmarklet
javascript:(function%20()%20{%20var%20$%20=%20document.createElement('script');%20$.src%20=%20'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';%20$.type%20=%20'text/javascript';%20document.getElementsByTagName('head')[0].appendChild($);%20var%20_%20=%20document.createElement('script');%20_.src%20=%20'http://documentcloud.github.com/underscore/underscore-min.js';%20_.type%20=%20'text/javascript';%20document.getElementsByTagName('head')[0].appendChild(_);%20})()