Skip to content

Instantly share code, notes, and snippets.

@walac
walac / avg_filesize.py
Created August 20, 2015 13:26
Utility to calculate the average cached symbol file size from logs for snappy
#!/usr/bin/env python
# Run: grep 'Parsing SYM file' *.log | awk '{print $9}' | xargs ./avg_filesize.py
import sys
import os
import tempfile
import urllib2
import cPickle as pickle
import contextlib
from bisect import bisect
import gzip
from __future__ import print_function
import time
import threading
import multiprocessing
N = 100000000
def count(n):
while n:
n -= 1
#!/bin/bash -vex
drv_path=/lib/modules/$(uname -r)/misc
drv_list=$(lsmod | grep vbox | awk '{print $1}' | xargs echo -n)
if test "$drv_list"; then
modprobe -r $drv_list
fi
for d in $drv_path/*vbox*.ko; do
insmod $d
done
@walac
walac / heap.py
Created December 29, 2014 19:18
A simple heap class for dijkstra's algorithm
#!/usr/bin/python
import operator
def parent(i):
return i/2
def left(i):
return i*2 + 1
@walac
walac / check_ids.awk
Last active August 29, 2015 14:05
Dump the breakpad symbols for fxos phones shared objects under /system/lib and check if they match to the generated by the buildsymbols command
BEGIN {
CRASHSYMBOLS = "~/work/B2G/objdir-debug/dist/crashreporter-symbols/"
}
{
if (system("test -d "CRASHSYMBOLS $2) == 0) {
if (system("test -d "CRASHSYMBOLS $2"/"$1) == 0) {
print $2" ok"
} else {
"ls " CRASHSYMBOLS $2"/" | getline id
print "The ids for "$2" don't match: "$1 " "id
@walac
walac / clear-halt-test.c
Created May 22, 2014 19:56
USB endpoint stall test for libusb-win32
#include <usb.h>
#include <stdio.h>
int main(int argc, char **argv)
{
struct usb_bus *bus;
struct usb_device *dev = NULL;
usb_dev_handle *handle;
char dummy_data[5];
int ret;
@walac
walac / test-openusb.py
Last active January 4, 2016 22:09
Test of the openusb backend for PyUSB
from usb.core import find
from usb.backend import openusb
import sys
if len(sys.argv) < 2:
print ('Usage: python test-openusb.py idvendor:idproduct (in hex)')
exit(1)
vendor, product = list(map(lambda x: int(x, 16), sys.argv[1].split(':')))
@walac
walac / problem.cc
Last active December 28, 2015 05:29
Some random stuff.
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <unordered_map>
using namespace std;
namespace {
@walac
walac / msubstr.c
Last active December 26, 2015 17:09
MSUBSTR spoj problem
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LEN 3000
#define AUX_LEN (MAX_LEN * 2 + 1)
int fn[AUX_LEN];
char aux[AUX_LEN+1];
int p[AUX_LEN];
@walac
walac / test-ffi.cc
Last active December 20, 2015 05:59
A crazy libffi test.
#include <ffi.h>
#include <iostream>
using namespace std;
class IInterface {
public:
virtual void fn1(int a, int b) = 0;
virtual void fn2(int a, int b) = 0;
~IInterface() {}