Skip to content

Instantly share code, notes, and snippets.

@lhchavez
lhchavez / mkns.cpp
Created October 22, 2017 02:14
Create namespaces and bind their nsfs FDs
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
@lhchavez
lhchavez / ClangIwyu.cpp
Created January 3, 2017 14:52
WIP of an IWYU ClangTool
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Path.h"
// Benchmark Time CPU Iterations
// -----------------------------------------------------
// BM_DynamicCast 1073 ns 1074 ns 630631
// BM_StaticCast 452 ns 452 ns 1552106
// BM_TaggedCast 59 ns 59 ns 11111111
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <benchmark/benchmark.h>
#!/usr/bin/python3
from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA
import argparse
import socket
import struct
import sys
ADB_AUTH_TOKEN = 1
#!/bin/bash
set +x
sudo apt-get install -y autoconf automake binutils-dev build-essential cmake g++-4.9 gawk git \
libbz2-dev libc-client-dev libldap2-dev \
libc-client2007e-dev libcap-dev libcurl4-openssl-dev libdwarf-dev libelf-dev \
libexpat-dev libgd2-xpm-dev libgoogle-perftools-dev libicu-dev \
libjemalloc-dev libmcrypt-dev libmemcached-dev libmysqlclient-dev libncurses-dev \
libonig-dev libpcre3-dev libreadline-dev libtbb-dev libtool libxml2-dev zlib1g-dev \
@lhchavez
lhchavez / strace.py
Created February 11, 2016 06:13
strace wrapper to display the read/written files of a process tree
#!/usr/bin/python
import argparse
import collections
import os
import os.path
import re
import subprocess
import sys
import threading
#!/usr/bin/python
import argparse
import random
import subprocess
import sys
import time
PREFIX = '/sbin/ip netns exec'
#!/usr/bin/python
# vim: set expandtab:ts=2:sw=2
import argparse
import bluetooth
import struct
import sys
def checksum(msg):
checksum = 0
#!/usr/bin/python
# Invoke n instances of sudo in parallel. This works fine in all machines I've
# tried this on, except Windows Azure VMs, where occasionally invocations to
# sudo take ~5s to complete when n > 1.
# Tested on a Standard_A1 instance w/Ubuntu Utopic, kernel 3.16.0-34-generic.
import subprocess
import sys
import time
@lhchavez
lhchavez / quimicos-solucion.md
Last active January 4, 2016 03:29
quimicos explicacion

Este es un problema que tiene una solución elegante y determinística pero requiere algoritmos avanzados bastante complicados. Lo bueno es que es posible aproximar a la solución utilizando fuerza bruta mediante backtracking.

El problema nos pide encontrar una manera de asignar sustancias a los tubos y después mezclarlas con las dos operaciones disponibles (suma y diferencia absoluta) para terminar con un acomodo homogéneo de sustancias: la diferencia entre el tubo con más cantidad y con menos cantidad de sustancia debe ser lo más pequeña posible. Una manera de hacerlo es proponer un intervalo $[a,b]$ y ver si es posible asignar sustancias y aparear los tubos de manera que la