This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Demonstrates how to construct and send raw Ethernet packets on the | |
network. | |
You probably need root privs to be able to bind to the network interface, | |
e.g.: | |
$ sudo python sendeth.py | |
""" | |
from socket import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To compile objective-c on the command line: | |
* | |
* gcc -framework Foundation objc-gcc.m | |
* | |
* You may have to link with -lobjc or other libs, | |
* as required. | |
*/ | |
#import <Foundation/Foundation.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% MetaPost free body diagram with frictional forces | |
% | |
% Placed in the public domain by the author; Christian Stigen Larsen | |
% 2011-10-07 | |
% | |
% To render: | |
% $ mptopdf free-body.mp | |
% | |
beginfig(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: iso-8859-1 -*- | |
""" | |
Written by Christian Stigen Larsen, http://csl.sublevel3.org | |
Placed in the public domain by the author | |
This is a version of the classic game of guessing which animal you | |
are thinking about. It uses a binary tree to guess. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example of heterogeneous arrayo in golang. | |
* | |
* The trick is simply to create an array that accepts elements that conform | |
* to the naked interface (an interface with no requirements). | |
* | |
* Expected output: | |
* | |
* $ go run array.go | |
* [1 2 3.14 hey {10 20}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A simple way to format numbers as human readable strings. | |
* E.g., 123456789 ==> 123 million | |
* | |
* Written by Christian Stigen Larsen | |
* http://csl.sublevel3.org | |
* | |
* Placed in the public domain by the author, 2012 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Functions to convert IPv4 address to integer and vice-versa. | |
Written by Christian Stigen Larsen, http://csl.sublevel3.org | |
Placed in the public domain by the author, 2012-01-11 | |
Example usage: | |
$ ./ipv4 192.168.0.1 3232235521 | |
192.168.0.1 ==> 3232235521 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Euler's totient function phi(n). | |
* http://en.wikipedia.org/wiki/Euler%27s_totient_function | |
* | |
* This is an *EXTREMELY* fast function and uses | |
* several tricks to recurse. | |
* | |
* It assumes you have a list of primes and a fast | |
* isprime() function. Typically, you use a bitset | |
* to implement the sieve of Eratosthenes and use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The binary gcd algorithm using iteration. | |
* Should be fairly fast. | |
* | |
* Put in the public domain by the author: | |
* | |
* Christian Stigen Larsen | |
* http://csl.sublevel3.org | |
*/ | |
int binary_gcd(int u, int v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Find the longest palindrome in the text. | |
* | |
* This is Greplin's first challenge, and I originally solved it in Python. | |
* | |
* This algorithm is linear on the average input, but has a quadratic | |
* worst case running time. There exists an even better algorithm, but | |
* this should do. | |
* | |
* There might also be a small error below, but you get the general idea. |
NewerOlder