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
@flandr
flandr / x86_64-abi.txt
Created October 13, 2015 00:27
x86_64 abi
http://en.wikipedia.org/wiki/X86_calling_conventions#AMD64_ABI_convention
rax function(rdi, rsi, rdx, rcx, r8, r9, ...);
Preserved across
Register Usage function calls
%rax temporary register; with variable arguments No
passes information about the number of SSE
registers used; 1st return register
%rbx callee-saved register; optionally used as base Yes
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.nio.file.Paths;
/** Caplet to include runtime classpath. */
public class RuntimeClasspathCaplet extends Capsule {
private static final String PROP_RUNTIME_CP = "caplet.runtime.classpath";
/** Composition constructor. */
@flandr
flandr / tls-vs-pthread_getspecific.cc
Created July 5, 2015 17:03
Comparing __thread storage class specifier to pthread_getspecific on OS X 10.7+
// Benchmarking pthread_getspecific vs __thread on OS X
//
// Compile with clang++ -g -O3 -std=c++11
#include <stdio.h>
#include <pthread.h>
#include <chrono>
#include <cinttypes>
@flandr
flandr / gist:c0f0a22655c453083184
Created June 16, 2015 05:45
clean up kernel images in ubuntu /boot
apt-get remove $(dpkg --list 'linux-image*' |grep ^ii | awk '{print $2}'\ | grep -v `uname -r`)
#include <stdio.h>
int main(int argc, char **argv) {
char *c = new char[0];
printf("new[0] -> %p\n", c);
// This is undefined: return (int) *c;
return 0;
}
@flandr
flandr / no.cc
Last active August 29, 2015 14:20
Should you care about an extra indirection when updating atomics?
#include <stdio.h>
#include <stdlib.h>
#include <atomic>
#include <chrono>
std::chrono::milliseconds direct(int iters) {
auto start = std::chrono::system_clock::now();
auto val = new std::atomic<int>[1];
@flandr
flandr / gist:082c6453ec97b4e3ed7f
Created April 22, 2015 18:39
awk ternary example
# Data:
# 1ms foo
# 3.7s bar
# ...
# Convert to seconds
gawk 'BEGIN {FS=" +"} { val = $1 ~ /ms$/ ? $1 / 1000 : $1 * 1; print val,$2 }'
@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());
}
@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 / 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) {