Skip to content

Instantly share code, notes, and snippets.

View stevej's full-sized avatar

Steve Jenson stevej

View GitHub Profile
@stevej
stevej / board_searcher.rb
Created November 2, 2012 22:28
Letterpress board searcher
#/usr/bin/env ruby
# A brute-force letterpress board searcher. It takes about 90 seconds to search a board.
#
# Good uses: train on your vocabulary with boards you lost on.
#
# LAZY AND STUPID CHEATERS: DO NOT USE THIS FOR CHEATING. CHEATERS NEVER WIN.
class BoardSearcher
attr_reader :board
@stevej
stevej / gist:3868225
Created October 10, 2012 20:29 — forked from anonymous/gist:3868185
Queue Anti-patterns (an argument in DMs)
I can make a case that queues only do what people want if you don’t consider failure cases.
Qs are empty (normal) or full (fail). Normally things are processed quickly. Failure case processing time is unbounded (or “too long”).
Solution is always “dump the Q”. Which means you do care about how long it takes to process items. So you want the queue to always be empty
Which means you only want a non-failing Q.
So why not admit it, use in-proc buffers, run enough servers to handle load? Reject work up front instead of dropping oldest items w/…
@stevej
stevej / bit_squat.rb
Created March 26, 2012 23:42
generate bit-squattable domains
#!/usr/bin/ruby
#
# find all domains that bit-squat a given domain.
#
# Based on this article: http://domainincite.com/bit-squatting-%E2%80%93-the-latest-risk-to-domain-name-owners/
#
# improvements: use a regex rather than URI.parse
require 'uri'
;; emacsd-tile.el -- tiling windows for emacs
(defun swap-with (dir)
(interactive)
(let ((other-window (windmove-find-other-window dir)))
(when other-window
(let* ((this-window (selected-window))
(this-buffer (window-buffer this-window))
(other-buffer (window-buffer other-window))
(this-start (window-start this-window))
@stevej
stevej / gist:1303004
Created October 21, 2011 03:01 — forked from mccv/gist:1259343
OAuth with finagle streaming
import java.net._
import java.util.UUID
import com.twitter.conversions.time._
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.util._
import java.nio.charset.Charset
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer}
import org.jboss.netty.handler.codec.http._
import com.twitter.finagle.stream.Stream
@stevej
stevej / scoping.pl
Created September 15, 2011 00:44
Just a reminder that Perl had both dynamic and static scoping
$x = 0;
sub f { return $x; }
sub g { my $x = 1; return f(); }
print g()."\n";
# the power of scoping compels you, change global $y!
$y = 0;
sub f1 { return $y; }
sub g1 { local $y = 1; return f1(); }
@stevej
stevej / gist:1177289
Created August 28, 2011 22:00
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?
/**
* This is an exmaple of how to program in scala without the use of imports or
* global namespaces. Foo seeing Bar's members does not rely on the fact
* that they are in the same package.
*
* Inspired by Gilad Bracha's talk at the Emerging Languages conference in 2010.
*
* Built with scala 2.8.0-final
*/
@stevej
stevej / red_led.asm
Created June 11, 2010 04:01
A simple example of doing memory-mapped IO on an ARM7 (this turns on a Red LED for a UberBoard v2)
.equiv GPIO_BASE_ADDR, 0x0E0028000
.equiv IOCLR0, GPIO_BASE_ADDR + 0x0C
.equiv IODIR0, GPIO_BASE_ADDR + 0x08
.equiv RED_LED, 1 << 18
.globl _start
_start:
ldr r1, =IODIR0
ldr r2, =RED_LED
str r2, [r1]
object FooBar extends Specification {
"Foo" should {
var i = 0
doFirst { i = 1 }
doLast { i = 0 }
"this should not be 1" in {
i mustEqual 0
}