Skip to content

Instantly share code, notes, and snippets.

@aktau
aktau / strcjoinv.c
Created August 31, 2014 21:11
neovim: path building API tryouts
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#define MAXPATHL 128
/// like `strcat`, but returns a pointer to the '\0' terminator of rht
/// resulting string.
@aktau
aktau / 32.asm
Created August 31, 2014 09:01 — forked from desertmonad/32.asm
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The .data section is for storing and naming constants.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
section .data
msg: db "Hello world!", 10
.len: equ $ - msg
@aktau
aktau / palignr.c
Created August 28, 2014 15:23
How does the SSSE3 PALIGNR instruction work?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <x86intrin.h>
/* void palignr(const __m128i a, const __m128i b, const int offset) { */
#define palignr(a, b, offset) { \
char *buf = calloc(sizeof(__m128i) + 1, 1); \
__m128i res = _mm_alignr_epi8(a, b, offset); \
@aktau
aktau / osx1094_memmove_ivybridge.s
Last active August 29, 2015 14:05
libsystem_platform.dylib memcpy dump, OSX 10.9.4
# seems to delegate to the Nehalem variant, but with some different
# constants to jump directly to relevant parts inside of the function
0000000000003fa0 <__platform_memmove$VARIANT$Ivybridge>:
3fa0: 55 push %rbp
3fa1: 48 89 e5 mov %rsp,%rbp
3fa4: 49 89 fb mov %rdi,%r11
3fa7: 49 29 f3 sub %rsi,%r11
3faa: 48 89 f8 mov %rdi,%rax
3fad: 49 39 d3 cmp %rdx,%r11
3fb0: 0f 82 44 00 00 00 jb 3ffa <__platform_memmove$VARIANT$Nehalem+0x1a>
@aktau
aktau / tinytee.c
Created August 8, 2014 08:03
tinytee.c
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#if defined(__GNUC__)
#include <stdint.h>
#include <cpuid.h>
#elif defined(_WIN32)
#include <intrin.h>
typedef unsigned __int32 uint32_t;
#endif
#include <stdio.h>
/**

How to connect a PS3 controller to a different machine (PS3, Mac, PC)

You will need a Mini USB cable. Overcome your laziness and go get one!

A big misconception is that keep holding PS button will reset the controller's pairing. It doesn't! From my testing, the controller pairs with the last machine it was CONNECTED VIA A USB CABLE.

Here are the real Steps:

  1. Turn OFF your PS3 controller by either...
@aktau
aktau / json_bench.go
Created June 23, 2014 12:42
golang: json (un)marshal benchmark
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
)
type js struct {
@aktau
aktau / uv_hrtime_bench.c
Last active January 15, 2016 15:11
libuv: ghetto benchmark uv_hrtime implementations on OSX (a link for QPC on Windows, still handy: http://technet.microsoft.com/it-it/sysinternals/dn553408(v=vs.110).aspx)
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <mach/mach_time.h>
#include <pthread.h>
#ifdef DISABLE_INLINE
#define MAYBE_INLINE __attribute__ ((noinline))
@aktau
aktau / clean-kernels.sh
Created June 16, 2014 14:19
debian: modified clean kernels script (try not to remove kernels I didn't compile myself)
#!/bin/sh
#
# purge-old-kernels - remove old kernel packages
# Copyright (C) 2012 Dustin Kirkland <kirkland@ubuntu.com>
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
# Kees Cook <kees@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by