Skip to content

Instantly share code, notes, and snippets.

View emaxerrno's full-sized avatar
💭
I may be slow to respond.

Alexander Gallego emaxerrno

💭
I may be slow to respond.
View GitHub Profile
@emaxerrno
emaxerrno / Makefile
Last active August 29, 2015 14:13 — forked from lindenb/Makefile
a.out: test.c githash.h
gcc $<
githash.h:
echo -n '#ifndef GIT_HASH\n#define GIT_HASH "' > $@ && \
git rev-parse HEAD | tr -d "\n" >> $@ && \
echo '"\n#endif' >> $@
(require 'popwin)
(setq display-buffer-function 'popwin:display-buffer)
(push '("^\*helm .+\*$" :regexp t) popwin:special-display-config)
(push '("^\*helm-.+\*$" :regexp t) popwin:special-display-config)
@emaxerrno
emaxerrno / ._what.md
Last active August 29, 2015 14:08 — forked from kneath/._what.md

Badass git pull alternative

Add this little snippet to your ~/.gitconfig and it amps up your git pull by means of git up

  1. Adds in a list of the commits you're pulling down
  2. Auto-prunes remote branches
  3. Defaults to pull --rebase - gets rid of unnecessary merge commits. If you don't know what rebase does, this is probably safe for you. If you know what rebase does, you should know where this will not be safe for you.

Scott Chacon and Ryan Tomayko basically figured out how to do this and I am stealing all of the credit.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
L2 cache reference ........................... 7 ns                     14x L1 cache
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns                     20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

#!/bin/bash
echo Building Google Protobuf for Mac OS X / iOS.
echo Use 'tail -f build.log' to monitor progress.
(
PREFIX=`pwd`/protobuf
mkdir ${PREFIX}
mkdir ${PREFIX}/platform
/**
* Detect if the browser can play MP3 audio using native HTML5 Audio.
* Invokes the callack function with first parameter is the boolean success
* value; if that value is false, a second error parameter is passed. This error
* is either HTMLMediaError or some other DOMException or Error object.
* Note the callback is likely to be invoked asynchronously!
* @param {function(boolean, Object|undefined)} callback
*/
function canPlayAudioMP3(callback){
try {
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
package com.yieldmo.rtb.util
class LazyMap[A,B](delegate: Map[A,() => B]) extends scala.collection.immutable.Map[A,B]{
def get(key: A): Option[B] = delegate.get(key).map{ _() }
def iterator: Iterator[(A,B)] = delegate.iterator.map{ pair => (pair._1, pair._2()) }
def +[B1 >:B](kv: (A, B1)): Map[A, B1] = new LazyMap[A,B1](delegate + (kv._1 -> (() => kv._2)))
def -(key: A): Map[A, B] = new LazyMap[A,B](delegate - key)
}
@emaxerrno
emaxerrno / echo.rs
Created February 14, 2014 03:41 — forked from elyzion/echo.rs
//! A simplistic echo server that allows client to exit using the quit command.
//! Based on various examples and sources from the internet.
#[crate_id = "main:0.1pre"];
#[crate_type = "bin"];
use std::io::{Listener, Acceptor, BufferedStream};
use std::io::net::tcp::TcpListener;
use std::io::net::ip::{SocketAddr, Ipv4Addr};
//use std::io::io_error; //Not using this at the moment.
var addScriptTag = function(url) {
var node = document.createElement('script');
node.type = 'text/javascript';
node.async = true;
node.src = ('https:' === document.location.protocol ? 'https:' : 'http:') + url;
node.id = '' + new Date().getTime();
var topelem = (document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]);
topelem.appendChild(node);
};