Skip to content

Instantly share code, notes, and snippets.

kylegibson /
Created Jul 31, 2014
Unicode issue with urllib quote and unquote
from urllib import unquote, quote
a = u'\u2022'
print a
b = a.encode('utf-8')
print b
c = quote(b)
print c
kylegibson / fermat.c
Created Mar 5, 2015
Fermat near miss finder
View fermat.c
Fermat Near-Miss Finder
Written by David X. Cohen
February 3, 1998, 3:24 AM.
This program generated the equation:
3987^12 + 4365^12 = 4472^12
View faked-list-scenarios.txt
## Nested lists using tabs:
1. FOO
2. FOO
[tab]a. FOO
[tab]b. FOO
[tab][tab]i. FOO
[tab][tab]ii. FOO
3. FOO
4. FOO
kylegibson / nginx.conf
Created Oct 26, 2010
nginx WordPress pretty URLs
View nginx.conf
server {
index index.php;
location /blog {
if (!-e $request_filename) {
rewrite ^/blog/(.+)$ /blog/index.php/$1 last;
location ~* \.php(/.*)?$ {
include /etc/nginx/fastcgi_params;
kylegibson /
Created Oct 26, 2010
Single Process CPU Usage
def get_current_cpu(pid):
d = open("/proc/%s/stat" % pid, "r").readline().split()
return int(d[13]), int(d[14])
def get_total_cpu():
d = open("/proc/stat", "r").readline()
return sum(map(int, d.split()[1:]))
kylegibson /
Created Oct 28, 2010
Python Single Connection Echo Server
import socket
import os
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
kylegibson /
Created Oct 28, 2010
Python Generate Email with Attachment
# ./ files.tar.bz2 > email_output
from email.encoders import encode_base64
from email.mime import Base, Multipart
from mimetypes import guess_type
def main(args):
file_path = args[1]
to = args[2]
View linux_kernel_frequency_test.c
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#define USECREQ 250
#define LOOPS 1000
void event_handler (int signum)
kylegibson /
Created Oct 28, 2010
Python Asynchronous Server
from __future__ import with_statement
import sys
import asyncore
import socket
import time
def loop(addrs, klass, args):
servers = []
kylegibson /
Created Feb 8, 2011
A bash script to download the nexus botclient installer
# Latest version is always available at:
# The MIT License
# Copyright (c) 2011 Kyle Gibson
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights