Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / langton_ant.py
Created March 6, 2016 01:51
Langton's ant visualizations
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
# Manuall add Viridis colormap
viridis = ListedColormap(_viridis_data, name='viridis')
viridis_r = ListedColormap(viridis.colors[::-1]) #reversed
def updatePosition(position, direction):
@dela3499
dela3499 / langton_text.py
Last active March 6, 2016 13:11
Trace text with Langton ant
execfile('viridis.py')
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
from PIL import Image
def image2array(filename):
im = Image.open('logo.jpg')
@dela3499
dela3499 / id2name.py
Last active March 9, 2016 01:44
Get mapping from DrugBank ID to drug name
execfile('/home/bioage/utils/utils.py')
import xmltodict #https://github.com/martinblech/xmltodict
drugbank_xml_file = "path/to/xml/file"
drugbank_json_file = "path/to/json/file" # save json here
drugbank_csv_file = "path/to/csv/file" # save csv here
# Convert XML to JSON and save
drugbank_dict = xmltodict.parse(read_file(drugbank_xml_file)) # takes around 6 minutes
write_file(drugbank_json_file, json.dumps(drugbank_dict))
@dela3499
dela3499 / skim.elm
Last active March 14, 2016 06:30
Document Skimmer - skim documents, summarize them, and note any criticism or new ideas.
import Html exposing (Html, Attribute, text, toElement, fromElement, div, span, input, textarea)
import Html.Attributes exposing (placeholder, value, style)
import Html.Events exposing (on, targetValue, onClick, onDoubleClick, onMouseDown)
import Signal exposing (Address)
import String
import Array exposing (Array)
import Json.Decode as Json
import StartApp as StartApp
import Dict exposing (Dict)
@dela3499
dela3499 / blockchain.py
Created March 22, 2016 08:08
Implementation of simple blockchain
import numpy as np
import hashlib
def create_block(parent_block, value, hashfunc):
""" ------------------------------------------------
String -> Block -> (Block -> String) -> Block
------------------------------------------------
Produce a new block from a string value and a hash
of its parent block. In this case, a block is also a string.
"""
@dela3499
dela3499 / showsong.elm
Last active March 28, 2016 13:39
Show progress of song as its played.
import Time exposing (Time)
import Graphics.Element exposing (show, image)
import Graphics.Collage exposing (collage, path, solid, traced, defaultLine, toForm, move)
import Signal
import Window
import Color exposing (..)
import String
duration = 60 * 5
multiplier = 0.95
@dela3499
dela3499 / bitcounts.py
Last active March 31, 2016 01:22
Pattern of set bits in range of binary numbers
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
x = np.arange(256).astype(np.uint8)
y = np.array(map(lambda x: np.unpackbits([x]).sum(), x))
figsize(10,5)
plt.step(x,y,'k', linewidth = 1)
plt.axis([-2,257,0,8.2])
@dela3499
dela3499 / songvis.ipynb
Created April 9, 2016 01:19
Song Visualizations (messy!)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.