Skip to content

Instantly share code, notes, and snippets.

Avatar

thorsten sideb0ard sideb0ard

View GitHub Profile
View raze4daze.cpp
#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 Dec 15, 2017 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
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
View colorqsort.c
#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 Nov 1, 2017
functional template
View filter.cpp
#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 Oct 29, 2017
cubic, quadratic and linear ways to solve problem
View timery.c
#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 Oct 27, 2017
given a number on the command line, prints a string version of the binary val
View binary_printer.c
#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 Nov 23, 2016
scrappy - was reading Joel on Software, and wrote this in relation to an interview question in there - "how we you reverse a linked list?"
View reverse_list.c
#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 Sep 22, 2016
work in progress - script to follow dependencies for libraries
View recursive dep resolver
#!/usr/bin/env python
import os
import re
import sys
import subprocess
READELF = "/usr/bin/readelf"
basedir = ""
libpattern = re.compile("\[([^\s]*)\]")
alllibs = list()
View gist:8bb48bb3bd71efc480b369b013a0f598
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 Jun 15, 2016
bitwise reverse lookup
View bittyzzz.c
#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 ) {