Skip to content

Instantly share code, notes, and snippets.

View sideb0ard's full-sized avatar

thorsten sideb0ard sideb0ard

View GitHub Profile
@sideb0ard
sideb0ard / raze4daze.cpp
Created November 29, 2019 19:27
Envelopes
#include <math.h>
#include <iostream>
#ifndef M_PI
#define M_PI (3.14159265358897932)
#endif
#define TWO_PI (2.0 * M_PI)
enum Envelope
@sideb0ard
sideb0ard / latency.txt
Created December 15, 2017 21:40 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
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
@sideb0ard
sideb0ard / colorqsort.c
Created November 8, 2017 04:59
colored qsort
#include <stdio.h>
#define PIVOT "\x1b[37m"
#define LOWERCOLOR "\x1b[38;5;226m"
#define UPPERCOLOR "\x1b[38;5;200m"
#define GREYRCOLOR "\x1b[38;5;124m"
#define RESET "\x1b[0m"
void print_nums(int *nums, int numnumbs)
{
@sideb0ard
sideb0ard / filter.cpp
Created November 1, 2017 20:51
functional template
#include <iostream>
#include <vector>
#include <list>
typedef std::vector<int> Ints;
using std::vector;
bool is_even(int x)
{
return x % 2 == 0;
@sideb0ard
sideb0ard / timery.c
Created October 29, 2017 02:48
cubic, quadratic and linear ways to solve problem
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
int nums_len = 20;
static int nums[] = {31, -41, 59, 26, -53, 58, 97, -93, -23, 84, 45, 344, -343, -34, 456, 87, 102, -434, 20, 188};
bool is_bigger(int numone, int numtwo)
{
return numtwo > numone ? true : false;
@sideb0ard
sideb0ard / binary_printer.c
Last active October 27, 2017 23:32
given a number on the command line, prints a string version of the binary val
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
// given a number on the command line, prints a string version of the binary val
void print_bin(int32_t num)
{
for (unsigned int i = 0, j = 2147483648; i < 32; i++, j = j >> 1)
{
if (num & j)
@sideb0ard
sideb0ard / reverse_list.c
Created November 23, 2016 02:03
scrappy - was reading Joel on Software, and wrote this in relation to an interview question in there - "how we you reverse a linked list?"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// linked list
//
typedef struct sweary sweary;
struct sweary {
char wurd[64];
sweary *next;
@sideb0ard
sideb0ard / recursive dep resolver
Last active September 22, 2016 23:21
work in progress - script to follow dependencies for libraries
#!/usr/bin/env python
import os
import re
import sys
import subprocess
READELF = "/usr/bin/readelf"
basedir = ""
libpattern = re.compile("\[([^\s]*)\]")
alllibs = list()
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
@sideb0ard
sideb0ard / bittyzzz.c
Created June 15, 2016 16:23
bitwise reverse lookup
#include <stdio.h>
int bignumz[16];
int conv_bitz(int num)
{
for ( int i = 0 ; i < 16; i++) {
//printf("Comparing %d with %d\n", num, ( 1 << i));
//printf("AND is %d\n", num & ( 1 << i));
if ( (num & ( 1 << i )) == num ) {