Skip to content

Instantly share code, notes, and snippets.

View obstschale's full-sized avatar
🥑
Avocado for the wise.

Hans-Helge Buerger obstschale

🥑
Avocado for the wise.
View GitHub Profile
@obstschale
obstschale / generaterandomchanges
Last active December 17, 2015 05:59
small script to generate some dummy files and commit them. (by @matthewmccullough | src: https://github.com/matthewmccullough/scripts/blob/master/generaterandomchanges)
#!/bin/bash
#Ensure we have the quantity specified on the CLI
if [ -z "$3" ]; then ARG_ERR=ERR; fi
if [ -z "$2" ]; then ARG_ERR=ERR; fi
if [ -z "$1" ]; then ARG_ERR=ERR; fi
if [ -n "$ARG_ERR" ];
then
echo "Usage: <filecount> <filenamebase> <filenameextension>"
exit
@obstschale
obstschale / hash_function.c
Created May 9, 2013 00:20
A good hash function is a bit like a random number generator. Given a regular pattern of input, the output appears chaotic. A good hash function for integers is where p0, p1, and p2 are large primes. (T does not have to be prime.)
h(k) = ( (p0 * k + p1) % p2) % T
h(k) = ((438439 * k + 34723753) % 376307) % 10
@obstschale
obstschale / LoC from git log with rm certain files
Created April 21, 2013 10:18
Displays the added lines, removed lines and the total for a specific author in a git log and removes certain files using `grep -v`. (src: http://codeimpossible.com/2011/12/16/Stupid-Git-Trick-getting-contributor-stats/ )
git log --author="Jared Barboza" --pretty=tformat: --numstat | \
grep -v public/javascripts/jquery | \
gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END \
{ printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
@obstschale
obstschale / LoC from git log
Created April 21, 2013 10:14
Displays the added lines, removed lines and the total for a specific author in a git log. (src: http://codeimpossible.com/2011/12/16/Stupid-Git-Trick-getting-contributor-stats/ )
git log --author="Hans-Helge Bürger" --pretty=tformat: --numstat | \
gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END \
{ printf "added lines: %s removed lines: %s total lines: %s\n",add,subs,loc }' -
#include "heap.h"
#include <stdlib.h>
struct Heap {
int capacity;
int size;
int *heap;
int type;
};
@obstschale
obstschale / Countchar().c
Last active December 15, 2015 07:49
count character in string
int countchar (char list[])
{
int i, count = 0;
for (i = 0; list[i] != '\0'; i++)
count++;
return (count);
}
void quickSort(int a[ ], int from, int to)‏
{ // sort partition from ... to of array a
int i, pivot, new_val;
if (from < to) // at least 2 elements in partition
{
pivot = from;
for (i = from + 1; i <= to; i++)‏
{
new_val = a[i];
@obstschale
obstschale / mergesort.c
Created July 23, 2012 13:00
Merge Sort
void mergeSort(int a[ ], int n)‏
{
int endcstr, endbstr, check, finished = 0; // booleans
int i, j, k, maxc, maxb;
int *b, *c; // pointers for arrays
b = (int *) malloc( n * sizeof(int) );
c = (int *) malloc( n * sizeof(int) );
while ( !finished )‏
{ // distribution pass
i = j = k = 0;
@obstschale
obstschale / shuttlesort.c
Created July 23, 2012 12:01
Shuttle Sort
void shuttlesort (int a[ ], int n)
{
int temp, i, j;
for (i = 0; i < n – 1; i++) // primary pass
{
if (a[i] > a[i + 1])
{
j = i – 1;
temp = a[i + 1]; // small value to move back
@obstschale
obstschale / bubblesort-flag.c
Created July 23, 2012 11:57
Flagged Bubble Sort
void bubbleSortV2(int a[ ], int n) // flagged bubble sort
{
int i, temp, comps, sorted = 0; // sorted is initially false
comps = n – 1;
while ( !sorted ) // comps reduces on each pass
{
sorted = 1; // set true for each pass
for (i = 0; i < comps; i++)‏
{