Skip to content

Instantly share code, notes, and snippets.

@fcoury
fcoury / txredns.py
Created July 10, 2011 07:17 — forked from gleicon/txredns.py
Python/Twisted/Redis backed DNS server.
# Python/Twisted/Redis backed DNS server - resolves from NAME to IP addrs
# fallback to google or any other DNS server to resolv domains not present on Redis
# to set a new domain on redis, just issue a SET domain.tld ip_addr
# run with twistd -ny txredns.tac
# gleicon 2011
from twisted.names import dns, server, client, cache
from twisted.application import service, internet
from twisted.internet import defer
from twisted.python import log
@johnboxall
johnboxall / dns.py
Created August 15, 2011 21:57
Twisted DNS server!
# http://notmysock.org/blog/hacks/a-twisted-dns-story.html
# http://blog.inneoin.org/2009/11/i-used-twisted-to-create-dns-server.html
# twistd -y dns.py
import socket
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server
@loonies
loonies / 1_phpunit-api.md
Last active January 19, 2024 07:34
PHPUnit Cheat Sheet

PHPUnit API reference

  • version 3.6

TODO

Check those constraints:

$this->anything()
@cheeming
cheeming / patch-fix-slave-ok-flag2.diff
Created August 5, 2012 11:19
Patch to fix nginx gridfs module to allow connection to secondary/slave mongodb instances. This patch will apply cleanly on revision 76225528b3903fc9eafcb8163c7ebfdf34237e8b for https://github.com/mdirolf/nginx-gridfs.
diff --git a/ngx_http_gridfs_module.c b/ngx_http_gridfs_module.c
index 77ef430..859dff1 100644
--- a/ngx_http_gridfs_module.c
+++ b/ngx_http_gridfs_module.c
@@ -490,7 +490,7 @@ static ngx_int_t ngx_http_mongo_add_connection(ngx_cycle_t* cycle, ngx_http_grid
if ( gridfs_loc_conf->mongods->nelts == 1 ) {
ngx_cpystrn( host, mongods[0].host.data, mongods[0].host.len + 1 );
- status = mongo_connect( &mongo_conn->conn, (const char*)host, mongods[0].port );
+ status = mongo_connect( &mongo_conn->conn, (const char*)host, mongods[0].port, MONGO_SECONDARY_OK );
@cheeming
cheeming / patch-fix-slave-ok-flag.diff
Created August 5, 2012 11:28
Patch to fix mongo c driver to allow connection to secondary/slave mongodb instances. This patch will apply cleanly on revision 13808396bd1b128dfa03ea3ba4d3cdccb9d990c7 for https://github.com/mongodb/mongo-c-driver
diff --git a/src/gridfs.c b/src/gridfs.c
index f51b397..66f8d88 100644
--- a/src/gridfs.c
+++ b/src/gridfs.c
@@ -43,7 +43,7 @@ int gridfs_init( mongo *client, const char *dbname, const char *prefix,
int options;
bson b;
- bson_bool_t success;
+ bson_bool_t success = 1;
@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:

@scragg0x
scragg0x / gist:3894835
Created October 15, 2012 19:47
Unserialize PHP Session in Python
def unserialize_session(val):
if not val:
return
session = {}
groups = re.split("([a-zA-Z0-9_]+)\|", val)
if len(groups) > 2:
groups = groups[1:]
groups = map(None, *([iter(groups)] * 2))
for i in range(len(groups)):
@stuartcarnie
stuartcarnie / clear-apc.php
Last active February 25, 2024 11:07
Self-contained php script to clear shared-memory cache in php5-fpm via command-line. In this instance it is clearing APC, but can be easily changed to clear other shared-memory caches.
#!/usr/bin/env php
<?php
/*
Copyright 2013 Stuart Carnie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
#!/usr/bin/python
# -*- coding: utf-8 -*-
# launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
# launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
from twisted.internet import reactor, stdio, defer
from twisted.internet.protocol import Protocol, Factory
from twisted.protocols.basic import LineReceiver
import time, re, math, json
@alicial
alicial / mock-service-example.js
Last active June 10, 2019 14:26
AngularJS: Setting up a mocked service to use in controller unit tests.
// Mocked Service
angular.module('mock.users', []).
factory('UserService', function($q) {
var userService = {};
userService.get = function() {
return {
id: 8888,
name: "test user"
}