Skip to content

Instantly share code, notes, and snippets.

View kimmobrunfeldt's full-sized avatar

Kimmo Brunfeldt kimmobrunfeldt

View GitHub Profile
@kimmobrunfeldt
kimmobrunfeldt / index.html
Created November 29, 2014 12:01
Example of progressbar.js
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ProgressBar.js - Minimal Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.progress {
@kimmobrunfeldt
kimmobrunfeldt / install.md
Last active August 29, 2015 14:10
Parse HTML table

Install

  • Install http://nodejs.org/
  • Save parse-table.js to your Downloads folder
  • Open Terminal application
  • Enter command cd Downloads
  • Enter command node parse-table.js

Now output.csv is in your Downloads folder.

// Return operations to modify array a to b.
// e.g. var a = [{id:1}, {id:2}], b = [{id:2}]
// operations(a, b) -> [{operation: ‘remove’, item: {id:1}]
function operations(a, b) {
var aIds = _.pluck(a, 'id');
var bIds = _.pluck(b, 'id');
var notInBoth = _.xor(aIds, bIds);
return _.map(notInBoth, function(id) {
var isInA = _.contains(aIds, id);
@kimmobrunfeldt
kimmobrunfeldt / wrap.md
Created January 23, 2015 00:10
Space Tyckiting pre-problem summary

Space Tyckiting Sign Up Problem

For the Space Tyckiting event, students had to solve a small problem at the sign up. Bonus points were awarded for creativity.

If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
Your task is to **write a function** which finds the sum of all the
multiples of 3 or 5 below 1000.
@kimmobrunfeldt
kimmobrunfeldt / ga-error.js
Last active August 29, 2015 14:16
Google Analytics error reporting skeleton. NOTE THAT THIS DOES NOT WORK!!! This is just an example how to hook to window.onerror
function sendErrorToAnalytics(err) {
console.log('Sending error to analytics', err);
// WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Google analytics exception's exDescription max length is 150 bytes.
// USE ANOTHER EXCEPTION LOGGING SERVICE IF YOU NEED TO LOG E.G. STACKTRACES
ga('send', 'exception', {
exDescription: err.stack,
fatal: false
});
@kimmobrunfeldt
kimmobrunfeldt / prepare-null.js
Created March 6, 2015 09:01
Preparing for null..
// utils.jsx
// Returns wanted data or null. You can specify default value instead of null.
// Remember that arrays are actually objects so you can get index of array with
// 'arr.0'
// e.g get(object, 'data.results.0')
function get(obj, attributePath, defaultValue) {
var opts = _.extend({defaultValue: null}, {defaultValue: defaultValue});
if (!obj) {
@kimmobrunfeldt
kimmobrunfeldt / 0-looks-like-correct.js
Created March 12, 2015 19:31
One reason why !! is dangerous
// _.find returns undefined if nothing is found, otherwise returns the found item.
var existsOnCurrentPeriod = _.find(currentValues.operators, function(operatorId) {
return operatorId === operator.usbKeyId;
});
operator.existsOnPeriod = !!existsOnCurrentPeriod;
// This looks correct at first glance, but see below
@kimmobrunfeldt
kimmobrunfeldt / 0-links.md
Last active August 29, 2015 14:18
Suomen karttajärjestelmä