Skip to content

Instantly share code, notes, and snippets.

View kidoman's full-sized avatar

Karan Misra kidoman

View GitHub Profile
@kidoman
kidoman / main.go
Created July 28, 2014 21:53
TLS Authenticated Docker
package main
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
@kidoman
kidoman / annotator.js
Last active January 9, 2016 15:32
A annotation library
function highlight(range) {
var textNodes = allTextNodes(range)
// Wrap all child text nodes
textNodes.forEach(function(node) {
var range = document.createRange()
range.selectNodeContents(node)
range.surroundContents(wrapperNode())
})
@kidoman
kidoman / sin.go
Created January 21, 2014 15:34
Sin kata in Go
package main
const accuracy = 0.00001
func multiplier(i int, angle, num, den float64) (float64, float64) {
num *= angle * angle
den *= float64(i * (i - 1))
return num, den
}
@kidoman
kidoman / saveme.go
Last active December 28, 2015 22:09
package main
import (
"github.com/gorilla/mux"
rpio "github.com/stianeikeland/go-rpio"
"log"
"net/http"
"os"
"os/signal"
"time"
@kidoman
kidoman / test.go
Created November 20, 2013 04:29
Test Go on RPi
package main
import (
rpio "github.com/stianeikeland/go-rpio"
"log"
"net/http"
)
func main() {
log.Print("Starting up...")
@kidoman
kidoman / main.go
Created November 6, 2013 00:06
A snatcher of sorts :)
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
@kidoman
kidoman / gist:6827452
Created October 4, 2013 15:02
Rand in Gorays which was not getting inlined
type randFn func() float64
func makeRand(seed uint32) randFn {
return func() float64 {
seed += seed
seed ^= 1
if int32(seed) < 0 {
seed ^= 0x88888eef
}
return float64(seed%95) / float64(95)
@kidoman
kidoman / card.cpp
Created September 26, 2013 01:46
Originally from http://www.cs.utah.edu/~aek/code/card.cpp Run with: c++ -O3 -o card card.cpp && ./card > aek.ppm
#include <stdlib.h> // card > aek.ppm
#include <stdio.h>
#include <math.h>
typedef int i;typedef float f;struct v{
f x,y,z;v operator+(v r){return v(x+r.x
,y+r.y,z+r.z);}v operator*(f r){return
v(x*r,y*r,z*r);}f operator%(v r){return
x*r.x+y*r.y+z*r.z;}v(){}v operator^(v r
){return v(y*r.z-z*r.y,z*r.x-x*r.z,x*r.
y-y*r.x);}v(f a,f b,f c){x=a;y=b;z=c;}v
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef int i; //Save space by using 'i' instead of 'int'
typedef float f; //Save even more space by using 'f' instead of 'float'
//Define a vector class with constructor and operator: 'v'
struct v {
f x,y,z; // Vector has three float attributes.
@kidoman
kidoman / dining_gophers.go
Last active December 23, 2015 14:09
My attempt at a "Dining Philosophers" simulation using Go concurrency Play version at: http://play.golang.org/p/Cy0ReZARbK
// Dining Gophers^2
// - By Karan
package main
import (
"flag"
"log"
"runtime"
"time"