Skip to content

Instantly share code, notes, and snippets.

@jsoffer
jsoffer / simplereader.c
Created February 28, 2016 12:09
libdwarf example
/*
Copyright (c) 2009, David Anderson; 2016, Jaime Soffer.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
@jsoffer
jsoffer / pkg_graph.py
Created December 5, 2013 18:45
Plots the reverse dependences of a FreeBSD package, cleaned up to remove redundant edges
import subprocess
import networkx as nx
import matplotlib.pyplot as plt
from sys import argv
root = argv[1]
G = nx.DiGraph()
@jsoffer
jsoffer / browser.py
Last active December 26, 2015 13:49
Navegador mínimo en Python y Webkit, toma 2. Incluye tabs. Basado en foobrowser (https://code.google.com/p/foobrowser/)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
minimalistic browser levering off of Python, PyQt and Webkit
Original: https://code.google.com/p/foobrowser/
davydm@gmail.com
+ tabs
@jsoffer
jsoffer / browser.py
Last active December 26, 2015 08:49
Mini-navegador homebrew. Construído porque Opera está funcionando mal (por ejemplo, no guarda el buscador http://localhost:8000, que es un servicio interno, por default). Webkit. Mucha flexibilidad, pocas funciones.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A minimal web browser.
Original: http://ralsina.me/weblog/posts/BB948.html
Features:
+++ verificar no tráfico no solicitado (startup, al menos)
@jsoffer
jsoffer / freebsd_ports.py
Created October 16, 2013 16:10
Crea de manera ingenua una gráfica .dot que contiene las dependencias de los ports instalados en un sistema FreeBSD (9.1, requiere 'pkg' estilo pkgng)
from subprocess import check_output
data = check_output(["pkg", "info", "-a", "-d"])
fuente = ''
print "digraph Dependencias {"
for linea in data.split('\n'):
if linea:
@jsoffer
jsoffer / gsearch.js
Last active December 25, 2015 11:38
Filtro para resultados de Google Search (que no use reescritura del url, etc)
/* Uso: 'node gsearch.js'; en el navegador, 'http://localhost:8000/?q=la búsqueda' */
var http = require('http')
, url = require('url')
, google = require('google-tools')
, mu = require('mu2');
mu.root = __dirname + '/templates';
http.createServer(function (req, web_out) {
@jsoffer
jsoffer / mixmusic.sh
Last active December 24, 2015 10:49
Mezcla una canción consigo misma
# lame --decode song.mp3 song.wav
WAV=$1
OFFSET=$2
# podría integrar los cambios en un solo comando,
# sin usar archivos intermedios, con 'delay'
# 'remix' hace el equivalente de 'pan', el canal
# derecho aparece antes al hacer offset
@jsoffer
jsoffer / gist:2283881
Created April 2, 2012 14:34
'top' output
last pid: 1681; load averages: 0.02, 0.03, 0.00 up 0+01:53:18 09:35:32
25 processes: 2 running, 22 sleeping, 1 waiting
CPU: 2.3% user, 0.0% nice, 1.5% system, 0.0% interrupt, 96.2% idle
Mem: 84M Active, 50M Inact, 32M Wired, 4K Cache, 34M Buf, 77M Free
Swap: 512M Total, 2668K Used, 509M Free
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
1102 jaime 6 20 0 134M 98792K uwait 3:20 0.00% /home/jaime/OperaDownloads/opera-dir/lib/opera/opera -pd /hom
820 jaime 1 20 0 69752K 58080K select 0:45 0.10% X -nolisten tcp (Xorg)
808 jaime 1 20 0 16376K 7732K select 0:02 0.00% urxvtd -q
@jsoffer
jsoffer / gist:1993795
Created March 7, 2012 15:27
Distinguiendo memoria virtual reservada de memoria actualmente usada
/* reservando memoria, sin usarla */
#include <unistd.h>
#include <stdlib.h>
#define PAGESIZE 4096
#define SIZE 1212 * PAGESIZE
int main() {
int i;
@jsoffer
jsoffer / gist:1672258
Created January 24, 2012 20:07
paradoja del cumpleaños, para 3 personas
import Math.Combinat.Numbers
import Data.Ratio
-- OEIS A141765: el número de cadenas de longitud n en un alfabeto de
-- longitud r que no repiten más de dos veces el mismo símbolo
t :: Integer -> Integer -> Integer
t r n = sum $ map g [a..r] where
a = quot (n+1) 2
g k = if n < k then 0 else