Skip to content

Instantly share code, notes, and snippets.

View danluu's full-sized avatar

Dan Luu danluu

  • https://danluu.com
  • Vancouver, BC
View GitHub Profile
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
@benjchristensen
benjchristensen / index.html
Created May 2, 2012 19:34
Simple Line Graph using SVG and d3.js
<html>
<head>
<title>Simple Line Graph using SVG and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
@bradfitz
bradfitz / diskchecker.pl
Created July 24, 2012 21:05
diskchecker.pl
#!/usr/bin/perl
#
# Brad's el-ghetto do-our-storage-stacks-lie?-script
#
sub usage {
die <<'END';
Usage: diskchecker.pl -s <server[:port]> verify <file>
diskchecker.pl -s <server[:port]> create <file> <size_in_MB>
diskchecker.pl -l [port]
# using VirtualBox version $VBOX_VERSION
FROM boot2docker/boot2docker
RUN apt-get install p7zip-full
RUN mkdir -p /vboxguest && \
cd /vboxguest && \
curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso && \
7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \
sh VBoxLinuxAdditions.run --noexec --target . && \
@zmagg
zmagg / ahi.md
Last active November 16, 2019 08:24
adaptive hash index in mysql

omg julia,

Today I learned something about the buffer pool in MySQL that made it seem less like performance black magic! So, before today I knew that the buffer pool was an in-memory cache for MySQL that let you do super fast lookups (especially PK lookups, but maybe only PK lookups (? uncertain on that one)), like, our PK lookups with the BP turned on take microseconds, and they did so even before we moved to SSDs for all our databases [1]. I didn't know ANYTHING about how the buffer pool worked though, other than like, "caching: it makes things faster".

So, today we were doing a routine schema change truncating some old tables. We did a TRUNCATE operations live with all the databases still in configuration serving live traffic [2], because a TRUNCATE essentially does a DROP/CREATE at the table level, instead of row by row (since MySQL 5.1, we're on 5.5), so it's usually reasonably high performance. TURNS OUT, it also does some really not-so-performant cache invalidation on the buffer pool! This

@drio
drio / tmux libevent
Created August 18, 2010 22:03
How to compile tmux
NOTE: I am using bash for this.
NOTE2: Another approach for getting tmux would be to use gentoo-prefix or netbsd's pkgsrc. I
didn't have too much luck with gentoo-prefix. NetBSD was pretty straight forward but it had
an old version of tmux (1.1).
Here is how to get tmux compiled if you can get your systadmins to installed it ... or
any other weird reason. I assume you have some basic libraries and headers installed (like
ncurses, etc...). If not, you'll have to compile those ones too.
@staticfloat
staticfloat / debugging.md
Last active February 24, 2017 03:11
Julia Debugging Procedures

Julia Debugging Procedures

So you managed to break Julia. Congratulations! Collected here are some general procedures you can undergo for common symptoms encountered when something goes awry. Including the information from these debugging steps can greatly help the maintainers when tracking down a segfault or trying to figure out why your script is running slower than expected.

If you've been directed to this page, find the symptom that best matches what you're experiencing and follow the instructions to generate the debugging information requested. Table of symptoms:

@assp1r1n3
assp1r1n3 / bench.c
Last active May 5, 2016 02:06
Hand assembly vs. Intrinsics
#include <stdint.h>
#include <stddef.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
uint64_t builtin_popcnt(const uint64_t* buf, size_t len){
uint64_t cnt = 0;
for(size_t i = 0; i < len; ++i){
cnt += __builtin_popcountll(buf[i]);
}

Some coding exercises, working up to matching regular expressions with Thompson's algorithm.

I'm assuming you know what a regular expression is and you're a fairly experienced programmer. I don't know if these exercises are either fun or effective -- please comment or fork here or email withal@gmail.com to help me improve them.

The problems

// On my system:
// virtual call time: 4.340
// non-virtual call time: 3.970
// virtual call overhead 9.32%
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define NOINLINE __attribute__ ((noinline))