Skip to content

Instantly share code, notes, and snippets.

@dela3499
dela3499 / generate-names.clj
Last active August 29, 2015 13:57
Auto-generating interesting names (a la Figure)
(require '[clojure.string :as string])
(defn insert-at [n coll elem]
"Insert elem as nth element of coll"
(let [[a b] (split-at n coll)]
(concat a [elem] b)))
(defn sample [coll n]
"Get n random samples from coll"
(repeatedly n #(rand-nth coll)))
This file has been truncated, but you can view the full file.
{"us-colemak:auto":{"layout":"English/US - Colemak","mode":"Computer-generated lessons","data":[{"timeStamp":1414692957036,"length":50,"time":29766,"errors":2,"complexity":7,"speed":100.786,"score":235.168,"histogram":{"32":{"h":10,"m":0,"t":567.648},"97":{"h":1,"m":0,"t":2750.005},"101":{"h":16,"m":2,"t":440.129},"105":{"h":5,"m":0,"t":672.661},"110":{"h":11,"m":0,"t":628.346},"111":{"h":1,"m":0,"t":565.611},"116":{"h":6,"m":0,"t":556.606}}},{"timeStamp":1414692990315,"length":47,"time":37175,"errors":4,"complexity":7,"speed":75.857,"score":99.828,"histogram":{"32":{"h":9,"m":0,"t":503.702},"97":{"h":10,"m":1,"t":873.295},"101":{"h":5,"m":1,"t":927.866},"105":{"h":2,"m":0,"t":826.223},"110":{"h":7,"m":0,"t":858.173},"111":{"h":4,"m":2,"t":703.692},"116":{"h":10,"m":0,"t":659.962}}},{"timeStamp":1414693029263,"length":48,"time":33633,"errors":5,"complexity":7,"speed":85.63,"score":95.906,"histogram":{"32":{"h":9,"m":0,"t":521.025},"97":{"h":10,"m":0,"t":360.996},"101":{"h":5,"m":3,"t":695.853},"105":{"h":5,"m
@dela3499
dela3499 / hobbit-symmetry.clj
Last active August 29, 2015 14:17
Symmetrizing hobbit body parts (refactored)
(def asym-hobbit-body-parts [{:name "head" :size 3}
{:name "left-eye" :size 1}
{:name "left-ear" :size 1}
{:name "mouth" :size 1}
{:name "nose" :size 1}
{:name "neck" :size 2}
{:name "left-shoulder" :size 3}
{:name "left-upper-arm" :size 3}
{:name "chest" :size 10}
{:name "back" :size 10}
@dela3499
dela3499 / results-only.js
Created May 28, 2015 23:46
To add a 'results only' toggle button to your IPython notebook, add the snippet below to the file ~/.ipython/profile_default/static/custom/custom.js
$('#menus .navbar-collapse').append($("<button id='results' class='btn btn-default navbar-btn' onclick='exec_code()'>Results Only</button>"));
function exec_code(){
$('#results').text(function(i, text){
return text === "Results Only" ? "Show All" : "Results Only";
})
$('.code_cell .input').toggle();
$('.code_cell .output .output_stderr').toggle();
}
@dela3499
dela3499 / Elm-Impressions.md
Created July 14, 2015 19:04
First Impressions of Elm

First impressions of Elm

Though I'm familiar with functional programming, I mainly work in Python, so I'm new to Elm's type annotations, tagged unions, and purity. I thought I'd play around with Elm a bit by writing a program to generate a random name. I've done this for a number of different programming languages, and found it helpful.

There are three areas I'm interested in exploring more after my first attempt at Elm.

Monads

Though I've never used monads, I understand they are helpful in writing programs that depend on random numbers, like this one. My code seems a bit crufty in this first iteration, since I have to explicitly create a variable for every value that depends on a random seed, and I also have to create a variable for every seed.

Tags in tagged unions

I ran into a compiler error that seemed to result from my using one tag in multiple tagged unions. In my case, it was using Just a in both Maybe and Length.

@dela3499
dela3499 / merge_images.py
Created July 19, 2015 02:49
Generate a macro to run in ImageJ - macro colorizes and merges images of a cell taken at different wavelengths.
from toolz import thread_first, thread_last, curry, groupby, pipe
import os
config = dict(c1 = "TxRed",
c2 = "FITC",
c3 = "DAPI")
directory = '/Users/jonah/Desktop/SRF Internship/APB ssC optimization data/Raw'
files = ['a DAPI 01.tif','a FITC 01.tif','a TxRed 01.tif']
@dela3499
dela3499 / random-number-generation.elm
Last active August 29, 2015 14:25
Succinctly expressing random number generation in a functional language
-- Original code to generate random numbers
let (nChars, seed2) = generate (int 3 5) seed1
(vIndices, seed3) = generate (list nChars (int 0 1000)) seed2
(cIndices, seed4) = generate (list nChars (int 0 1000)) seed3
(length, seed5) = generate (int 0 2) seed4
config = {vIndices = vIndices,
cIndices = cIndices}
-- Dictionary that represents computation
@dela3499
dela3499 / decode-strings.elm
Last active August 29, 2015 14:27
Decode messages where letters are just shifted (i.e 'a' becomes 'b', 'b' becomes 'c', and so on.) You can run this by pasting the code into http://elm-lang.org/try
import Html exposing (Html, Attribute, text, toElement, div, input)
import Html.Attributes exposing (..)
import Html.Events exposing (on, targetValue)
import Signal exposing (Address)
import StartApp.Simple as StartApp
import String
import List
import Graphics.Element exposing (show)
import Char
import Dict exposing (Dict)
import StartApp.Simple exposing (start)
import Html exposing (..)
import Html.Events exposing (onClick, on, targetValue)
import String
{--
Modified from: https://gist.github.com/bbugh/bf150a8be595068de88c