Skip to content

Instantly share code, notes, and snippets.

@andrewcsmith
andrewcsmith / loadashMixins.js
Created September 5, 2018 21:27
camelCase the things
import _ from 'lodash'
// Transforms a function into a deep function
_.mixin({
deeply: function (map) {
var deeplyArray = function (obj, fn) {
return obj.map(function(x) {
return _.isPlainObject(x) ? _.deeply(map)(x, fn) : x;
})
}
@andrewcsmith
andrewcsmith / cartesian.py
Created June 20, 2018 21:50
All permutations in tensorflow
import tensorflow as tf
import numpy as np
def cartesian_graph(a):
"""
Given at least 2 elements in a, generates the Cartesian product of all
elements in the list.
"""
tile_a = tf.expand_dims(tf.tile(tf.expand_dims(a[0], 1), [1, tf.shape(a[1])[0]]), 2)
tile_b = tf.expand_dims(tf.tile(tf.expand_dims(a[1], 0), [tf.shape(a[0])[0], 1]), 2)
@andrewcsmith
andrewcsmith / main.rs
Created June 9, 2018 17:15
Broken sine problem
hi
@andrewcsmith
andrewcsmith / output
Last active January 22, 2018 22:03
lilypond error: regression 2.19.17 to 2.19.18
[vagrant@bazinga ly_test]$ lyp use 2.19.18
Using Lilypond version 2.19.18
[vagrant@bazinga ly_test]$ lyp compile test.ly
Lyp 1.3.5
GNU LilyPond 2.19.18
Processing `/tmp/lyp/wrappers/test.ly'
Parsing...
Interpreting music...
Preprocessing graphical objects...
Finding the ideal number of pages...
@andrewcsmith
andrewcsmith / split.rs
Created October 6, 2017 19:20
Splits a signal into two parts
use std::sync::Arc;
use std::cell::RefCell;
use bounded_spsc_queue::{Producer, Consumer, make};
use sample::Signal;
const SPLIT_BUFFER_SIZE: usize = 512;
#[allow(dead_code)]
@andrewcsmith
andrewcsmith / bench.rs
Last active September 1, 2017 03:51
Benchmarks for various Atomic and non-Atomic operations
#![feature(test, integer_atomics)]
// On my computer.
//
// test bench_increment_arc_data ... bench: 28,315,200 ns/iter (+/- 3,614,573)
// test bench_increment_cell_data ... bench: 3,905,437 ns/iter (+/- 826,350)
// test bench_increment_raw_data ... bench: 3,895,535 ns/iter (+/- 1,103,250)
// test bench_increment_rc_data ... bench: 3,771,218 ns/iter (+/- 682,398)
// test bench_spawn_thread_and_increment ... bench: 34,876,612 ns/iter (+/- 4,553,297)
// test bench_spawn_thread_and_increment_f64 ... bench: 55,028,376 ns/iter (+/- 6,402,499)
Output from rust-lldb - panic on LU Factorization
frame #4: 0x0000000100060cb1 partition`rulinalg::matrix::{{impl}}::det<f64>(self=&0x101bce000) + 2417 at mod.rs:506
503 (self[[0, 1]] * self[[1, 0]] * self[[2, 2]]) -
504 (self[[0, 2]] * self[[1, 1]] * self[[2, 0]])
505 } else {
-> 506 let (l, u, p) = self.lup_decomp().expect("Could not compute LUP decomposition.");
507
508 let mut d = T::one();
509
@andrewcsmith
andrewcsmith / main.rs
Created September 2, 2016 04:57
Sound similarity matching
extern crate soundsym;
extern crate vox_box;
extern crate portaudio;
extern crate hound;
extern crate crossbeam;
extern crate bounded_spsc_queue;
use soundsym::*;
use portaudio::*;
@andrewcsmith
andrewcsmith / backtrace
Created July 18, 2016 14:22
Rubinius Issue #3679 backtrace
* thread #1: tid = 0x72791c, 0x000000010d1abe30 rbx`rubinius::GlobalCache::resolve_i(rubinius::State*, rubinius::Symbol*, rubinius::Dispatch&, rubinius::LookupData&) + 240, name = 'ruby.main', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x52)
* frame #0: 0x000000010d1abe30 rbx`rubinius::GlobalCache::resolve_i(rubinius::State*, rubinius::Symbol*, rubinius::Dispatch&, rubinius::LookupData&) + 240
frame #1: 0x000000010d199d22 rbx`rubinius::Dispatch::send(rubinius::State*, rubinius::LookupData&, rubinius::Arguments&, rubinius::MethodMissingReason) + 50
frame #2: 0x000000010d2aee8b rbx`rubinius::Object::send(rubinius::State*, rubinius::Symbol*, rubinius::Array*, rubinius::Object*, bool) + 219
frame #3: 0x000000010d2ee85c rbx`rubinius::memory::ManagedFinalizer::finalize(rubinius::State*) + 124
frame #4: 0x000000010d2ef276 rbx`rubinius::memory::FinalizerThread::finish(rubinius::State*) + 198
frame #5: 0x000000010d19d6ff rbx`rubinius::Environment::halt(rubinius
@andrewcsmith
andrewcsmith / hellish_parse_code.rs
Created April 27, 2016 19:12
hellish parse code
// TODO: macro-ify this
fn parse_input() -> Result<Input, io::Error> {
let q = regex!(r"^[qQ]\s+$");
let o = regex!(r"^[oO]\s+$");
let p = regex!(r"^[pP]\s+$");
let d = regex!(r"^[dD]\s+$");
let clear = regex!(r"^clear\s+$");
let cluster = regex!(r"^cluster (\d+)\s+$");
let partition = regex!(r"^partition (\d+), (\d+)");
let split = regex!(r"^split (\d+), (\d+)");