Skip to content

Instantly share code, notes, and snippets.

;variants of the code from point #2 of:
; http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses
;original
(apply merge-with +
(pmap count-lines
(partition-all *batch-size*
(line-seq (reader filename)))))
@kyanny
kyanny / echo.rb
Created February 24, 2010 17:43
Ruby socket TCPServer echo server
require 'socket'
gs = TCPServer.open(0)
socks = [gs]
addr = gs.addr
addr.shift
puts "server is on #{addr.join(':')}"
while true
nsock = select(socks)
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@jeffkreeftmeijer
jeffkreeftmeijer / bassie.png
Created April 11, 2011 12:01
Colored image blob detection
bassie.png
@jhartikainen
jhartikainen / DynLoad.hs
Created August 20, 2011 11:31
Module for loading modules dynamically in Haskell
{-# LANGUAGE ScopedTypeVariables #-}
module DynLoad (
loadSourceGhc,
execFnGhc
) where
import Control.Exception (throw)
import GHC hiding (loadModule)
import GHC.Paths (libdir)
import HscTypes (SourceError, srcErrorMessages)
@bpsm
bpsm / gist:1858654
Created February 18, 2012 10:31
g[un]zip input to output
(ns clj-gunzip.core
(:require [clojure.java.io :as io])
(:require [clojure.string :as str])
(:import java.util.zip.GZIPInputStream
java.util.zip.GZIPOutputStream))
(defn gunzip
"Writes the contents of input to output, decompressed.
input: something which can be opened by io/input-stream.
@endolith
endolith / readme.md
Last active May 7, 2024 08:38
Sethares dissmeasure function in Python

Adaptation of Sethares' dissonance measurement function to Python

Example is meant to match the curve in Figure 3:

Figure 3

Original model used products of the two amplitudes a1⋅a2, but this was changed to minimum of the two amplitudes min(a1, a2), as explained in G: Analysis of the Time Domain Model appendix of Tuning, Timbre, Spectrum, Scale.

This weighting is incorporated into the dissonance model (E.2) by assuming that the roughness is proportional to the loudness of the beating. ... Thus, the amplitude of the beating is given by the minimum of the two amplitudes.

@ryin
ryin / tmux_local_install.sh
Last active April 23, 2024 01:06
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8
@mahata
mahata / sha-512.clj
Created July 21, 2012 02:34
sha-512 in clojure
;; (let [md (. java.security.MessageDigest getInstance "sha-512")]
;; (. md update (.getBytes "helloworld"))
;; (let [bytes (. md digest)]
;; (reduce (fn [n x] (str n (format "%02x" x))) "" bytes)))
;; (let [md (. java.security.MessageDigest getInstance "sha-512")]
;; (. md update (.getBytes "helloworld"))
;; (let [bytes (. md digest)]
;; (reduce #(str %1 (format "%02x" %2)) "" bytes)))
@HeinrichApfelmus
HeinrichApfelmus / GameLoop.hs
Created October 2, 2012 16:49
Game loop in reactive-banana
{------------------------------------------------------------------------------
reactive-banana
Implementation of an "industry strength" game loop with fixed time step
and variable fps.
See also http://gafferongames.com/game-physics/fix-your-timestep/
-------------------------------------------------------------------------------}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where