Skip to content

Instantly share code, notes, and snippets.

class Foo.<T> {
static function callIt(f : () -> T) : void {
f();
}
}
class _Main {
static function main(args : string[]) : void {
Foo.<void>.callIt(function () {});
}
$ git status
# On branch master
nothing to commit, working directory clean
$ DYLD_INSERT_LIBRARIES=../../unco.dylib DYLD_FORCE_FLAT_NAMESPACE=YES git checkout HEAD^
Note: checking out 'HEAD^'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
@kazuho
kazuho / gist:9800525
Created March 27, 2014 04:53
switch from master to wip, then undo the switch
$ git status
# On branch master
nothing to commit, working directory clean
$ unco record --log=/tmp/unco.log git checkout wip
Switched to branch 'wip'
$ git status
# On branch wip
nothing to commit, working directory clean
static int _log_exists(const char *dir, long long log_index, int *exists)
{
struct stat st;
char fnbuf[PATH_MAX];
snprintf(fnbuf, sizeof(fnbuf), "%s/%lld", dir, log_index);
if (fstat(path, &st) == 0) {
*exists = 1;
} else if (errno == ENOENT) {
@kazuho
kazuho / gist:9803136
Created March 27, 2014 08:45
elias-search.c
#include <stdio.h>
static int N;
static int findN(void)
{
int min, max, mid;
// index starts from 1; search using Elias encoding (i.e. search at 1,2,4,8,16,... and then perform binary search)
for (max = 1; ; max *= 2) {
$ alias git='unco record -- git' <-- set alias
$ git status <-- now on 'master'
# On branch master
nothing to commit, working directory clean
$ git checkout wip <-- switch to 'wip'
Switched to branch 'wip'
$ git status <-- now on 'wip'
# On branch wip
nothing to commit, working directory clean
$ unco history <-- print history
@kazuho
kazuho / gist:11168660
Created April 22, 2014 07:32
tempfile, UNLINK, and flock
my $fn = do {
# some BSD variants (notably OS X) flocks the file handle when calling tempfile()
my ($fh, $fn) = tempfile(UNLINK => 1);
$fn
# setting UNLINK => 1 keeps a hidden reference to the file handle, and thus the file
# is not automatically closed when exitting this block
};
open my $fh, "<", $fn
or die $!;
$ git clone git@github.com:miyagawa/cpanminus.git
Cloning into 'cpanminus'...
remote: Reusing existing pack: 8570, done.
remote: Total 8570 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (8570/8570), 3.70 MiB | 96.00 KiB/s, done.
Resolving deltas: 100% (3504/3504), done.
Checking connectivity... done.
$ cd cpanminus/
$ git branch
* devel
use strict;
use warnings;
use Data::Dump qw(dump);
sub parse {
my $k = shift;
my @keys;
while (1) {
@kazuho
kazuho / gist:be297f2735d836b3cd4f
Created June 30, 2014 03:00
#libuv - only one of the callbacks is called when a socket which is at the same time reading / writing gets closed by peer
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <uv.h>
static uv_tcp_t sconn, cconn;
static uv_connect_t cconn_ctx;
static uv_write_t wreq;
static uv_buf_t on_alloc(uv_handle_t *handle, size_t suggested_size)