Skip to content

Instantly share code, notes, and snippets.

View stevej's full-sized avatar

Steve Jenson stevej

View GitHub Profile
@stevej
stevej / gist:158982
Created July 30, 2009 22:51
multi-way-merge as a tail recursive function in Scala
trait Merge {
def m_way_merge(out: List[Int], xs: List[List[Int]]): List[Int] = {
val arrays = xs.remove(_ == Nil)
if (arrays.isEmpty) {
out
} else {
val idx: Int = arrays.findIndexOf((xs: List[Int]) => xs.head == arrays.map(_.head).sort(_ < _).head)
m_way_merge(out ::: List(arrays(idx).head), arrays.slice(0, idx) ::: arrays.slice(idx + 1, arrays.length) ::: List(arrays(idx).tail))
}
}
@stevej
stevej / doc_fix.patch
Created November 19, 2009 18:55
Fixing documentation output to say 'def'
Index: src/main/scala/sbt/DefaultProject.scala
===================================================================
--- src/main/scala/sbt/DefaultProject.scala (revision 1129)
+++ src/main/scala/sbt/DefaultProject.scala (working copy)
@@ -445,7 +445,7 @@
{
log.warn("No Main-Class attribute will be added automatically added:")
log.warn("Multiple classes with a main method were detected. Specify main class explicitly with:")
- log.warn(" override mainClass = Some(\"className\")")
+ log.warn(" override def mainClass = Some(\"className\")")
object FooBar extends Specification {
"Foo" should {
var i = 0
doFirst { i = 1 }
doLast { i = 0 }
"this should not be 1" in {
i mustEqual 0
}
@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]
/**
* 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 / 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?
@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: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
;; 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 / 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'