Skip to content

Instantly share code, notes, and snippets.

View flandr's full-sized avatar
💭
Working for a corporate behemoth

Nate Rosenblum flandr

💭
Working for a corporate behemoth
View GitHub Profile

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
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

From e8fb47a394e5c2e0ba6110ff96d216ba2c16bf61 Mon Sep 17 00:00:00 2001
From: Nate Rosenblum <nater@maginatics.com>
Date: Mon, 13 May 2013 16:33:19 -0700
Subject: [PATCH] Hide camellia symbols that collide with openssl
---
src/lib/crypto/builtin/camellia/camellia.c | 32 +++++++++++++++---------------
src/lib/crypto/builtin/camellia/camellia.h | 15 --------------
2 files changed, 16 insertions(+), 31 deletions(-)
// Define a static local variable once, safely, for MSVC
//
// This macro is necessary because MSVC pre-2013 doesn't
// properly implement C++11 static local initialization.
// It is equivalent to writing something like
//
// static type var = stmt;
//
// in a compliant compiler (e.g. GCC since who knows when)
// Copyright © 2014 Nate rosenblum <flander@gmail.com>
// This work is free. You can redistribute it and/or modify it under the
// terms of the Do What The Fuck You Want To Public License, Version 2,
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#include <inttypes.h>
#include <stdio.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/function.hpp>
# Plot histograms from variable frame input
getplots <- function(...) {
frames <- list(...)
names <- as.list(substitute(list(...)))[-1]
# Find the max range
m <- max(sapply(frames, function(f) { max(f$len) }))
plots <- mapply(function(f,n) {
print(max(f$len))
@flandr
flandr / urllib2_tls.py
Created October 16, 2014 15:22
Forcing TLS in Python's urllib2
# Python 2.6's urllib2 does not allow you to select the TLS dialect,
# and by default uses a SSLv23 compatibility negotiation implementation.
# Besides being vulnerable to POODLE, the OSX implementation doesn't
# work correctly, failing to connect to servers that respond only to
# TLS1.0+. These classes help set up TLS support for urllib2.
class TLS1Connection(httplib.HTTPSConnection):
"""Like HTTPSConnection but more specific"""
def __init__(self, host, **kwargs):
httplib.HTTPSConnection.__init__(self, host, **kwargs)

Keybase proof

I hereby claim:

  • I am flandr on github.
  • I am nater (https://keybase.io/nater) on keybase.
  • I have a public key whose fingerprint is DB2F 5C5D 6B97 6DDE 1C42 07D3 8790 0700 F0FB E18A

To claim this, I am signing this object:

@flandr
flandr / move_function.cc
Last active August 29, 2015 14:13
Surprising behavior of std::function move constructor in Apple clang
#include <stdio.h>
#include <functional>
#include <utility>
struct Big {
char data[1024];
};
int main(int argc, char **argv) {
@flandr
flandr / gist:dc4475761a5929e1fa01
Created January 21, 2015 18:48
xcode 6.1.1 std functional move constructor
template<class _Rp, class ..._ArgTypes>
template <class _Alloc>
function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
function&& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if (__f.__f_ == (__base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
@flandr
flandr / exp.cc
Created February 7, 2015 22:10
Some basically insane template-based function dispatching magic
#include "exp.h"
void no_args() {
printf("no args\n");
}
void just_pathparams(PathParam<std::string> p1) {
printf("just path params: %s\n", p1.value().c_str());
}