Skip to content

Instantly share code, notes, and snippets.

@jochasinga
jochasinga / app.js
Last active May 8, 2021 20:16
Node/Socket.io server code for syncing data from Firebase
var Firebase = require("firebase");
var express = require("express");
// Create HTTP Server
var app = express();
var server = require("http").createServer(app);
// Attach Socket.io server
var io = require("socket.io")(server);
// Indicate port 3000 as host
var port = process.env.PORT || 3000;
@jochasinga
jochasinga / index.html
Last active August 29, 2015 14:07
HTML + Angular displaying Firebase RGB values and changing background color accordingly
<!DOCTYPE html>
<!--Directive-->
<html ng-app="app">
<head>
</head>
<!--Controller-->
<body ng-controller="Ctrl">
<div class="header">
<!--Style-->
<h1 ng-style="{'background-color': 'rgb(' + data.r + ',' + data.g + ',' + data.b +')'}">
@jochasinga
jochasinga / index.js
Created October 15, 2014 16:14
Angularfire three-way binding
// Register firebase module
var app = angular.module("app", ["firebase"]);
// Set up controller function
app.controller("Ctrl", function($scope, $firebase) {
var firebaseRef = new Firebase(
// Replace this fictional URL with your own
"https://burning-limbo-6666.firebaseio.com/colors"
);
// create an AngularFire ref to the data
@jochasinga
jochasinga / get_set.swift
Last active August 29, 2015 14:08
Class getter and setter in Swift
import Darwin
class Circle {
var radius: Double
// contructor
init(radius: Double) {
self.radius = radius
}
@jochasinga
jochasinga / willset.swift
Created October 27, 2014 23:49
willSet hook in Swift
class Circle {
var radius: Double
init(radius: Double) {
self.radius = radius
}
}
class Square {
var sideLength: Double
@jochasinga
jochasinga / json_to_instances.go
Last active January 12, 2020 15:47
How to convert JSON blob into an array of instances
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int
@jochasinga
jochasinga / models.go
Last active August 29, 2015 14:16
Simple struct models for a blog post
package main
import "time"
// User
type User struct {
Id int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
}
@jochasinga
jochasinga / routes.go
Last active August 29, 2015 14:17
URL endpoints for REST APIs
package main
import (
mux "github.com/julienschmidt/httprouter"
)
type Route struct {
Method string
Path string
Handle mux.Handle // httprouter package as mux
@jochasinga
jochasinga / handlers.go
Last active August 29, 2015 14:17
Handler functions for blog REST API
package main
import (
"encoding/json"
"fmt"
"net/http"
"io"
"io/ioutil"
"strconv"
"time"
@jochasinga
jochasinga / router.go
Last active August 29, 2015 14:17
Router for blog API
package main
import mux "github.com/julienschmidt/httprouter"
func NewRouter *mux.Router {
router := mux.New()
for _, route := range routes {