Skip to content

Instantly share code, notes, and snippets.

static struct addrinfo tcp_hints = {
.ai_flags = AI_NUMERICSERV,
.ai_socktype = SOCK_STREAM,
.ai_family = AF_INET,
};
static struct addrinfo https_ai;
static struct addrinfo
make_https_addrinfo (void) {
int r = 0;
crawler/crawler
*.o
*.pyc
*.pyo
@temoto
temoto / a better programming language builtin types.rst
Created September 2, 2009 14:35
a better programming language features

Types

  • Atoms (Erlang, Ruby)

>>> ok

>>> :ok

  • Infinite size integers
def connect(addr, family=socket.AF_INET, bind=None):
"""Convenience function for opening client sockets.
:param addr: Address of the server to connect to. For TCP sockets,
this is a (host, port) tuple.
:param family: Socket family, optional. See :mod:`socket`
documentation for available families.
:param bind: Local address to bind to, optional.
"""
sock = green_socket.socket(family)
# chunkify_list( list(xrange(1, 11), 2 ) -> ([1,2], [3,4], [5,6], [7,8], [9,10])
def chunkify_list(L, size):
while L:
chunk, L = L[:size], L[size:]
yield chunk
; Copied from http://newos.org/txt/context_switch.txt
BITS 32
global HalSwitchContext
section .text
; void i386_context_switch(void **from_esp, void *esp)
HalSwitchContext:
pusha ; save all 8 general purpose regs on the stack
# Muhs3 in Go.
include $(GOROOT)/src/Make.inc
TARG := muhs3
GOFMT := gofmt -spaces=true -tabindent=false -tabwidth=4
GOFILES := \
main.go \
muh.go \
@temoto
temoto / datetime.py
Created March 9, 2011 13:15
Python datetime timezone utils.
# coding: utf-8
from __future__ import absolute_import
"""Datetime utils.
To store time use `naive_to_utc(dt, tz_name)`.
To display time use `utc_to_local(dt, tz_name)`.
"""
import datetime as stdlib_datetime
import pytz
@temoto
temoto / gist:1330373
Created November 1, 2011 11:46
Python time machine contextmanager for tests
# Except it would not work, because TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
@contextmanager
def time_machine(now=None, utcnow=None, today=None):
if now is None and utcnow is None and today is None:
raise ValueError(u"At least one of `now`, `utcnow` or `today` must be specified.")
real_now = datetime.now()
real_utcnow = datetime.utcnow()
tz_delta = real_now - real_utcnow
#include <pcrecpp.h>
#include <iostream>
int main(int argc, char *argv[]) {
// Don't sync C++ and C I/O
std::ios_base::sync_with_stdio(false);
if (argc < 2) {
std::cerr << "Usage: re_remove REGEX <input" << std::endl;