Skip to content

Instantly share code, notes, and snippets.

func combinations(n, m int, f func([]int)) {
// For each combination of m elements out of n
// call the function f passing a list of m integers in 0-n
// without repetitions
// TODO: switch to iterative algo
s := make([]int, m)
last := m - 1
var rc func(int, int)
rc = func(i, next int) {
@FiloSottile
FiloSottile / browser_request
Created December 12, 2013 23:20
Analysis of the new GMail image proxy
{
"accept-language": "en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4",
"accept-encoding": "gzip,deflate,sdch",
"cache-control": "max-age=0",
"connection": "keep-alive",
"accept": "image/webp,*/*;q=0.8",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36",
"host": "filosottile.info",
"if-modified-since": "Wed, 31 Oct 2012 23:52:07 GMT"
}
import urllib2
import re
import sys
from collections import defaultdict
from random import random
"""
PLEASE DO NOT RUN THIS QUOTED CODE FOR THE SAKE OF daemonology's SERVER, IT IS
NOT MY SERVER AND I FEEL BAD FOR ABUSING IT. JUST GET THE RESULTS OF THE
CRAWL HERE: http://pastebin.com/raw.php?i=nqpsnTtW AND SAVE THEM TO "archive.txt"

Basketball Game

A group of N high school students wants to play a basketball game. To divide themselves into two teams they first rank all the players in the following way:

  • Players with a higher shot percentage are rated higher than players with a lower shot percentage.
  • If two players have the same shot percentage, the taller player is rated higher.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import BaseHTTPServer
import sys
import time
import urlparse
import json
@FiloSottile
FiloSottile / 0xBCF05F6B.gpg
Created November 23, 2013 20:50
PGP key 0xBCF05F6B
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.15 (Darwin)
mQINBFA/TqwBEACugv9eTIochvPlZAvL1D8qtVMgUodkZ9AfkYFHcFlRFktYHu+z
XQ8UDjGTpUcWix627ZzlxbYIowsUiGz0JE2E15KXpwyK/xLJstGLpnhXB2Wr9oUY
FEP0qUDDUDK9NBdsHvH1J6SvUCDFPloRZQih3En8b7WeafxFDp6lxDcWNRgOko3J
qDrwdvkNSjlXg9banE0bryWogCZuoqsGwkOWjXRccLM0e1yGHWvPRESd5pkK5F7t
eGdKxJGRsd4IFXkfCk4/h01XWLFUHpT3iWm8CS3hu5Rf6Fk/L4F1RUJSKHaH4G1Y
hvSw5UHJBuvHHHP76X+oPsUOpA+HzONhFf/hehqS859ocSwmuLWhUaIObN/liC+7
+LegRZLTSeDTYruq3CzI8Q2syN7gCjtpkqf3Xqg3WzFf+iJIgGR4u8sXLNmA2mi9
>>> def F(n):
... x = 1
... while True:
... if n == 1: return x
... elif n % 2 == 0: n /= 2
... else: n = n * 3 + 1
... x += 1
>>> input = 1429
>>> max(range(1, input+1), key=F)
1161
@FiloSottile
FiloSottile / 32.asm
Last active March 23, 2024 12:28
NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated nasm with brew)
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
@FiloSottile
FiloSottile / crontab
Last active December 26, 2015 01:59
Shell script to run @Neal's savethemblobs in a cronjob https://github.com/Neal/savethemblobs
0 5 * * 1 bash -c "cd ~/shsh-blobs/; ./savethem.sh"
@FiloSottile
FiloSottile / unchroot.c
Last active January 18, 2023 08:54
Code for my article about chroot jail escaping
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int dir_fd, x;
setuid(0);
mkdir(".42", 0755);
dir_fd = open(".", O_RDONLY);
chroot(".42");