Skip to content

Instantly share code, notes, and snippets.

Jonathan Raphaelson lygaret

View GitHub Profile
@lygaret
lygaret / clustering.rb
Created Jul 13, 2017
ruby module for kmeans clustering (1d)
View clustering.rb
# Methods for clustering data
module Clustering
# k-means clustering for 1d data
# pass a block to project from an element into a number
def self.kmeans_1d(data, k: 2, &projection)
return [data] if k == 1
if data.to_a.uniq(&projection).length < 2
return [data].concat((k - 1).times.collect { [] })
end
@lygaret
lygaret / PKGBUILD
Created Feb 21, 2017
PKGBUILD for installing npm2arch from @MazeChaZer's updated dependencies branch
View PKGBUILD
_npmname=npm2arch
_npmver=0.1.19
pkgname=nodejs-npm2arch-updated-deps-git # All lowercase
pkgver=0.1.19
pkgrel=2
pkgdesc="Convert NPM package to a PKGBUILD for ArchLinux, patched for recent dependencies."
arch=(any)
url="https://github.com/Filirom1/npm2arch"
license=(MIT)
depends=('nodejs' 'npm' )
View keybase.md

Keybase proof

I hereby claim:

  • I am lygaret on github.
  • I am lygaret (https://keybase.io/lygaret) on keybase.
  • I have a public key ASCH_bCflDF9Q17IZVv7ox1t0p56et_SBdQSk5MQ-tFOYgo

To claim this, I am signing this object:

@lygaret
lygaret / 1.dispatch.md
Last active Jul 8, 2016
Chrome Extension Helpers
View 1.dispatch.md

dispatch helpers

createMessageDispatcher creates a message listener which will call a method on the handler argument, based on the contents of the message that's passed from elsewhere. It does this by injecting the (potentially error causing) method into a promise chain, by sticking it inside a custom thenable, which gives us much nicer error handling.

example

@lygaret
lygaret / octet_finder.rb
Last active Feb 19, 2016
find octets in a string with no periods
View octet_finder.rb
#!/bin/env ruby
def octet?(str)
(0...256) === str.to_i
end
def octets(str, current = [], output = [])
# bail if there's nothing left to get
if str.nil? || str.empty?
View csv_parser.rb
#!/bin/env ruby
STOP_QUOTED_RE = /(?:[^"]|"{2})(",)/
STOP_NORMAL_RE = /(,)/
# returns [chunk, rest], rest is nil at the end
def read_chunk(line)
quoted = line[0] == '"'
start = quoted ? 1 : 0
View overtone-1.clj
;; https://soundcloud.com/jonathan-raphaelson/overtone-experiment-1
(ns overtonetute.core
[:use [overtone.live]])
(use 'overtone.inst.drum)
(definst swave [freq 440 attack 0.001 sustain 0.4 release 0.1 vol 0.005]
(lpf (* (env-gen (env-lin attack sustain release) 1 1 0 1)
(sin-osc freq)
@lygaret
lygaret / env.clj
Last active Aug 29, 2015
not really useful config loader
View env.clj
(ns my.env
(:require [clojure.edn :as edn]))
(defn- get-resource [path]
(let [classloader (java.lang.ClassLoader/getSystemClassLoader)]
(.getResource classloader path)))
(defn- read-config-file []
(let [url (get-resource "config.edn")]
(slurp url)))
@lygaret
lygaret / index.js
Last active Apr 20, 2019
ES6 Quasi-Literal for JSX
View index.js
define(function(require) {
var React = require('react');
var paramRegex = /__(\d)+/;
var parser = new DOMParser();
var errorDoc = parser.parseFromString('INVALID', 'text/xml');
var errorNs = errorDoc.getElementsByTagName("parsererror")[0].namespaceURI;
// turns the array of string parts into a DOM
// throws if the result is an invalid XML document.
@lygaret
lygaret / tutticolori.vim
Created Jul 8, 2010
port of the espresso color theme to vim
We couldn’t find that file to show.
You can’t perform that action at this time.