Skip to content

Instantly share code, notes, and snippets.

View rbonvall's full-sized avatar

Roberto Bonvallet rbonvall

View GitHub Profile
@rbonvall
rbonvall / compare.py
Last active December 25, 2015 00:19
Helper functions for debugging deeply nested data structures on the console.
def dictcompare(da, db):
ka = set(da.keys())
kb = set(db.keys())
if ka & kb:
if ka - kb:
print 'Keys only in A:', ka - kb
if kb - ka:
print 'Keys only in B:', kb - ka
else:
(function () {
var width = 500, height = 200, padding = 40;
var max = 10;
var dataset = d3.range(10)
.map(function () { return 1 + Math.random() * (max - 1); });
// Coordinate scaling functions
var x = d3.scale.linear()
.domain([0, dataset.length])
.range([padding, width - padding]);
@rbonvall
rbonvall / comparito.py
Last active August 29, 2015 13:57
Compare two JSONable Python data structures and enumerate their differences
#!/usr/bin/env python
def add_to_path(path, item):
return '{}[{}]'.format(path, repr(item))
def dictcompare(old, new, path, differences):
old_keys = set(old.keys())
new_keys = set(new.keys())
@rbonvall
rbonvall / redirect.py
Created April 4, 2014 20:36
Redirect both stdin and stdout of a process to a PyQt text edit.
from PyQt4 import QtGui, QtCore, uic
def p(x):
print x
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QWidget.__init__(self)
uic.loadUi('redirect.ui', self)
@rbonvall
rbonvall / gist:924e7c0727a0c6055dc8
Created May 1, 2014 02:38
Error compiling kakoune
~/codigo/kakoune/src (master)$ git log -1 --oneline
67559da file.cc: try more portable use of struct stat::st_mtime
~/codigo/kakoune/src (master)$ LANG=C make
g++ -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -pedantic -DKAK_DEBUG -MMD -MP -MF .event_manager.d -c -o .event_manager.o event_manager.cc
g++ -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -pedantic -DKAK_DEBUG -MMD -MP -MF .buffer_manager.d -c -o .buffer_manager.o buffer_manager.cc
g++ -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -pedantic -DKAK_DEBUG -MMD -MP -MF .exception.d -c -o .exception.o exception.cc
g++ -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -pedantic -DKAK_DEBUG -MMD -MP -MF .selectors.d -c -o .selectors.o selectors.cc
In file included from buffer.hh:6:0,
from selection.hh:4,
from selectors.hh:4,
def variable_dict(module):
v = vars(module)
return {x:v[x] for x in v if not x.startswith('__')}
import a
import b
A = variable_dict(a)
B = variable_dict(b)
A.update(B)
@rbonvall
rbonvall / gist:1fe47b09791114160dc6
Created December 30, 2014 18:08
Unicode characters in Java identifiers
public class App {
static String x8mil200µm; // micro symbol
static String x7mil175μm; // mu letter
static int aβc = 10;
static final double π = 3.14159265359;
public static void main(String[] args) {
x8mil200µm = "Y";
x7mil175μm = "N";
@rbonvall
rbonvall / gist:b5f99b407af7a2709626
Created May 8, 2015 21:46
Extractors for numbers in strings
object f {
val floatingPointNumberPattern = """(\d+(?:[.]\d*))""".r
def unapply(s: String): Option[Double] = s match {
case floatingPointNumberPattern(x) ⇒ Some(x.toDouble)
case _ ⇒ None
}
}
object i {
val nonNegativeIntegerPattern = """(\d+)""".r
#!/usr/bin/env python
from numpy import *
#r = raw_input()
r = 'Programming Puzzles & Code Golf'
s = sign(diff(map(ord, r[0] + r)))
c = cumsum(s)
p = 2 * (max(c) - c) + 1
w = max(p) + 1
@rbonvall
rbonvall / 01-unos-tipos-con-opciones.scala
Last active April 5, 2016 13:03
Charla «Unos tipos con opciones».
// Unos tipos con opciones //
// //
// Roberto Bonvallet //
// @rbonvall //
// //
// Viernes 1 de abril de 2016 //
// Santiago Scala Meetup //