Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / gist:1203861
Created September 8, 2011 16:39 — forked from stevej/gist:1177289
For when you accidentally write Scala in Ruby
# for when I acccidentally try to val foo = bar something.
def val x
x
end
val foo = 1 + 2
puts "#{foo}" # ==> 3
# Yeah, just jam that into Kernel like everybody else. why not?
@fogus
fogus / ppartial.clj
Created September 9, 2011 12:03 — forked from alandipert/ppartial.clj
positional partial
;;; positional partial for giggles
;;; use #(foo %1 %2) instead
(defn- placeholder-indices
([template]
(placeholder-indices '_ template))
([placeholder-sym template]
(->> template
(map vector (range))
(filter (comp (partial = placeholder-sym) last))
@fogus
fogus / gist:1211467
Created September 12, 2011 14:54 — forked from odyssomay/gist:1209498
trace forms
(ns trace
(:use clojure.pprint))
(def *ignore*
'#{def quote var try fn* monitor-enter monitor-exit})
(defmulti trace-special-form (fn [form] (first form)))
(defn- trace-bindings [bindings]
(vec (apply concat
@fogus
fogus / serial.clj
Created September 13, 2011 16:54 — forked from alandipert/serial.clj
serial I/O with blocking queue and trampoline
(defn serial-processor
"Given BlockingQueue q, returns a map of two functions, :process and :stop.
:process takes a constant function (presumably for side effects) and
adds it to the queue, where it is invoked serially with respect to
other functions added via :process.
:stop takes a non-function value to return, blocks on the completion
of remaining process functions, and returns the value."
[^java.util.concurrent.BlockingQueue q]
@fogus
fogus / capybara cheat sheet
Created September 13, 2011 18:08
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@fogus
fogus / logging.rb
Created September 14, 2011 12:12 — forked from DRMacIver/logging.rb
Split logging
# Capture stdout and stderr in a named file (while still writing to current stdout and stderr) for a block then restore old behaviour
def capture_output(file)
read, write = IO.pipe
pid = fork
unless pid
write.close
$stdin.reopen(read)
@fogus
fogus / ruby fork rsync
Created September 14, 2011 12:22 — forked from drio/ruby fork rsync
ruby fork rsync
#!/usr/bin/env ruby19
#
ses = %w{
/stornext/snfs1/next-gen/solid/results/solid0301/0301_20091103_1_SP/AWG_TCGA_GBM_02_T_000sA_01003244545_1/results.F1B1
/stornext/snfs1/next-gen/solid/results/solid0301/0301_20091103_1_SP/AWG_TCGA_GBM_02_T_000sA_01003244545_2/results.F1B1
/stornext/snfs1/next-gen/solid/results/solid0301/0301_20091103_1_SP/ANG_HSAP_NG_003sA_01003244545_3/results.F1B1
/stornext/snfs1/next-gen/solid/results/solid0301/0301_20091103_1_SP/ANG_HSAP_NG_003sA_01003244545_4/results.F1B1
/stornext/snfs4/next-gen/solid/results/solid0446/0446_20091125_1_SL/AWG_TCGA_OVA_01_T_000sA_01003244597_1/results.F1B1
}
@fogus
fogus / rlsp.rb
Created September 14, 2011 12:23 — forked from davidblair/rlsp.rb
LISP in <200 lines of Ruby (Fork of work done by h0rs3r4dish)
#!/usr/bin/ruby
RLSP_VERSION = "1.4.1"
class Lambda
attr_accessor :args, :body
def initialize(args=[],body="")
@args = (args.class == Array) ? args : [args]
@body = body
end
@fogus
fogus / doublefork.rb
Created September 14, 2011 12:24
Double fork a Ruby process.
raise 'Must run as root' if Process.euid != 0
p1 = Process.fork {
# p1 is now running independent of, and parallel to the calling process
Process.setsid
p2 = Process.fork {
# p2 is now running independent of, and parallel to p1
$0 = 'mydaemon'
pidfile = File.new('/var/run/mydaemon.pid', 'w')
pidfile.chmod( 0644 )
pidfile.puts "#{Process.pid}"
#!/usr/bin/env ruby
#
# forking supervisor - forks workers and replaces dead workers.
# start it in one console, send signals to it from another console.
#
require 'rubygems'
require 'daemons/daemonize'