Skip to content

Instantly share code, notes, and snippets.

View whyrusleeping's full-sized avatar

Whyrusleeping whyrusleeping

View GitHub Profile
@whyrusleeping
whyrusleeping / gist:6108204
Last active December 20, 2015 09:30
examples of the C coding style i am going to enforce, for future students
/*
surround a binary operator (particular a low precedence
one) with spaces; don't try to write the most compact
code possible but rather the most readable.
*/
int i = 5 + 3;
//NOT
int i=5+3;
/*
@whyrusleeping
whyrusleeping / gist:5887111
Created June 28, 2013 18:55
Xor encryption dawg
void xor(char *str, char *key) {
char *t=key;
for (;*str;str++,t++){
if(!*t){t=key;}
*str^=*t;}}
@whyrusleeping
whyrusleeping / go-hi.vim
Created June 17, 2013 23:33
struct Method and Member highlighting for go in vim
syn match goMember "\.\zs\w\+\ze\%((\@!\W\)"
syn match goMethod "\.\zs\w\+\ze("
hi def link goMember Identifier
hi def link goMethod Function
@whyrusleeping
whyrusleeping / example.go
Created May 19, 2013 18:25
Broadcast Channel for go
//In this example i assume that 'T' is an int
func DoWhatever(toSay string, c chan int) {
for {
n := <-c
fmt.Printf('%s %d\n', toSay, n)
}
}
func main() {
@whyrusleeping
whyrusleeping / manTHEbrot.go
Created May 10, 2013 22:45
some go mandlebrot code
package main
import (
"fmt"
"runtime"
"image"
"image/color"
"image/png"
"math"
"os"
@whyrusleeping
whyrusleeping / fuzz.go
Last active December 17, 2015 02:29
Quick fuzzy search that could easily be improved
package main
import (
"fmt"
"os"
)
type FuzzMatch struct {
str string
val int
@whyrusleeping
whyrusleeping / bserv.go
Last active December 16, 2015 16:18
had a small idea for a build server in go DISCLAIMER: i wrote this without a real text editor off the top of my head, i dont think its gonna compile or work right at all. just ideas
package main
import (
"net"
"gob"
"os"
"bytes"
)
const (
@whyrusleeping
whyrusleeping / fun.go
Created April 18, 2013 22:30
Guild Wars Port Spam
package main
import (
"net"
"time"
)
func main() {
time.Sleep(time.Second)
addr,err := net.ResolveUDPAddr("udp", "192.168.1.10:6112")
@whyrusleeping
whyrusleeping / helloworld.cpp
Created April 17, 2013 15:37
OpenCL Code im trying to get to work
#include <utility>
#define __NO_STD_VECTOR
#include <CL/cl.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <iterator>
#include <fstream>
@whyrusleeping
whyrusleeping / makeprimes.c
Last active December 15, 2015 18:49
Function to make a list of primes.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
inline
int isPrime(int check, int *primes) {
for (; (*primes * *primes) < check; primes++)
if (check % *primes == 0) return 0;
return 1;
}