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 / 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 / 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.
@ksnabb
ksnabb / Tracks.markdown
Created September 27, 2014 11:06
A Pen by Kristoffer Snabb.
@ksnabb
ksnabb / geometry.js
Created September 29, 2014 18:07
calculate distance between two points
// Calculate distance between two given points on a plane
(function(root) {
// a and b are given as arrays of length 2
var distance = function(a, b) {
return Math.sqrt(Math.pow(b[0] - a[0], 2) + Math.pow(b[1] - a[1], 2));
};
root.distance = distance;
@ksnabb
ksnabb / geometry.js
Created September 29, 2014 19:07
Calculate current position according to start point destination point speed and time
// calculate a new point according to start point, destination, speed and time.
(function(root) {
// start and destination are points given as arrays of length 2
// speed is in m/s
// time is in seconds
var currentPosition = function(start, destination, speed, time) {
var distanceTravelled = speed * time;
// calulate the diff x and diff y to be travelled
@ksnabb
ksnabb / geometry.js
Created September 30, 2014 18:35
speed calculation accoring to start end point and time
// calculate the speed according to two points and two times
(function(root) {
// speed is returned in m / s
// points given as arrays of length 2 and coordinates in meters
// times are given in milliseconds
var speed = function(startPoint, endPoint, startTime, endTime) {
var distance = this.distance(startPoint, endPoint);
var timeDiff = (endTime - startTime) / 1000;
return distance / timeDiff;
@ksnabb
ksnabb / gulpfile.js
Last active August 29, 2015 14:09
Gulp file to compile static files. This is created to reduce work that I do over and over again for each new project.
var gulp = require('gulp');
var jade = require('gulp-jade');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var transform = require('vinyl-transform');
var stylus = require('gulp-stylus');
var nib = require('nib');
// templates