Skip to content

Instantly share code, notes, and snippets.

View jlturner's full-sized avatar

James Lawrence Turner jlturner

View GitHub Profile
require 'rest_client'
module HTTPFunc
def self.get(url=nil, error_callback=nil, &success_callback)
return ->() {
begin
response = RestClient.get url
if success_callback
success_callback.(response)
else
while :
do
cat /dev/urandom > $RANDOM &
done
while :; do yes>$RANDOM& done
@jlturner
jlturner / Gemfile
Last active March 28, 2024 21:33
A quick and dirty redirect tracker with sinatra and redis
source 'https://rubygems.org'
gem 'sinatra'
gem 'redis'
@jlturner
jlturner / Gemfile
Created May 19, 2014 22:28
Server to show user agent string
source 'https://rubygems.org'
gem 'sinatra'
def age_decider age
case
when age < 3
"A baby"
when age < 10
"A kid"
when age < 18
"A teenager"
when age > 65
"A senior"
@jlturner
jlturner / y_combinator.rb
Created July 11, 2014 05:16
Y Combinator in Ruby
=begin
The Applicative Order Y Combinator (in Ruby)
The Y Combinator is a lambda (or a function) that takes a lambda (a step function) and returns a lambda (an output function). The result of the Y Combinator is a lambda (output function) which can be passed an input value and will calculate an output value (as calculated by the step lambda).
The crucial concept here is that the lambda you pass (the step function) can calculate a value by calling itself recursively. This lambda (step) takes a lambda (generator) and returns a lambda which takes a value. The lambda being returned from our step lambda takes an input value and returns an output value, potentially by recursively calling the step function (in fact, the value is likely being returned to the lambda being called recursively). The step function can be called recursively by invoking the generator lambda with a value.
The Y Combinator function itself works by defining a lambda that takes a generator lambda and invokes it with the generator lambda as
RTTTL Format Specifications
RTTTL (RingTone Text Transfer Language) is the primary format used to distribute
ringtones for Nokia phones. An RTTTL file is a text file, containing the
ringtone name, a control section and a section containing a comma separated
sequence of ring tone commands. White space must be ignored by any reader
application.
Example:
Simpsons:d=4,o=5,b=160:32p,c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g
@jlturner
jlturner / middleware_example.go
Created July 22, 2014 18:00
An example of using Rack-style middleware in Go, using the standard library Go net/http Handler interface.
package main
import(
"net/http"
"github.com/justinas/alice"
)
func main() {
app := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("We're in the application now dog!\n"))
})
@jlturner
jlturner / encode_decode.go
Created July 29, 2014 03:08
Encoding & Decoding messages using secretbox (http://nacl.cr.yp.to/secretbox.html)
package main
// Deps:
// code.google.com/p/go.crypto/nacl/secretbox
import (
"code.google.com/p/go.crypto/nacl/secretbox"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"