Skip to content

Instantly share code, notes, and snippets.

@bmatheny
bmatheny / gist:983162
Created May 20, 2011 15:29
hiredis weirdness
static void
redis_connect_cb(const struct redisAsyncContext *c) {
struct node *n = c->data;
if ( !n || c->err ) {
ERROR_OUT("Node is null or error is %s\n", c->errstr);
return;
} else if ( !(c->c.flags & REDIS_CONNECTED) ) {
DEBUG_OUT("Not connected\n");
return;
} else {
@bmatheny
bmatheny / gist:988962
Created May 24, 2011 15:50
hiredis assertion fails with no callbacks
int main (int argc, char **argv) {
int i = 0;
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
redisAsyncContext *c2 = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
@bmatheny
bmatheny / gist:991247
Created May 25, 2011 16:02
curl_multi speed for PHP
<?php
class CurlMulti
{
// Code from http://www.somacon.com/p537.php
public static function getMulti(array $urls)
{
// Create get requests for each URL
$mh = curl_multi_init();
foreach($urls as $i => $url)
@bmatheny
bmatheny / gist:1069547
Created July 7, 2011 13:49
Why I left Indy (but still think it's great)

Miles recently wrote a post on the Indy Hackers Blog appropriately titled, Why Indy? In the post (http://blog.indyhackers.org/post/7262445527/why-indy) Miles (along with several other hoosiers) enumerates the various great things about why a developer/business might want to live in/stay in/come to Indiana. Having spent 10 of my 31 years in Indiana (4 in West Lafayette, 6 in Indianapolis) I definitely think of myself as a hoosier but despite that I moved to NYC in May. I am in the defector group, but maybe not in the dissenter group.

While I was in Indianapolis I held leadership roles at 3 different startups including ChaCha and Compendium, witnessed a very successful exit at one of my startups (3GUpload.com in 2004), and consulted for a half-dozen other various companies. That is to say, I think I have a pretty good feeling for what Indy has to offer in terms of work. Additionally, I participated in a variety of volunteer organizations (Big Brothers Big Sisters, Leukemia/Lymphoma society, ADA, etc) as well a

@bmatheny
bmatheny / gist:1186011
Created September 1, 2011 11:43
Memcache Codec with Quit Support
import com.twitter.finagle.{Codec, Service}
import com.twitter.finagle.memcached.protocol.{Command, Response, Quit => MemcacheQuit, NoOp}
import com.twitter.finagle.memcached.protocol.text.{Encoder, Memcached, ResponseToEncoding}
import com.twitter.finagle.memcached.protocol.text.server.{Decoder => ServerDecoder, DecodingToCommand}
import com.twitter.logging.Logger
import com.twitter.util.Future
import org.jboss.netty.buffer.{ChannelBuffer, ChannelBuffers}
import org.jboss.netty.channel._
import org.jboss.netty.util.CharsetUtil
@bmatheny
bmatheny / gist:1562136
Created January 4, 2012 21:05
.ssh/config for multiplexed connections
Host *
ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r
@bmatheny
bmatheny / mysqlpool.scala
Created March 30, 2012 02:07 — forked from tsuna/mysqlpool.scala
MySQL JDBC connection pool for Scala + Finagle
// Copyright (C) 2012 Benoit Sigoure
// Copyright (C) 2012 StumbleUpon, Inc.
// This library is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
@bmatheny
bmatheny / gist:2785402
Created May 25, 2012 02:18
Sample Heapster Config
#!/bin/sh
#
# foo init.d script.
#
# All java services require the same directory structure:
# /usr/local/$APP_NAME
# /var/log/$APP_NAME
# /var/run/$APP_NAME
APP_NAME="foo"
@bmatheny
bmatheny / gist:3722111
Created September 14, 2012 14:10
Cheatsheet

zsh

  • !$ - Last argument of previous command

iterm2

  • CMD-shift-H - Paste history
  • CMD-; - Start typing word, will use history and show top 20 choices

Vim

@bmatheny
bmatheny / vim.rb
Created September 23, 2012 16:10 — forked from vesln/vim.rb
Vim Formula with Ruby & Python support for OS X
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
version '7.3.666'
url 'https://vim.googlecode.com/hg/', :revision => '1e22adc6176e'
head 'https://vim.googlecode.com/hg/'
def ruby_bin