Skip to content

Instantly share code, notes, and snippets.

View chrisnatali's full-sized avatar

Chris Natali chrisnatali

  • Sustainable Engineering Lab
  • New York
View GitHub Profile
@chrisnatali
chrisnatali / getPalindromes.js
Created August 14, 2016 02:08
get palindrome function in javascript
function getPalindromes(s) {
/* get all palindromes of the string s */
var results = [];
for (var i = 0; i < s.length; i++) {
var start, end;
start = end = i;
//check 'odd' palindromes
while ( 0 <= start && end < s.length && s[start] == s[end] ) {
results.push(s.substring(start, end + 1));
start--;
@chrisnatali
chrisnatali / powerset.js
Created June 24, 2015 20:59
iterative js powerset
function powerset(input) {
var result = [];
var selections; // bitmap of current subset
for(selections = 0; selections < Math.pow(2, input.length); selections++) {
var subset = [];
var index; // index into bitmap we're looking for
for(index = 0; index < input.length; index++) {
if(selections & (1 << index)) {
subset.push(input[index]);
}
@chrisnatali
chrisnatali / gist:35201a5dc74e97c581ca
Created June 23, 2015 22:16
recursive all subsets
def all_subsets_rec(left, so_far, accum):
if len(left) == 0:
accum.append(so_far)
else:
# find subsets that include first item of left
all_subsets_rec(left[1:], [left[0]] + so_far, accum)
# find subsets that do NOT include first item of left
all_subsets_rec(left[1:], so_far, accum)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chrisnatali
chrisnatali / graph_plot
Created March 20, 2014 16:47
quick plot of graph to png file
my_g_plot <- function(g, id, transform=FALSE) {
# get coords in mercator proj
png(paste("plots/plot", id, ".png", sep=""),
type="cairo-png",
width=1000, height=1000)
if(transform) {
vec_df <- get.data.frame(g, what="vertices")
xy <- vec_df[,c("X", "Y")]
coordinates(xy) <- ~X+Y
proj4string(xy) <- CRS("+proj=longlat +ellps=WGS84")
@chrisnatali
chrisnatali / scrape_falling_rain.py
Created January 21, 2014 23:21
Script to scrape fallingrain.com for a region. Sample execution: python scrape_falling_rain.py "http://www.fallingrain.com/world/BM/" > myanmar_cities.csv
from lxml import etree
import urllib2
import urlparse
import sys
# Prevents this script from failing when output is piped
# to another process
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)
@chrisnatali
chrisnatali / data_model.svg
Last active December 22, 2015 01:09
NeXT data model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chrisnatali
chrisnatali / gist:1595019
Created January 11, 2012 14:54
haskell xmonad config file
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
myManageHook = composeAll
[ ]