Skip to content

Instantly share code, notes, and snippets.

View ksnabb's full-sized avatar

Kristoffer Snabb ksnabb

  • Reaktor Innovations
  • Helsinki, Finland
View GitHub Profile
@ksnabb
ksnabb / express app with CRUDS
Created August 2, 2013 19:27
This is a short example file of how an express app and socket.io work together with the CRUDS module.
express = require("express")
app = express()
# app configuration etc...
server = http.createServer(app)
server.listen app.get("port"), ->
console.log "Express server listening on port " + app.get("port")
# REST API and socket.io interface
@ksnabb
ksnabb / xyz tiles
Created August 26, 2013 18:56
CoffeeSript version of counting tile x y z or coordinates from tile x y z.
long2tile = (lon, zoom) ->
Math.floor (lon + 180) / 360 * Math.pow(2, zoom)
lat2tile = (lat, zoom) ->
Math.floor (1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, zoom)
tile2long = (x, z) ->
x / Math.pow(2, z) * 360 - 180
@ksnabb
ksnabb / cruds backbone sync
Last active December 28, 2015 09:58
example of using CRUDS with Backbone for reading and creating entitites
crudsSync = (socket, method, model, options) ->
if method is 'create'
socket.once 'create', (data) ->
model.set data
socket.emit 'create', model.attributes
else if method is 'read'
socket.once 'get', (data) ->
@ksnabb
ksnabb / formdata cruds example
Last active December 28, 2015 09:58
example of sending data to CRUDS using formdata
navigator.geolocation.getCurrentPosition (evt) ->
formdata = new FormData()
formdata.append "longitude", evt.coords.longitude
formdata.append "latitude", evt.coords.latitude
formdata.append "accuracy", evt.coords.accuracy
formdata.append "timestamp", evt.timestamp
req = new XMLHttpRequest()
req.open("POST", "/location", true)
req.send(formdata)
@ksnabb
ksnabb / deselecable radio buttons with jquery
Created February 10, 2014 13:08
Deselectable radio buttons with JQuery
@$(".radio").each (index, elem) ->
$(elem).on "click", (evt) ->
if $(elem).hasClass "checked"
evt.target.checked = false
$(elem).removeClass "checked"
else
evt.target.checked = true
$(elem).addClass "checked"
@ksnabb
ksnabb / wgs84-distance.js
Created April 25, 2014 07:23
JavaScript: WGS84 distance (Harvesin)
/*
Pass in two WGS84 points as arrays in x y order to calcuate the
meter distance between them.
distance([longitude1, latitude1], [longitude2, latitude2])
The distance is calculated with the help of the harvesin formula
*/
var distance = function(coords1, coords2) {
@ksnabb
ksnabb / form-validation.markdown
Created August 13, 2014 19:16
A Pen by Kristoffer Snabb.
@ksnabb
ksnabb / hello.js
Created September 12, 2014 07:25
Hello world Node.js web application
var http = require("http");
var server = http.createServer(function(req, res) {
res.end("hello world");
});
server.listen("8090");
@ksnabb
ksnabb / hello.go
Last active August 29, 2015 14:06
Hello world golang web application
package main
import "net/http"
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
}
func main() {
http.HandleFunc("/", handler)
@ksnabb
ksnabb / Canvas-image-rotation.markdown
Created September 13, 2014 09:34
A Pen by Kristoffer Snabb.