Skip to content

Instantly share code, notes, and snippets.

View kpuputti's full-sized avatar

Kimmo Puputti kpuputti

View GitHub Profile
@jevakallio
jevakallio / reactiveconf-slam-poetry.md
Last active July 7, 2021 19:57
#ReactiveConf 2017 Lightning Talk Submission: JavaScript Slam Poetry

TL;DR: If you want to see me perform a spoken word poem about JavaScript in front of 1000 people (and on video), please ⭐ star this gist. If you're on mobile, you'll need to request desktop site.

JavaScript Slam Poetry

Javascript! Slam! Poetry!

const t = require("tcomb");
// imstruct is a tcomb type builder that internally builds an
// Immutable.Record object, but applies tcomb's type system to it
const imstruct = require("../util/imstruct");
const Person = imstruct({
name: t.String,
age: t.Number
});
@paulirish
paulirish / what-forces-layout.md
Last active September 19, 2024 22:56
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@pyrtsa
pyrtsa / ntuples.js
Created April 29, 2013 07:16
Split a sequence into groups of `n` consecutive elements each, with 1..n items in the last group.
function range(n) {
return Array.apply(null, Array(n)).map(function (_, i) { return i })
}
function ntuples(n, xs) {
return range(Math.ceil(xs.length / n)).map(function (i) {
return xs.slice(i * n, i * n + n)
})
}
function range(/* [begin,] end[, step] */) {
var begin = arguments.length > 1 ? arguments[0] : 0,
end = arguments.length > 1 ? arguments[1] : arguments[0],
step = arguments[2] || 1,
n = Math.max(0, Math.ceil((end - begin) / step))
return Array.apply(null, Array(n)).map(function (_, i) {
return begin + step * i
})
}
@pyrtsa
pyrtsa / get_at_it.js
Last active December 11, 2015 06:08
Get at it!
// Public domain.
// Attribution welcome, but not required. -- Pyry Jahkola.
// What's the point in all this? To get the equivalent of CoffeeScript's
// (?.) operator into vanilla JavaScript.
// get(x, key1, key2, ...) -- Get the result of x[key1][key2]..., or undefined.
// Will short circuit if a key is not found.
@gcatlin
gcatlin / gist:1847248
Created February 16, 2012 19:43
Install specific version of Homebrew formula
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@scottjehl
scottjehl / hideaddrbar.js
Created August 31, 2011 11:42
Normalized hide address bar for iOS & Android
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){
@akheron
akheron / gist:827408
Created February 15, 2011 11:12
Unit test helper for diffing Python data structures
def eq_diff(a, b):
import json, difflib
from datetime import datetime
if a == b:
return
class DatetimeEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
@gnomet
gnomet / Sharetribe DB installation
Created January 31, 2011 16:32
Running these commands in MySQL will create three databases where the user "sharetribe" has access. DON'T FORGET TO CHANGE ALL THE put_a_password_here PARTS TO A SECURE PASSWORD!
CREATE DATABASE sharetribe_test CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE sharetribe_development CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE sharetribe_production CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT all privileges ON sharetribe_development.* TO 'sharetribe'@'localhost' IDENTIFIED BY 'put_a_password_here';
GRANT all privileges ON sharetribe_production.* TO 'sharetribe'@'localhost' IDENTIFIED BY 'put_a_password_here';
GRANT all privileges ON sharetribe_test.* TO 'sharetribe'@'localhost' IDENTIFIED BY 'put_a_password_here';