Skip to content

Instantly share code, notes, and snippets.

View ruggeri's full-sized avatar
🌕
🌀_🌀

Ned Ruggeri ruggeri

🌕
🌀_🌀
View GitHub Profile
@ruggeri
ruggeri / test.md
Created October 13, 2012 15:37
A Test file

This is my story

This is my song.

@ruggeri
ruggeri / gist:4441742
Created January 3, 2013 08:12
Insertion sort implementation
def insertion_sort(array)
i = 0
while i < array.length
j = 0
while array[j] < array[i]
j += 1
end
# array[j] is the first element >= array[i]
# delete array[i] and move it to just before position j
@ruggeri
ruggeri / build.sh
Last active April 5, 2017 02:02
AVX Implementation of a 1D Convolution
#!/usr/bin/env bash
gcc -std=c11 -mavx -mavx2 convolution_test.c -o convolution_test
@ruggeri
ruggeri / tf_fail.py
Created December 15, 2017 00:00
Shrink initialization; don't scale variables!
import tensorflow as tf
# Notice that x and y have the same initial value, but y_var has
# totally different scale from x_var. Therefore y_var has much farther
# to change than x_var.
x_var = tf.Variable(1.0)
y_var = tf.Variable(100.0)
y_var_scaled = y_var / 100.0
# This is just a silly linear equation. It will have a derivative of 2
@ruggeri
ruggeri / generation.py
Last active December 19, 2017 02:25
Keras Generation Example
import keras.backend as K
from keras.datasets import mnist
from keras.layers import Dense, Flatten, Input, Reshape
from keras.models import Model
from keras.optimizers import Adam
import numpy as np
# == This code trains a denoising autoencoder. ==
input_tensor = Input(shape = (28, 28))
flattened_input = Flatten()(input_tensor)
@ruggeri
ruggeri / functional.py
Created December 18, 2017 01:30
Keras Functional API Example
# Resource: https://keras.io/getting-started/functional-api-guide/
import keras.backend as K
from keras.datasets import mnist
from keras.layers import Dense, Input, Lambda
from keras.models import Model
from keras.optimizers import Adam
from keras.utils import to_categorical
import numpy as np
@ruggeri
ruggeri / promises.js
Created January 17, 2018 19:04
two-argument then
promise.then((result) => {
// promise resolved successfully.
console.log(`Result is ${result}`);
}, (error) => {
// promise was failed
console.log(`Error is ${error}`);
});
// Also: promise.then(null, (error) => { ... }) is the same as promise.catch((error) => { ... }).
// The Promise#catch method is just a convenience. You can always just pass a null success handler to then.
@ruggeri
ruggeri / imdb_logistic_regression.py
Created January 19, 2018 21:47
Lecture #2: Logistic Regression Demo
from keras.datasets import imdb
import numpy as np
TOP_N_WORDS = 1_000
(x_train, y_train), (x_test, y_test) = imdb.load_data(
num_words = TOP_N_WORDS
)
# Transform dataset from variable-length word sequences to a
# binary valued dense matrix.
@ruggeri
ruggeri / heaps.md
Last active February 26, 2018 02:01

Heaps

Priority Queue

Heaps are an implementation of the priority queue abstract data type:

  • insert(entry, priority).
    • priority is an integer priority. Entries with "higher priority" will be extracted before entries with "lower priority."
  • Lower number often is "higher priority." This makes sense

Binary Search Trees


Operations

  • find
  • insert
  • delete
  • Each has time complexity proportional to depth of the tree.