Skip to content

Instantly share code, notes, and snippets.

@guillem
guillem / wikisplit.py
Created May 26, 2019 20:20
Quick and dirty script to split the huge XML file with all the wikipedia pages into individual files. No actual XML parsing is done, it handles the input as a text file and parses it line by line, so it doesn't need much memory to run.
#!/usr/bin/env python3
import os, sys, shutil
infile = sys.argv[1]
outdir = sys.argv[2]
shutil.rmtree(outdir, ignore_errors=True)
os.mkdir(outdir)
@guillem
guillem / guessing_game.go
Created March 6, 2019 16:58
Guessing Game (Rust vs. Go)
package main
import "os"
import "bufio"
import "strconv"
func main() {
f := bufio.NewWriter(os.Stdout)
defer f.Flush()
const MIN = 1
@guillem
guillem / benchmark.c
Created May 30, 2018 15:35
Why Go takes 30 seconds and C just 0.2 ?
#include <stdio.h>
#define MIN 1
#define MAX 1000001
int main (int argc, char **argv) {
for (int secret = MIN; secret <= MAX-1; secret++) {
printf("%d", secret);
int min = MIN;
int max = MAX;
@guillem
guillem / http-stochastic-sleeper.py
Created December 21, 2017 15:12
Simple HTTP server that sleeps and returns random data as requested. Useful to mock other services simulating latency.
#!/usr/bin/env python
# HTTP Stochastic Sleeper
#
# Usage example: run this script with Python and visit the URL
#
# http://127.0.0.1:8080/httpss?sleep=500&size=1000
#
# This will sleep 500 milliseconds and then return 1000 bytes.
@guillem
guillem / cleanOpenWith.sh
Created January 13, 2013 12:37
This single line of shell code (just type it in a Terminal window and press enter) will clean up your "Open With..." menu. It will leave one single entry for each application. It's totally safe, with no side effects.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user