Skip to content

Instantly share code, notes, and snippets.

@zed
zed / ping.py
Created December 12, 2009 19:04
#!/usr/bin/env python
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
// See http://stackoverflow.com/questions/2482933/write-number-n-in-base-m/2483546#2483546
#include <cassert>
#include <cstdlib> // exit
#include <iostream>
#include <string>
#include <vector>
#include <boost/lambda/lambda.hpp> // _1
#include <boost/function.hpp> // function<>
#include <boost/lexical_cast.hpp> // lexical_cast<>
@zed
zed / .gitignore
Created March 28, 2010 20:11
profile performance of countchars() functions
*.py[co]
/cachegrind.out.profilestats
/profilestats.prof
#include <assert.h>
#include <stdio.h>
enum { N = 10 };
static void inc(int* static_out, int* out){
static int static_var = 0;
int var = 0;
++static_var;
++var;
/** see http://stackoverflow.com/questions/2242553/copy-a-linked-list/2242645#2242645 */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> // malloc
typedef struct Node* pNode;
typedef void (*node_visitor_t)(pNode);
struct Node {
int data;
#include <iostream>
#include <iterator>
#include <algorithm>
#include <boost/range.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
namespace llist {
typedef long int ssize_t;
@zed
zed / .gitignore
Created April 2, 2010 10:20
xor string: numpy vs. pyublas vs. fortran vs. C vs. Cython vs. Boost.Python
boost-python/bin/
*.py[co]
*.so
*.o
/xorcy.c
// http://stackoverflow.com/questions/2638781/c-conjunction-of-binds
// $ g++ -Wall -pedantic conjunctions_of_bind.cc -o conjunctions_of_bind
// $ ./conjunctions_of_bind
#include <cstdlib> // atoi
#include <cstring> // strcmp
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/test/minimal.hpp>
@zed
zed / main.c
Created April 18, 2010 19:32
compare relative performance of tolower_ctype, tolower_openbsd, tolower_oraz functions
// compare relative performance of tolower_ctype, tolower_openbsd, tolower_oraz functions
// result: 30.80, 30.51, 38.09
// $ gcc -std=c99 -O3 -g -Wall -pedantic test_tolower.c -o test_tolower;
// $ valgrind --tool=callgrind ./test_tolower 1000000
#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Index: gmpy_mpz.c
===================================================================
--- gmpy_mpz.c (revision 311)
+++ gmpy_mpz.c (working copy)
@@ -400,72 +400,99 @@
return result;
}
+static int gmpy_mpz_bit_set_iterable(PyObject *self, PyObject *other) {
+ long bit_index;