Skip to content

Instantly share code, notes, and snippets.

View ktosiu's full-sized avatar

Marcin Boćkowski ktosiu

View GitHub Profile
@paulsmith
paulsmith / echo.go
Created January 12, 2011 06:09
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
@gleicon
gleicon / gDNS.py
Created July 10, 2011 03:31
gevent/dnslib/redis based DNS server
# dns server using dnslib and gevent
# based on https://bitbucket.org/paulc/dnslib/src/80d85555aae4/src/server/gevent_server.py
# set the key as
# set IP:name ip_addr
# set TXT:name txtfield
# fallback on gevent's dns resolver
# gleicon 2011
import gevent
@ksato9700
ksato9700 / http_client.py
Created December 13, 2011 05:18
pyuv example
import pyuv
def on_close(tcp):
print "closed"
def on_read(tcp, data):
print "read"
if data is None:
tcp.close(on_close)
else:
@sweenzor
sweenzor / logtest.py
Created February 9, 2012 19:59
Writing to syslog with Python's logging library
import logging
import logging.handlers
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = '/dev/log')
formatter = logging.Formatter('%(module)s.%(funcName)s: %(message)s')
@nvie
nvie / workers.py
Created August 28, 2012 21:30
The following sample shows a pool of 5 child processes and submits calculations of the Fibonacci numbers 10..40 (this takes looooong). What you can see is that all work is submitted (as `apply_async` doesn't block), instead of blocking after the fifth.
from multiprocessing import Pool
def fib(n):
if n <= 1:
return n
else:
return fib(n - 1) + fib(n - 2)
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@saghul
saghul / child.py
Created October 4, 2012 06:23
pyuv child process example
#!/usr/bin/env python
import os
import pyuv
import sys
fd = os.getenv('PYUV_CHANNEL_FD')
if fd is None:
print "[Child] No channel fd found"
#!/usr/bin/env python
import dpkt, socket
f = open('t.cap', 'rb')
pcap = dpkt.pcap.Reader(f)
c = 0
ptr_c = 0
log = open('4-seg-ip-dns-filter','w')
#!/usr/bin/env python
from __future__ import unicode_literals
import pymongo
import threading
DB_NAME = 'events'
COLLECTION_NAME = 'events'
class Subscriber(threading.Thread):
@physacco
physacco / test_pcap.c
Created April 9, 2013 08:49
A "hello world" example for libpcap.
#include <stdio.h>
#include <stdlib.h>
#include <pcap/pcap.h>
/* callback function when packet have captured */
static void mycb(u_char *user,
const struct pcap_pkthdr *h, const u_char *packet)
{
static int count = 1;
printf("Packet %d:\n", count);