Skip to content

Instantly share code, notes, and snippets.

@lhchavez
lhchavez / quimicos-bf.cpp
Last active January 3, 2016 23:29
Solución de `quimicos`, fuerza bruta.
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
// Número de parejas de tubos de vidrio.
int N;
// La cantidad de cada sustancia.
@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

@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
#!/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 \
// 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>
@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"
@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 / adbddb.cpp
Created January 19, 2018 01:30
Android Debug Bridge Debugger
#include <errno.h>
#include <fcntl.h>
#include <linux/usb/ch9.h>
#include <linux/usbdevice_fs.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstdio>
#include <iostream>
@lhchavez
lhchavez / Makefile
Created June 15, 2018 04:22
quark Makefile
golangfiles:=$(shell find src/github.com/omegaup/quark -name '*.go')
assetfiles:=$(shell find src/github.com/omegaup/quark/cmd/omegaup-grader/data/dist)
all: bin/omegaup-grader bin/omegaup-broadcaster bin/omegaup-runner
bin/go-bindata:
go get -u github.com/jteeuwen/go-bindata/...
bin/golint:
go get -u golang.org/x/lint/golint
@lhchavez
lhchavez / process.py
Created August 3, 2018 02:17
Obtener los issues de GitHub
#!/usr/bin/python3
import json
import os
import subprocess
import sys
def download(page):
print(page, file=sys.stderr)
subprocess.check_call([