Skip to content

Instantly share code, notes, and snippets.

@Sgeo
Sgeo / pry crash
Created August 19, 2011 09:39
Pry crash
pry(main)> Object.methods
C:/Ruby192/lib/ruby/gems/1.9.1/gems/pry-0.9.3-x86-mingw32/lib/pry/helpers/base_h
elpers.rb:92:in `block in simple_pager': undefined local variable or method `out
put' for Pry::Helpers::BaseHelpers:Module (NameError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/pry-0.9.3-x86-mingw32/lib/pry/h
elpers/base_helpers.rb:91:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/pry-0.9.3-x86-mingw32/lib/pry/h
elpers/base_helpers.rb:91:in `each_slice'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/pry-0.9.3-x86-mingw32/lib/pry/h
elpers/base_helpers.rb:91:in `simple_pager'
Question Answer given Answer expected
Is your character an adult man? Probably not Probably
Has your character really existed? Probably not Probably
Does your character have legs? Probably not No
Does your character use a cane? Probably not No
Is your character on an album cover? Probably not No
Does your character wield electricity/lightning as a weapon? Probably not No
Does your character have claws? Probably not No
Is your character Muslim? Probably not No
Is your character hired to kill people? Probably not No
@Sgeo
Sgeo / gist:3846768
Created October 7, 2012 01:30
delimonads
(ns delimonads.core
(:require [monads.core :as m])
(:use delimc.core))
(reset
(defn bind-cont
"Binds its monadic value argument to the continuation.
Easy to understand explanation: (f (bind-cont x) y) becomes do {x' <- x; f x' y}"
[monadic-value]
@Sgeo
Sgeo / gist:4005862
Created November 3, 2012 04:18
Some hypothetical test.
#_(deftest maybe-plus
(is (= :bogus
@(m/plus [m/maybe-zero-val
(m/do m/maybe
[_ (m/maybe 1)]
(throw (Exception. "Should not be thrown")))]))))
DynamicVariable subclass: #DynamicGeneratorVar
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Sgeo-DynamicGenerator'!
!DynamicGeneratorVar commentStamp: 'SethJGold 1/14/2013 06:41' prior: 0!
DynamicGeneratorVar holds the current DynamicGenerator in use. Should not be used directly by client code.!
waitFor: anAnnouncementClass
"Blocks the current process until anAnnouncementClass is announced.
Note that synchronous code using this method runs the risk of missing announcements."
| val sem |
sem := Semaphore new.
self on: anAnnouncementClass do: [:ann | val := ann. sem signal].
sem wait.
^val.
@Sgeo
Sgeo / gist:4717537
Created February 5, 2013 20:52
Haskell code to emulate in Scala and Clojure. Idea for the functions taken from http://www.scala-lang.org/api/current/index.html#scala.util.control.TailCalls$
listEven :: [a] -> Bool
listEven [] = True
listEven (_:xs) = listOdd xs
listOdd :: [a] -> Bool
listOdd [] = False
listOdd (_:xs) = listEven xs
@Sgeo
Sgeo / gist:4717756
Created February 5, 2013 21:20
Demonstration of mutually recursive tail-call optimized functions in Scala.
/* code taken verbatim from http://www.scala-lang.org/api/current/index.html#scala.util.control.TailCalls$ */
def isEven(xs: List[Int]): TailRec[Boolean] =
if (xs.isEmpty) done(true) else tailcall(isOdd(xs.tail))
def isOdd(xs: List[Int]): TailRec[Boolean] =
if (xs.isEmpty) done(false) else tailcall(isEven(xs.tail))
REBOL [
Title: "Monads"
Author: "Sgeo"
]
do-monad: func [
monad "An object containing a /bind and a /return."
assigns [block!]
result [block!]
/local ma f next-assigns arg
use [num] [
num: 0
count: func [x] [
num: num + x
print num
]
]
count 1 count 1 count 1