Skip to content

Instantly share code, notes, and snippets.

@dela3499
dela3499 / combinator.elm
Last active March 7, 2016 06:27
Combinator UI
import Html exposing (Html, Attribute, text, toElement, fromElement, div, input, textarea)
import Html.Attributes exposing (..)
import Html.Events exposing (on, targetValue, onClick, onDoubleClick)
import Signal exposing (Address)
import StartApp as StartApp
import String
import Graphics.Element exposing (spacer, color, show)
import Color exposing (..)
import Dict exposing (Dict)
import Maybe exposing (withDefault)
@dela3499
dela3499 / forkingPathGenerator.elm
Last active March 6, 2016 22:27
Forking Paths in Elm
import Graphics.Element exposing (show)
import List
import Regex
import Dict exposing (Dict)
import String
import Random
import Array
import Set
-- Return list with no duplicate elements
@dela3499
dela3499 / forking_paths.py
Last active March 4, 2016 23:57
Generate a tree of paths, and repeatedly travel random paths from root to leaf to generate strings.
import random
def lprint(xs):
for x in xs:
print(x)
def repeat_and_deduplicate(f, args, n):
return list(set([f(*args) for _ in range(n)]))
@dela3499
dela3499 / combinations.js
Last active March 1, 2016 12:34
Given a format string, replace appropriate fields with all combinations of input lists.
function hasValue(x) {
return x.toString().length > 0;
}
function hasValues(values) {
for (var i = 0; i < values.length; i += 1) {
if (values[i].toString().length > 0) {
return true;
}
}
def thread_last(val, *forms):
""" Thread value through a sequence of functions/forms
>>> def double(x): return 2*x
>>> def inc(x): return x + 1
>>> thread_last(1, inc, double)
4
If the function expects more than one input you can specify those inputs
in a tuple. The value is used as the last input.
@dela3499
dela3499 / chunkapply.py
Created February 11, 2016 02:36
Apply function to file in chunks.
import fileinput
import numpy as np
import cPickle as pickle
# (String -> a) -> Filename -> Int -> SideEffect[FileSystem] # List a
def chunkapply(f, filename, chunksize, savefile):
""" For each chunk, apply f to each line, and save the list of results to
file starting with savefilename, and followed by chunk number. """
data = []
@dela3499
dela3499 / acronym2word.py
Created February 8, 2016 22:32
Produce candidate pronunciation for an acronym. Take set of letters, perhaps a potential acronym, and try to expand it. Maybe just to have a new word to pronounce. Turn crps to carapace.
import numpy as np
import toolz as tz
np.random.seed(1000)
# String -> String
def generate_word(word):
""" Given a word, return a new word with vowels interspersed between the letters. """
vowels = list('aeiouy_')
letters = list(word)
@dela3499
dela3499 / checker.py
Last active February 2, 2016 21:18
Generate a checkered matrix in Python.
from itertools as it
# Generator a -> Int -> List a
def take(generator, n):
""" Return first n elements of generator as list. """
return list(it.islice(generator, n))
# List a -> Int -> List a
def takecycle(elements, n):
""" Return first n elements of infinite cycle given by elements. """
@dela3499
dela3499 / convnet.py
Created January 31, 2016 23:58
Rewriting keras example
from keras.models import Sequential
from keras.layers import Convolution2D, ZeroPadding2D, MaxPooling2D
img_width, img_height = 128, 128
# this will contain our generated images
input_img = K.placeholder((1, 3, img_width, img_height))
# build the VGG16 network with our input_img as input
first_layer = ZeroPadding2D((1, 1), input_shape=(3, img_width, img_height))
@dela3499
dela3499 / geo2r.R
Created January 29, 2016 21:56
GEO2R test
# Version info: R 2.14.1, Biobase 2.15.3, GEOquery 2.23.2, limma 3.10.1
# R scripts generated Fri Jan 29 16:56:51 EST 2016
################################################################
# Differential expression analysis with limma
library(Biobase)
library(GEOquery)
library(limma)
# load series and platform data from GEO