Skip to content

Instantly share code, notes, and snippets.

@fmela
fmela / stacktrace.cxx
Last active November 20, 2024 13:00
A C++ function that produces a stack backtrace with demangled function & method names.
/*
* Copyright (c) 2009-2017, Farooq Mela
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@fmela
fmela / agm_log.c
Created December 30, 2011 20:15
A natural logarithm function that uses the arithmetic-geometric mean.
double
agm_log(double x)
{
double a, b, e, e0 = DBL_MAX;
assert(x > 0.0);
for (a = (x + 1.0) * 0.5, b = sqrt(x); (e = fabs(a - b)) < e0; e0 = e) {
a = 0.5 * (a + b);
b = sqrt(a * b);
@mbostock
mbostock / .block
Last active January 26, 2022 14:32 — forked from mbostock/.block
Spline Transition
license: gpl-3.0
@sasha-id
sasha-id / README
Created March 23, 2012 15:03
MongoDB multiple instance upstart scripts: mongodb, mongod --configsvr and mongos
MongoDB upstart scripts for Ubuntu.
Run following commands after installing upstart scripts:
ln -s /lib/init/upstart-job /etc/init.d/mongoconf
ln -s /lib/init/upstart-job /etc/init.d/mongodb
ln -s /lib/init/upstart-job /etc/init.d/mongos
To start services use:
@jboner
jboner / latency.txt
Last active May 10, 2025 11:02
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
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 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@shanselman
shanselman / gist:5422230
Last active April 10, 2025 15:49
Evil Blog Comment Spammer just exposed his template through some error and the whole thing showed up in my comments.
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as
you did, the {internet|net|web} will be {much more|a lot more}
useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch}
your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
Thanks.|
@debasishg
debasishg / gist:8172796
Last active April 20, 2025 12:45
A collection of links for streaming algorithms and data structures

General Background and Overview

  1. Probabilistic Data Structures for Web Analytics and Data Mining : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation.
  2. Models and Issues in Data Stream Systems
  3. Philippe Flajolet’s contribution to streaming algorithms : A presentation by Jérémie Lumbroso that visits some of the hostorical perspectives and how it all began with Flajolet
  4. Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani : One of the early papers on the subject.
  5. [Methods for Finding Frequent Items in Data Streams](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&amp;rep=rep1&amp;t
@fmela
fmela / GNUmakefile
Created February 17, 2014 23:04
C program makefile boilerplate
SOURCES = $(wildcard *.c)
HEADERS = $(wildcard *.h)
OBJECTS = $(SOURCES:%.c=%.o)
PROGRAM = $(shell basename `pwd`)
CC := $(shell which clang || which gcc)
CFLAGS = -Wall -W -O
LIBS =
LDFLAGS = $(LIBS:%=-l%)
@fmela
fmela / GNUmakefile
Last active July 8, 2017 18:54
C++ program makefile boilerplate
SOURCES = $(wildcard *.cxx)
HEADERS = $(wildcard *.hxx)
OBJECTS = $(SOURCES:%.cxx=%.o)
PROGRAM = $(shell basename `pwd`)
CC := $(shell which clang || which gcc)
CFLAGS = -Wall -W -O -fno-exceptions -fno-rtti
LIBS = stdc++ m
LDFLAGS = $(LIBS:%=-l%)
@fmela
fmela / flipsign.c
Created February 17, 2014 23:57
Branch-free conditional sign flip in C
int f(int x, int negate) {
return (x ^ -negate) + negate;
}