Skip to content

Instantly share code, notes, and snippets.

View deckarep's full-sized avatar
🎯
Focusing

Ralph Caraveo deckarep

🎯
Focusing
View GitHub Profile
@deckarep
deckarep / Paper.js sin(balls)
Created May 4, 2013 03:34
Messing with Paper.js for the first time. Cool stuff!
// The amount of circles we want to make:
var count = 79;
// Create a symbol, which we will use to place instances of later:
var path = new Path.Circle({
center: [0, 0],
radius: 10,
fillColor: new Color(1, 1, 0, .5),
blendMode:'normal'
@deckarep
deckarep / PIXI.DisplayObject.prototype.updateTransform
Created May 6, 2013 18:35
PIXI rotation about the x-axis working
PIXI.DisplayObject.prototype.updateTransform = function()
{
// TODO OPTIMIZE THIS!! with dirty
if(this.rotation != this.rotationCache)
{
this.rotationCache = this.rotation;
this._sr = Math.sin(this.rotation);
this._cr = Math.cos(this.rotation);
}
@deckarep
deckarep / gist:5530097
Created May 7, 2013 03:38
Demonstrates doing an rotation about the Y axis using the scale-x property of a given Sprite.
<!DOCTYPE HTML>
<html>
<head>
<title>pixi.js example 1</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000000;
}
package main
import (
"code.google.com/p/go.net/websocket"
)
type connection struct {
// The websocket connection.
ws *websocket.Conn
@deckarep
deckarep / gist:7539418
Last active December 28, 2015 17:59
From Andrew Gerrand's talk: Go: code that grows with grace http://vimeo.com/53221560 Notice that because the connection is a reader/writer io.Copy can be used. Short and sweet. Also notice that io.Copy runs in an infinite for loop so long as EOF or an error has not occurred.
//As seen in: http://vimeo.com/53221560 (Andrew Gerrand's talk: Go: code that grows with grace)
//A concurrent Echo Server
package main
import (
"io"
"log"
"net"
)
@deckarep
deckarep / goroutine-channel-pattern.go
Last active December 13, 2016 20:46
A Goroutine safe pattern using channels that abstracts away the usage of channels.
/*
A Goroutine safe pattern using channels that abstracts away the channels
This is a concept of creating a goroutine safe object that uses channels under the covers to communicate
with the internal map[string]string structure. I know that typically this kind of solution may done
with mutexes but the excercise was in using channels on purpose although they are heavier.
Note a couple of points:
- When using channels, you can still build a public-facing api that nicely abstracts them away, therefore
@deckarep
deckarep / foxgopher.go
Last active December 29, 2015 23:19
The fox, gopher and bag of beans puzzle in Go -- https://coderwall.com/p/lb3eaw
/*
The fox, gopher and bag of beans puzzle in Go.
https://coderwall.com/p/lb3eaw
*/
package main
import (
"fmt"
"log"
)

OSX i7-3720QM CPU @ 2.60GHz go1.2 darwin/amd64

Performance doesn't increase with GOMAXPROCS it gets worse on OSX!

GOMAXPROCS=1
./websocket_client 1 100000
Sent 400000 in 2.389414969s for a rate of 167404/second

GOMAXPROCS=2
./websocket_client 2 100000

Sent 400000 in 6.219798526s for a rate of 64310/second <-- Lost 100K msgs/second!

@deckarep
deckarep / websocket.go
Last active January 1, 2016 09:39
Untested unfortunately but you get the idea.
package main
import (
"github.com/codegangsta/martini"
"github.com/gorilla/websocket"
"log"
"net"
"net/http"
"sync"
)
@deckarep
deckarep / gist:9438523
Created March 8, 2014 20:39
Slide 46 solution from Golang Tour
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b := 0, 1
return func() int{
a, b = b, a +b