Skip to content

Instantly share code, notes, and snippets.

View whyrusleeping's full-sized avatar

Whyrusleeping whyrusleeping

View GitHub Profile
@whyrusleeping
whyrusleeping / gist:4609052
Created January 23, 2013 16:23
Notes from the git lesson last night

To copy a git repository from online (github or other)

git clone [insert url here]

That will create a directory for the project and copy it to your local machine.

Once youve made changes to the files, for each file you modified do:

git add myFile.txt
@whyrusleeping
whyrusleeping / arrayGo.go
Created January 22, 2013 23:34
throwing up some code for later
package main
import "fmt"
import "math/rand"
func IsSorted(arr []int) bool {
for i := 1; i < len(arr); i++ {
if arr[i - 1] > arr[i] {
return false
@whyrusleeping
whyrusleeping / gist:4575613
Created January 19, 2013 22:30
Go Mergesort
func merge(arr []int, start, mid, end int) {
var sorted = make([]int, (end - start) + 1)
sortPos := 0
leftPos := start
rightPos := mid + 1
for ;sortPos < len(sorted); {
if !(leftPos > mid || rightPos > end) {
if arr[leftPos] < arr[rightPos] {
sorted[sortPos] = arr[leftPos]
@whyrusleeping
whyrusleeping / gist:4201095
Created December 4, 2012 05:52
Huffman tree in java, kinda
import java.io.InputStream;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
public class HuffmanTree {
private Map<Character, Integer> counts;
@whyrusleeping
whyrusleeping / compins.cpp
Created December 3, 2012 07:32
Implicit Compilation (aka, shell scripting fun)
#if 0
#!/bin/sh
g++ compins.cpp -o compins
./compins
exit
#endif
#include <iostream>
using std::cout;
@whyrusleeping
whyrusleeping / revised algorithm in c
Created December 1, 2012 21:55
fuzzy string comp
public const float SCALE = 1.5;
public double compStr(string a, string b)
{
return (double)lcSubString2(a, b)/ Math.Pow((a.Length > b.Length ? a.Length : b.Length), SCALE);
}
public int lcSubString2(string _a, string _b)
{
@whyrusleeping
whyrusleeping / kbNonblock.c
Created October 30, 2012 21:49
Non Blocking Keyboard Input (C++)
#include <termios.h>
#include <stdlib.h>
void RestoreKeyboardBlocking(struct termios *initial_settings)
{
tcsetattr(0, TCSANOW, initial_settings);
}
void SetKeyboardNonBlock(struct termios *initial_settings)
{
try
{
mainsock = dynamic_cast<whatever>;
if(!mainsock)
throw ERROR_CODE;
}
catch(int er_code)
{
}
@whyrusleeping
whyrusleeping / example.c
Created October 22, 2012 16:46
Bit Fields and Unions
#include <stdio.h>
typedef struct a
{
unsigned short q : 4;
unsigned short w : 2;
unsigned short e : 4;
unsigned short r : 6;
}A;
#include <stdio.h>
#define FILL(arr,n,eq) for(int i = 0; i < n; i++) arr[i] = eq;
#define to ; i <=
#define DO(range) for(int i = range; i++)
int main()
{
int myArray[30];