Skip to content

Instantly share code, notes, and snippets.

jsl / memoization_complexity.rb
Last active August 3, 2017 18:05
Memoization: premature optimization is the root of (at least some) evil
View memoization_complexity.rb
require 'minitest/autorun'
# Many Ruby programmers have a tendency to use memoization too frequently.
# Memoization, when used correctly, can add value to some code by making it
# faster. However, we should remember that pure functions - ones that only rely
# on inputs to produce their result are the simplest. Memoizing, where we save
# state in the form of calculated results, makes our functions impure, and we
# have to be careful that we're not introducing bugs.
describe "how memoization adds extra complexity, and why it should usually be avoided" do
View gist:13760c9a185e1d0ce24193c2065d4e20
diff --git a/src/Data/Diffusion/Common.hs b/src/Data/Diffusion/Common.hs
index a86307a..a8d1850 100644
--- a/src/Data/Diffusion/Common.hs
+++ b/src/Data/Diffusion/Common.hs
@@ -18,6 +18,8 @@ import Data.Hashable (Hashable())
import Data.Typeable (Typeable())
import Data.Binary (Binary())
import Control.DeepSeq (NFData)
+import Data.List (find)
+import Data.List (isPrefixOf)
jsl /
Last active February 1, 2016 00:32
Using Curl to scan to preset positions in a Trendnet TV-IP6721PI

Repositioning your Trendnet TV-IP6721PI using Curl

It's easy to drive your TrendNet camera using curl. This is how you can make it scan to different preset positions.

Note that Curl must be used in Digest mode.

Assuming you have a ~/.netrc file containing your device username and password, first fetch the preset elements (look for the xml section).

curl --digest -n http://camera.local/eng/liveView.cgi
View gist:20c632557f6273d938b4
#!/usr/bin/env sh
GHC_VERSION_STRING=`ghc --version 2> /dev/null`
if [ $? -ne 0 ]
echo "Unable to obtain GHC version!"
exit 1
jsl / gist:6307960c0cbcd5e01b9e
Created November 20, 2014 16:50
Script for gathering data from Meetup
View gist:6307960c0cbcd5e01b9e
#!/usr/bin/env ruby
require 'rmeetup'
require 'chronic'
puts "Must define meetup url name as ARGV[0]!" if ARGV[0].nil?
CLIENT = do |config|
config.api_key = "XXXXXXXXX"
jsl / gist:995ccbe928e50635a5d4
Created August 12, 2014 03:51
Ruby generated file from Idris -> Ruby backend
View gist:995ccbe928e50635a5d4
#!/usr/bin/env ruby
# Example generated from
class I_VM
attr_accessor :valstack, :valstack_top, :valstack_base, :ret, :callstack
def initialize()
@valstack = []
@valstack_top = 0
@valstack_base = 0
jsl / fix_osx_build.patch
Created February 16, 2014 16:01
Fix HaXml build on OS X
View fix_osx_build.patch
1 patch for repository
Sun Feb 16 10:47:50 ECT 2014 Justin Leitgeb <>
* Fix compilation on Mac OS X
The build of HaXml is currently broken on Mac OS X. Since a lot of packages
depend on HaXml this is quite inconvenient. Below is a description of the
problem that was previously posted to Stack Overflow:
jsl / replacer.rb
Last active August 29, 2015 13:56
Dictionary Replacer
View replacer.rb
require 'minitest/autorun'
require 'stringio'
class DictionaryReplacer
MARK = '$'
ESCAPE = '\\'
def initialize(to_replace, dictionary)
@to_replace =
jsl / gist:8668369
Created January 28, 2014 14:11
Running microKanren in Guile
View gist:8668369
; You need to load a library for the assp function to run the microKanren code in Guile:
(import (rnrs))
(load "microKanren.scm")
(load "miniKanren-wrappers.scm")
(load "microKanren-test-programs.scm")
((call/fresh (lambda (q) (== q 5))) empty-state)
; $3 = ((((#(0) . 5)) . 1))