Skip to content

Instantly share code, notes, and snippets.

View kimmobrunfeldt's full-sized avatar

Kimmo Brunfeldt kimmobrunfeldt

View GitHub Profile
@kimmobrunfeldt
kimmobrunfeldt / postgres.md
Last active April 18, 2017 08:04
Postgres tips
<Song tempo={90}>
<Sequencer resolution={16} bars={1}>
<Reverb>
<Delay>
<Monosynth
steps={[
[0, 4, "c3"],
[4, 4, "c4"],
]}
/>
@kimmobrunfeldt
kimmobrunfeldt / react-router.jsx
Created December 25, 2016 00:05
Example of react-router configuration
<Router history={browserHistory}>
<Route path=”/” component={App}>
<Route path=”users” component={Users}>
<Route path=”/user/:userId” component={User}/>
</Route>
<Route path=”*” component={NoMatch}/>
</Route>
</Router>
@kimmobrunfeldt
kimmobrunfeldt / react-router.jsx
Last active December 25, 2016 00:09
Example of how react-router configuration could look like as a JS object
const routes = [
{ path: '/', component: App },
{ path: '/users/', component: UserList },
{ path: '/users/:userId', component: User },
{ path: '*', component: Default },
];
<Router history={browserHistory} routes={routes} />
@kimmobrunfeldt
kimmobrunfeldt / cpu-profile-trigger.js
Last active October 26, 2016 21:07
Helper to record node CPU profiles, which can be easily viewed as CPU flame graphs using Chrome debugger
// Helper to record CPU profiles
// https://github.com/node-inspector/v8-profiler#cpu-profile-api
//
// Usage:
// 1. npm install v8-profiler
// 2. require('./cpu-profile-trigger') once in your app code
// 3. Start CPU profiling with kill -PIPE <pid>. Instructions will be logged to stdout.
// 4. Stop CPU profiling with running again kill -PIPE <pid>
// 5. Go to Chrome debugger, open Profiles tab. Click Load and
// open the <timestamp>.cpuprofile. It was saved to the same dir
@kimmobrunfeldt
kimmobrunfeldt / hapi-for-express-devs.md
Last active July 6, 2016 13:21
Hapi for Express developers
@kimmobrunfeldt
kimmobrunfeldt / salausfunktio.py
Created June 19, 2016 20:53
Älä koskaan kirjota omaa cryptoa.. paitsi ekan kerran
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import random
from math import floor
kirjaimet = {u' ': u'00', u'!': u'01', u'"': u'02', u'#': u'03', u'$': u'04', u'%': u'05', u'&': u'06', u'\'': u'07', u'(': u'08', u')': u'09', u'*': u'10', u'+': u'11', u',': u'12', u'-': u'13', u'.': u'14', u'/': u'15', u'0': u'16', u'1': u'17', u'2': u'18', u'3': u'19', u'4': u'20', u'5': u'21', u'6': u'22', u'7': u'23', u'8': u'24', u'9': u'25', u':': u'26', u';': u'27', u'<': u'28', u'=': u'29', u'>': u'30', u'?': u'31', u'@': u'32', u'A': u'33', u'B': u'34', u'C': u'35', u'D': u'36', u'E': u'37', u'F': u'38', u'G': u'39', u'H': u'40', u'I': u'41', u'J': u'42', u'K': u'43', u'L': u'44', u'M': u'45', u'N': u'46', u'O': u'47', u'P': u'48', u'Q': u'49', u'R': u'50', u'S': u'51', u'T': u'52', u'U': u'53', u'V': u'54', u'W': u'55', u'X': u'56', u'Y': u'57', u'Z': u'58', u'[': u'59', u'\\': u'60', u']': u'61', u'^': u'62', u'_': u'63', u'`': u'64', u'a': u'65', u'b': u'66', u'c': u'67', u'd': u'68', u'e': u'69', u'f': u'70', u'g':
@kimmobrunfeldt
kimmobrunfeldt / Matikka ohjelma.py
Last active June 19, 2016 20:55
One of my earliest experiences with coding in 2007 (In Finnish)
print "Matikka ohjelma"
print "-----------------------"
print
print "Valitse vaihtoehto:"
print "1 Simppelit laskut"
print "2 Pinta-alat ja tilavuudet"
print "3 Muita laskuja"
ehto = input("> ")
@kimmobrunfeldt
kimmobrunfeldt / monkey-patch-console.js
Created April 4, 2016 11:16
Monkey patching console log
console.warn('- console.(debug|info|log|warn|error) monkey-patched');
const methods = ['debug', 'info', 'log', 'warn', 'error'];
// We have to take the direct references to the actual function like this
// instead of doing just: originalConsole = console
const originalConsole = _.reduce(methods, (memo, methodName) => {
memo[methodName] = _.bind(console[methodName], console);
return memo;
}, {});
@kimmobrunfeldt
kimmobrunfeldt / unique-generator.js
Created February 29, 2016 21:02
Small example of a generator
function* uniqueId() {
var i = 0;
while (true) {
yield i;
++i;
}
}
var idGenerator = uniqueId();