Skip to content

Instantly share code, notes, and snippets.

@jochasinga
jochasinga / testserver.go
Last active April 5, 2016 14:48
Creating a standard test server in goconvey testing
// Error handling omitted for brevity
var handler = func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello world!")
}
func TestGet(t *testing.T) {
Convey("GIVEN a test server", t, func() {
ts := httptest.NewServer(http.HandlerFunc(handler))
Convey("WITH a GET request", func() {
@jochasinga
jochasinga / structs.go
Created January 20, 2016 15:53
Simple structs in Go
type Animal struct {
Kingdom string
Legs uint8
}
type Cat struct {
Animal
Sound string
Fav []string
}
@jochasinga
jochasinga / easing.pde
Created December 8, 2015 20:09
Basic easing in Processing
float x;
float y;
// This is the easing factor, the more the faster the (x, y) reach the target
float easing = 0.05;
void setup() {
size(640, 360);
noStroke();
}
@jochasinga
jochasinga / tweet_2.json
Last active November 12, 2015 16:04
JSON for Cassandra mapping
{
"jochasinga": {
"email": "jo.chasinga@gmail.com",
"row_data": [
{
"tweet_id": "97719c50-e797-11e3-90ce-5f98e903bf02",
"tweet": "I want to go to @banksy ‘s exhibition today so badly."
},
{
"tweet_id": "bd48ac00-8310-11e5-985d-dd516b67e698",
@jochasinga
jochasinga / tweet_1.json
Last active November 11, 2015 22:28
Sample JSON for Cassandra mapping
[
{
"jochasinga": {
"email": "jo.chasinga@gmail.com",
"tweet": "I want to go to @banksy ‘s exhibition today so badly."
}
},
{
"banksy": {
"email": "banksy@bs.com",
@jochasinga
jochasinga / random_type.go
Created November 9, 2015 14:01
Snippet on how to guess types of data from arbitrary JSON
package main
import (
"encoding/json"
"fmt"
"log"
)
type Hole struct {
Alias string `json:"alias"`
@jochasinga
jochasinga / custom.go
Created November 5, 2015 01:55
Pretty cool trick to map Go struct to and from arbitrary JSON
/* Original code posted here https://stackoverflow.com/questions/27492888/how-to-map-json-objects-with-dynamic-fields-to-go-structs */
package main
import (
"fmt"
"encoding/json"
"errors"
)
@jochasinga
jochasinga / Gruntfile.js
Last active October 29, 2015 15:14
Grunt file for watching SaSS
module.exports = function(grunt) {
// Project configuration
grunt.initConfig({
// optionally read package.json
pkg: grunt.file.readJSON('package.json'),
// Metadata
meta: {
basePath: '../', // your project path
srcPath: '../static/scss/', // where you keep your sass files
@jochasinga
jochasinga / simple_chat.rs
Last active August 29, 2015 14:27 — forked from andelf/simple_chat.rs
Simple Socket Chat Server in Rust. (TcpListener, TcpStream, SharedChan, RWArc)
extern mod sync;
// str op trait
use std::str::StrSlice;
// for tcp listen
use std::io::{TcpListener, TcpStream};
use std::io::net::ip::SocketAddr;
// for trait
use std::io::{Listener, Writer, Acceptor, Buffer};
// for spawn
@jochasinga
jochasinga / animal.py
Created July 29, 2015 17:15
Simple example class in Python
#!/usr/env/bin python
import time
class Animal(object):
_tired = False
_pace = 1
def __init__(self, legs, kingdom):
self.legs = legs