Skip to content

Instantly share code, notes, and snippets.

"""Allow IO-synchronous (blocking) code run ``asynchronously'' in the
tornado IO loop. We accomplish this by using threads & a pipe to
notify the event loop when the synchronous call has finished. This
works because threads yield when waiting for IO.
``AsyncThreadPool'' also passes eventlogs around, so that they are
always set in the right thread context."""
from __future__ import absolute_import
from __future__ import with_statement
;; 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))
@mariusae
mariusae / gen.ml
Created September 13, 2010 07:10
python generators in ocaml using delimcc
type ('a, 'b) t = Done | More of 'a * ('b -> ('a, 'b) t)
let gen f =
(*
* Note: the first value to yield gets thrown away as the generator
* has not yet started.
*)
let start _ =
let p = Delimcc.new_prompt () in
Delimcc.push_prompt p begin fun () ->
#!/bin/sh
# $ sshm /fifo/directory host1 host2 host3...
# $ sshm -k /fifo/directory
# $ sshm /fifo/directory -c "ls"
# XXX - extra ssh flags
# set -- $(getopt kc "$@")
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.atomic.AtomicInteger
object Hotpotato {
private val nwaiters = new AtomicInteger(0)
private val executionQueue = new LinkedBlockingQueue[Function0[Unit]]
def serialized(f: => Unit) {
executionQueue offer { () => f }
package com.twitter.test;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Executors;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import com.twitter.finagle.*;
@mariusae
mariusae / git-project.el
Created April 4, 2011 19:08
support for project operations using git
(defvar git-grep-history '())
(defvar git-grep-command "git grep -nH")
(defvar git-tree-command "git rev-parse --show-cdup")
;; from http://www.emacswiki.org/emacs/ElispCookbook
(defun chomp (str)
"Chomp leading and tailing whitespace from STR."
(let ((s (if (symbolp str) (symbol-name str) str)))
(replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" "" s)))
trait LogicLike[A, This[A] <: LogicLike[A, This]] {
def or(t: => This[A]): This[A]
def map[B](f: A => B): This[B]
def flatMap[B](f: A => This[B]): This[B]
def filter(p: A => Boolean): This[A]
def split: Option[(A, This[A])]
def |(t: => This[A]): This[A] = or(t)
def run(n: Int): List[A] =
if (n <= 0) Nil else
#!/bin/sh
exec runscala -dfinagle/finagle-core -dfinagle/finagle-ostrich4 -dfinagle/finagle-http "$0" "$@"
!#
import java.net.InetSocketAddress
import com.twitter.finagle._
import com.twitter.finagle.builder._
import com.twitter.finagle.http._
import com.twitter.finagle.stats.OstrichStatsReceiver
import org.jboss.netty.handler.codec.http._
@mariusae
mariusae / gist:1339915
Created November 4, 2011 17:24
Monitors for Finagle.
diff --git a/finagle/finagle-core/src/main/scala/com/twitter/finagle/builder/ClientBuilder.scala b/finagle/finagle-core/src/main/scala/com/twitter/finagle/builder/ClientBuilder.scala
index 1df9c58..32663db 100644
--- a/finagle/finagle-core/src/main/scala/com/twitter/finagle/builder/ClientBuilder.scala
+++ b/finagle/finagle-core/src/main/scala/com/twitter/finagle/builder/ClientBuilder.scala
@@ -56,7 +56,7 @@ import org.jboss.netty.channel.socket.nio._
import org.jboss.netty.handler.ssl._
import org.jboss.netty.handler.timeout.IdleStateHandler
-import com.twitter.util.{Future, Duration, Throw, Return}
+import com.twitter.util.{Future, Duration, Throw, Return, Monitor, NullMonitor}