Skip to content

Instantly share code, notes, and snippets.

@afeinberg
afeinberg / SConstruct
Created December 9, 2011 07:51
Quick and dirty transliteration of the libevent2 book async DNS example to C++ -- based on http://www.wangafu.net/~nickm/libevent-book/Ref9_dns.html
# -*- python -*-
env = Environment()
env.Append(CPPFLAGS='-g -Wall -Wextra')
env.Program(target='resolver',
source=['resolver.cc'],
LIBS=['event'])
#include <stdio.h>
int main(void)
{
int i, j, l[4]= {0x48617070, 0x79204269, 0x72746864, 0x61792021};
for (i=0; i<4; i++)
for (j=3; j>=0; j--)
void x() {
SomeClass blah;
asyncthread(y(blah));
}
// Note if you pass shit by reference, it should be a const reference. Otherwise just use a pointer
void y(const SomeClass &blah) {
Blah blah_copy(blah); // <-- assuming the constructor does not do a shallow copy
}
finally {
if(source != null) {
try {
source.close();
} finally {
if(dest != null) {
dest.close();
}
}
}
import Control.Monad
import System.IO
import Data.List
import qualified Data.Map as Map
countWords :: [String] -> Map.Map String Integer
countWords = foldl updateMap Map.empty
where
updateMap m word =
Map.insert word (1 + (Map.findWithDefault 0 word m)) m
// -*-c++-*-
#ifndef AF_ALLOC_ALLOC_H_
#define AF_ALLOC_ALLOC_H_
#include <cstdlib>
#include <memory>
namespace af {
#include <cstdlib>
#include <cstring>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <iostream>
#include <string>
/*
* tlook.c - [email protected] based on mlook.c
* threaded mass resolver
*
* ./tlook <file> Accepts stdin if no arguments are given resolves both hostname
* and IPs
*
* grep new.cgi access.log | awk '{print $1}' | sort |uniq |tlook > resolved
*
*/
(defvar *default-font-size* 13)
(defvar *default-font-name* "Menlo")
(defun increase-default-font-size ()
"Increase font size"
(interactive)
(incf *default-font-size*))
(defun decrease-default-font-size ()
"Decrease default font size"
#include <stdio.h>
#include <sys/mman.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
static volatile int done = 0;