Skip to content

Instantly share code, notes, and snippets.

@dela3499
dela3499 / ec2-setup.md
Last active June 13, 2016 23:06
Setting up new machine on EC2
# Matplotlib depends on a few libraries that seem to be missing. Run the following commands to get them. 
sudo apt-get install libsm6
sudo apt-get install libxrender1

# Zappa depends on these. 
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
@dela3499
dela3499 / float_precision_errors.py
Last active August 20, 2016 08:37
Pattern of error when reducing precision in floats
figsize(10,5)
x = np.linspace(-10,10,10000)
y1 = x.astype(np.float32)
y2 = x.astype(np.float16)
# plt.semilogy(np.abs(x - x))
plt.semilogy(np.abs(x - y1))
plt.semilogy(np.abs(x - y2))
plt.legend(['32','16'])
label('Original value','Error','Error when reducing precision of 64-bit floats')
@dela3499
dela3499 / song_thumnails.ipynb
Created May 8, 2016 19:43
Song thumbnails - take sections from the beginning, middle, and end of songs, and combine them into a discography-spanning summary of an artist's work.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dela3499
dela3499 / newVersion.elm
Created June 17, 2016 20:29
Example use of Elm 0.17 - taking advantage of subscriptions, and tasks.
import Html.App as Html
import Html exposing ( Html, div, text )
import Html.Attributes exposing ( .. )
import Html.Events exposing ( onClick )
import Window
import Task
main = Html.program
{ init = ( ( initSize, initSize ), triggerGetSize )
@dela3499
dela3499 / french_sentences.py
Created July 5, 2016 15:40
Learn 4 French sentences
import numpy as np
import time
from IPython.display import clear_output
sentences = [
("I must eat.", "Je dois manger."),
("I want to eat.","Je veux manger."),
("I'm going to eat tomorrow.","Je vais manger demain."),
("I can't eat.","Je ne peux pas manger.")
]
@dela3499
dela3499 / expand_rows.ipynb
Created August 11, 2016 02:13
Iterate over the rows of a dataframe, and expand some rows into multiple rows.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dela3499
dela3499 / print_matrix.py
Last active August 20, 2016 08:06
Print large boolean matrix row by row in a terminal (looks like a scene from the matrix)
import time
import numpy as np
def g(t):
ti = 0
for _ in range(int(1e6)):
print ' '.join(np.random.randint(2, size = 80).astype(str))
time.sleep(np.random.random() * 0.05)
ti += 0.01
if ti > t:
@dela3499
dela3499 / stringsAndSums.js
Created August 26, 2016 02:16
How to convert strings to integers in JavaScript, and sum the values in an array
// Convert string to number
string = '12.1';
number = parseFloat(string);
// Convert float to int
myInt = Math.floor(number);
// Convert list of strings to list of ints
strings = ['1.1','2.1','3.1'];
numbers = strings.map(parseFloat);
@dela3499
dela3499 / elm-package.json
Last active August 29, 2016 01:26
This is a scaffold for Elm projects. Takes care of basic imports, along with model, view, and update information.
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {