Skip to content

Instantly share code, notes, and snippets.

/**
1728 * Code shared by String and StringBuffer to do searches. The
1729 * source is the character array being searched, and the target
1730 * is the string being searched for.
1731 *
1732 * @param source the characters being searched.
1733 * @param sourceOffset offset of the source string.
1734 * @param sourceCount count of the source string.
1735 * @param target the characters being searched for.
1736 * @param targetOffset offset of the target string.
module Golem::Mongo
# Golem::Mongo::ReplSet is an abstraction around a mongo replica set
# that provides methods for performing administrative functions. It
# implements equivalents to a number of the rs.* helpers in the
# mongo shell, as well as higher-level functions for operations such
# as managing failovers
class ReplSet
@nelhage
nelhage / is_in_epoll.rb
Created March 28, 2014 06:12
Is this pid (using epoll, on amd64, on EM 1.0.0) currently blocked in the EM mainloop?
def is_in_eventmachine(pid)
begin
syscall = File.read("/proc/#{pid}/syscall")
rescue Errno::ENOENT
return false
end
words = syscall.split(" ")
if words.length != 9
# Running, or in an fault handler
# -*- coding: utf-8 -*-
class Charge
def visit(obj, method, *args)
obj.public_send(:"#{method}_for_charge", args)
end
end
class Refund
def visit(obj, method, *args)
obj.public_send(:"#{method}_for_refund", args)
[nelhage@anarchique:~]$ sudo dpkg-divert --divert /usr/share/update-notifier/notify-reboot-required.orig --rename --add /usr/share/update-notifier/notify-reboot-required
Adding 'local diversion of /usr/share/update-notifier/notify-reboot-required to /usr/share/update-notifier/notify-reboot-required.orig'
[nelhage@anarchique:~]$ echo $'#!/bin/sh\nexit 0' | sudo tee /usr/share/update-notifier/notify-reboot-required
#!/bin/sh
exit 0
[nelhage@anarchique:~]$ sudo chmod +x /usr/share/update-notifier/notify-reboot-required
[nelhage@anarchique:~]$ sudo rm /var/run/reboot-required*
class To
def initialize(object)
@object = object
end
def method_missing(method, *args)
@object.public_send("to_#{method}", *args)
end
end
@nelhage
nelhage / read.go
Last active August 29, 2015 14:00
package reader
import "io"
func getRead(r io.Reader) func([]byte) (int, error) {
return r.Read
}
// partial output of `go tool 6g -S read.go`:
//
[nelhage@aeronautique:~]$ time ruby -rbson -e1
real 0m0.281s
user 0m0.233s
sys 0m0.042s
[nelhage@aeronautique:~]$ cd /tmp/
[nelhage@aeronautique:/tmp]$ cat > bson.go
package main
import _ "labix.org/v2/mgo/bson"
func main() {}
[A simple Brainfuck quine. This program is not a quine, but if you run
it, its output (which will be the same as the input, but stripped of
all comments and whitespace) will be.
We're going to represent things using four tape cells as one logical
struct. Skip right four cells to leave an empty start-of-tape marker.]
>>>>
>>>>
+++++>>>>+++++>>>>+++++>>>>+++++>>>>++>>>>+++++>>>>+++++>>>>+++++>>>>+++++>>>>+++>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+++++++>>>>+++++++>>>>+++++++>>>>+++++++>>>>++>>>>++++>>>>+++>>>>++>>>>+++++++>>>>+++++++>>>>+++++++>>>>+++>>>>++++++>>>>++++++>>>>++++++>>>>++++++>>>>++>>>>++++++>>>>++++++>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>++>>>>+++++>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>++++++>>>>++++>>>>+++>>>>+++++>>>>+>>>>+++++>>>>++>>>>++++++>>>>+++++++>>>>++++++>>>>++++++>>>>+>>>>+++++>>>>+++++>>>>+++++>>>>++++>>>>+++>>>>++++++>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+>>>>+++++++>>>>+++++++>>>>+++++++>>>>+++++++>>>>+++++>>>>+>>>>+>>>>+>>>>+>>>>++>>>>++++>>>>++++++>>>>++++>>>>++++>>>>++++>>