This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select? | |
rb_thread_schedule() is the guts of the thread scheduler, it traverses | |
over the linked list of threads (several times) to find the next one | |
to switch into. The function is long (250 lines) and messy, and covers | |
all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED, | |
KILLED) and wait state (FD, SELECT, TIME, JOIN, PID). | |
If there are no threads doing i/o or waiting on a timeout, | |
rb_thread_schedule() picks another thread from the list (considering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Update 7 Oct 2010: | |
# - This example does *not* appear to work with Chrome >=6.0. Apparently, | |
# the WebSocket protocol implementation in the cramp gem does not work | |
# well with Chrome's (newer) WebSocket implementation. | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sh function to murder all running processes matching a pattern | |
# thanks 3n: http://twitter.com/3n/status/19113206105 | |
murder () { | |
ps | grep $1 | grep -v grep | awk '{print $1}' | xargs kill -9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proc | |
def <<(other) | |
case other | |
when Proc | |
Proc.new do |*args| | |
call(other.call(*args)) | |
end | |
else | |
call(other) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <hiredis/libevent.h> | |
void getCallback(redisContext *c, redisReply *reply, const void *privdata) { | |
printf("argv[%s]: %s\n", (const char*)privdata, reply->reply); | |
/* Disconnect after receiving the reply to GET */ | |
redisDisconnect(c); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This core extension customizes XML and JSON serialization in Mongoid::Document | |
# objects: | |
# * Serializes BSON::ObjectIDs as strings in XML | |
# * Removes leading underscores from attributes (such as _id, _type) | |
# * Allows documents to customize serialization even further by declaring a | |
# `serialize_attributes!` method, e.g.: | |
# def serialize_attributes!(attribute_hash) | |
# attribute_hash.delete(:unnecessary_key) | |
# attribute_hash[:password] = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method | |
class Sendable(a: AnyRef) { | |
val methods = a.getClass.getDeclaredMethods | |
def wrapByte(b: Byte) = new java.lang.Byte(b) | |
def wrapShort(s: Short) = new java.lang.Short(s) | |
def wrapInt(i: Int) = new java.lang.Integer(i) | |
def wrapLong(l: Long) = new java.lang.Long(l) | |
def wrapFloat(f: Float) = new java.lang.Float(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim color file | |
" Converted from Textmate theme Twilight using Coloration v0.2.5 (http://github.com/sickill/coloration) | |
set background=dark | |
highlight clear | |
if exists("syntax_on") | |
syntax reset | |
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Packaged version of singly-linked list based FIFO queue described | |
;; by Paul Graham in Ansi Common Lisp. Functions names changed not to | |
;; conflict with the lock free queue in sb-concurrency. | |
;; Taken from | |
;; http://cs.northwestern.edu/academics/courses/325/programs/graham.lisp | |
(defpackage :pg-queue (:use :cl)) | |
(in-package :pg-queue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.banksimple.util | |
private[util] final class Effectful[T](val origin: T) { | |
/** | |
* A special case of doto, andAlso is useful for | |
* quick logging or output tasks. Similar in use | |
* to doto, but only takes one function. | |
* */ | |
def andAlso(x: T => Unit): T = { x(origin) ; origin } |
OlderNewer