Skip to content

Instantly share code, notes, and snippets.

View ajdavis's full-sized avatar

A. Jesse Jiryu Davis ajdavis

View GitHub Profile
Multi-threaded
1. Record the server selection start time
2. If the topology wire version is invalid, raise an error
3. Find suitable servers by topology type and operation type
4. If there are any suitable servers, choose one at random from those
within the latency window and return it; otherwise, continue to step #5
@scaryghost
scaryghost / dnssd.cpp
Last active February 23, 2020 15:27
How to do a SRV or TXT record lookup in C/C++ on Linux.
/**
* compile: g++ -std=c++0x -o dnssd dnssd.cpp -lresolv
* Your g++ compiler must have lambda support
*
* Code based on examples from:
* http://www.cs.columbia.edu/~zwb/project/dotslash/dots_apache/dnsc.c
* http://people.samba.org/bzr/jerry/slag/unix/query-srv.c
*/
#include <arpa/nameser.h>
#include <functional>
@bergundy
bergundy / stdin_byte_reader.py
Last active December 19, 2015 06:49
An example of how to use coroutines with IOStream.read and timeouts
import sys
import functools
import termios
import socket
from tornado import gen, ioloop, iostream
from datetime import timedelta
class StdinReader(object):
@rantav
rantav / README.md
Created August 23, 2012 06:13
Find slow queries in mongo DB

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

# All of this testing was done on an AWS m1.large with a single Python
# process. I ran the commands multiple times and the numbers below are
# typical of the behavior, though they are the results of two particular
# cases
# Brubeck with Gevent
$ siege -c500 -t10s localhost:6767/brubeck
Lifting the server siege... done.
@mattmccray
mattmccray / backbone_helper.coffee
Created October 14, 2010 08:44
Use Backbone.js classes as native CoffeeScript classes
# Backbone CoffeeScript Helpers by M@ McCray.
# Source: http://gist.github.com/625893
#
# Use Backbone classes as native CoffeeScript classes:
#
# class TaskController extends Events
#
# class TaskView extends View
# tagName: 'li'
# @SRC: '<div class="icon">!</div><div class="name"><%= name %></div>'