Skip to content

Instantly share code, notes, and snippets.

View rikukissa's full-sized avatar
🍔

Riku Rouvila rikukissa

🍔
View GitHub Profile
@rikukissa
rikukissa / gist:6061635
Last active December 20, 2015 03:09
Object recursion, requires underscore.js
var walk = function(obj, iterator) {
for(i in obj) {
if(_.isObject(obj[i]) && !_.isArray(obj[i]) && !_.isFunction(obj[i])) {
walk(obj[i], iterator);
continue;
}
iterator(obj[i]);
}
};
core]
quotepath = false
whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
[color]
ui = true
[color "branch"]
current = yellow black
local = yellow
@rikukissa
rikukissa / gist:6744023
Created September 28, 2013 16:52
domo-weather
domo.route('!weather :city', function(res) {
var response = request.get('http://api.openweathermap.org/data/2.5/weather?q=' + res.params.city + ',FI&units=metric&lang=fi', function (error, response, body) {
if (error || response.statusCode !== 200) return;
var data = JSON.parse(body);
var saa = data.main.temp;
this.say(res.channel, 'Sää ' + res.params.city + ': ' + saa);
class Base
constructor: ->
on: ->
console.log 'base:on', arguments
class Child extends Base
constructor: ->
on: ->
console.log 'child:on', arguments
super
# -*- coding: utf-8 -*-
import sublime, sublime_plugin, json, codecs
class I18nCommand(sublime_plugin.TextCommand):
settings = sublime.load_settings('i18nHelper')
last_path = settings.get('default_path', '')
last_key = settings.get('default_chain', '')
def run(self, edit):
@rikukissa
rikukissa / gist:7842890
Created December 7, 2013 14:30
Wraps promise so that it's not called again until it's resolved
throttleWrapper = (promiseTarget, args...) ->
isLoading = false
promiseToServe = null
return ->
return promiseToServe if isLoading
isLoading = true
promiseToServe = promiseTarget.apply promiseTarget, args...
promiseToServe.then (promiseResolved) ->
fs = require 'fs'
es = require 'event-stream'
Transform = require('stream').Transform
PassThrough = require('stream').PassThrough
reverser = new Transform
reverser._transform = (data, encoding, done) ->
this.push data.toString().split('').reverse().join ''
done()
@rikukissa
rikukissa / myController.js
Last active August 29, 2015 13:56
Example "Collection" implementation for angularFire
function MyController($scope, $firebaseCollection) {
// "images" - contains for example >10 000 children and we don't want to fetch them all at once
var imagesRef = new Firebase("https://<my-firebase>.firebaseio.com/images");
// Creates an empty collection for images
// Collection should now track changes in imagesRef.
// Example methods:
// $push( snapshot ) - Push new children to collection
$scope.images = $firebaseCollection(imagesRef);
form(data-bind='submit: loadFoobar')
button(type='submit', data-bind='css: { loading: loadFoobar.loading }')
phoneBook =
[("betty","555-2938")
,("bonnie","452-2928")
,("patsy","493-2928")
,("lucille","205-2928")
,("wendy","939-8282")
,("penny","853-2492")
]
getNumberByName :: (Eq a) => a -> [(a, c)] -> Maybe c