Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / main.go
Last active August 29, 2015 01:55
Diff image compression
package main
import (
"compress/gzip"
"fmt"
"image/jpeg"
"log"
"os"
)
@unixpickle
unixpickle / main.m
Last active August 29, 2015 13:58
Bitmap Average using Accelerate.framework
//
// main.m
// BitmapAverage
//
// Created by Alex Nichol on 4/8/14.
// Copyright (c) 2014 Alex Nichol. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Accelerate/Accelerate.h>
@unixpickle
unixpickle / cpuid.c
Last active August 29, 2015 13:59
Inspect x86 CPUID results
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
void print_chars(uint64_t num);
bool isvischar(char ch);
int main(int argc, const char * argv[]) {
if (argc != 2) {
@unixpickle
unixpickle / firewall.sh
Created April 22, 2014 19:59
My iptables configuration script
#!/bin/bash
setupAccept () {
$1 -P INPUT ACCEPT
$1 -P OUTPUT ACCEPT
$1 --flush
$1 -A INPUT -i lo -j ACCEPT
$1 -A OUTPUT -o lo -j ACCEPT
@unixpickle
unixpickle / calc.coffee
Created May 3, 2014 22:14
Calculate b-tree size
# Take a binary tree of depth D, where the lowest nodes have 1 bit, the second lowest have 2 bits, etc.
# This script finds the number of bits in a tree of depth D.
if process.argv.length isnt 3
console.log 'Usage: coffee calc.coffee <depth>'
process.exit()
depth = parseInt process.argv[2]
count = 0
for i in [0...depth]
@unixpickle
unixpickle / count.coffee
Created May 8, 2014 21:41
Count occurrences of a line in a file
fs = require 'fs'
fs.readFile 'letters.txt', (err, buffer) -> processFile buffer.toString()
processFile = (s) ->
counts = {}
lines = s.split '\n'
for line in lines
if counts[line]?
counts[line]++
@unixpickle
unixpickle / download.coffee
Created May 31, 2014 23:20
Download Streaming Rough Code
Page = require './page'
Session = require '../session'
Transfer = require '../transfer'
tar = require 'tar-stream'
url = require 'url'
getTarName = (path) ->
result = path.match /\/([^\/]*)$/
str = if result? then result[1] else path
if str[str.length - 1] is '/'
@unixpickle
unixpickle / Disassembly
Created June 15, 2014 20:56
Demonstrate covariant return thunk in C++
__ZN13FancyReturner7BaseRefEv: # the regular
00000001000014a0 pushq %rbp
00000001000014a1 movq %rsp, %rbp
00000001000014a4 movq %rdi, 0xfffffffffffffff8(%rbp)
00000001000014a8 movq 0xfffffffffffffff8(%rbp), %rdi
00000001000014ac addq $0x8, %rdi
00000001000014b3 movq %rdi, %rax
00000001000014b6 popq %rbp
00000001000014b7 ret
00000001000014b8 nopl (%rax,%rax)
@unixpickle
unixpickle / test.dart
Created July 18, 2014 22:19
Get function signature for main()
import 'dart:io';
typedef void EmptyFunc();
typedef void OneFunc(List<String> _);
myMain1(List<String> _) {
}
myMain2() {
}
@unixpickle
unixpickle / prof.dart
Created July 30, 2014 03:23
Compare switch and List speed in Dart
import 'dart:io';
void main(List<String> args) {
if (args.length != 1) {
print('Usage: dart prof.dart <list|switch>');
exit(1);
}
if (args[0] == 'list') {
for (int j = 1; j < 128; j++) {
for (int i = 0; i < 100000; i++) {