Skip to content

Instantly share code, notes, and snippets.

@tuvokki
tuvokki / gist:7080280
Created October 21, 2013 08:11
AMD: Basic principle; You don't create any global variables. Not even a 'Whatever' namespace. Instead, you explicitly export any variables you want to expose to the AMD framework. On the other hand, when you need a dependency, you tell the AMD framework. The AMD framework then takes care of supplying that dependency to you. It is a bit like OSGi…
/*
Have a look at these links:
https://github.com/amdjs/amdjs-api/wiki/AMD
http://requirejs.org/docs/whyamd.html
EXAMPLE:
*/
define('moduleA', [ /* no dependencies */ ], function() {
// Here we are inside the callback function body. This is called by AMD.
@tuvokki
tuvokki / gist:7080299
Created October 21, 2013 08:13
Script by Stijn
(function() {
var test, something;
function privateFunc() {
};
var myObject = {
myMethod: function() {privateFunc.apply(this, []);}
};
/**
* This method will calculate the change in a player's
* Elo rating after playing a single game against another player.
* The value K is the maximum change in rating.
**/
function calculateELORatingChange(elo1, elo2, k)
{
var percentage = 1 / ( 1 + Math.pow( 10, (elo2 - elo1) / 400 ) );
return {
@tuvokki
tuvokki / test-data.js
Created February 9, 2015 20:52
Generate data for a blog with mongoskin
/**
* Run with: $ node test-data.js
*/
var mongoskin = require('mongoskin'),
http = require('http'),
db = mongoskin.db('mongodb://@localhost:27017/tuvok', {safe:true}),
coll = db.collection("posts"),
id,
titleDone = false,

Add this to a bogart (or express etc.) route to do funky suff. See bogart-blog and just paste this in app.js.

router.get('/✌☮✔', function (req) {
  return 'Freedom and Peace = like!';
});

image

@tuvokki
tuvokki / bcolors.py
Created June 30, 2015 11:18
Simple Python class to create colored messages for command line printing
# Helper class to print colored output
#
# To use code like this, you can do something like
#
# print bcolors.WARNING
# + "Warning: No active frommets remain. Continue?"
# + bcolors.ENDC
#
# you can also use the convenience method bcolors.colored like this
#
//See: http://stackoverflow.com/questions/15937267/inject-service-in-app-config
//See: http://stackoverflow.com/questions/14688290/inject-dependencies-in-run-method-of-the-module-in-angularjs
var app = angular.module('SystemSettings', ['ui.router', 'formly', 'formlyBootstrap']);
/**
* Set up routing
*/
app.config(function($stateProvider, $urlRouterProvider) {
// For any unmatched url, redirect to /main
@tuvokki
tuvokki / README.md
Created December 21, 2015 15:44 — forked from chriswessels/README.md
A guide to setting up self-hosted infrastructure for Meteor applications on Ubuntu Server 13.04.

#Meteor and Self-hosted Infrastructure

Meteor is an eye-opening JavaScript framework that runs on both the client and the server, giving developers a revolutionary take on software engineering. If you are not familiar with Meteor, I urge you to visit their website.

##An overview

In this brief gist, I am going to discuss the process of setting up a server (in my case, a VPS) to host Meteor applications.

My experience with Meteor has been brief, however it has not taken much demonstration for me to realise the significance of this stellar framework. Let's jump right in!

@tuvokki
tuvokki / vscode.settings.json
Last active March 24, 2017 15:22
A set of settings for VSCode
// Place your settings in this file to overwrite the default settings
{
"window.zoomLevel": 0,
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.minimap.enabled": true,
"editor.minimap.renderCharacters": false,
"editor.cursorStyle": "underline-thin",
"editor.dragAndDrop": true,
iex(1)> lala = fn(msg) -> send self(), {:hello, msg} end
#Function<6.99386804/1 in :erl_eval.expr/5>
iex(2)> lala.("hehe")
{:hello, "hehe"}
iex(3)> lala.("hoho")
{:hello, "hoho"}
iex(4)> getst = fn() -> receive do {:hello, msg} -> "Got this #{inspect msg}" after 1_000 -> "Nothing after 1s" end end
#Function<20.99386804/0 in :erl_eval.expr/5>
iex(5)> getst.()
"Got this \"hehe\""