Skip to content

Instantly share code, notes, and snippets.

View karlpokus's full-sized avatar
💭
wohoo!

carl-fredrik grimberg karlpokus

💭
wohoo!
View GitHub Profile
@karlpokus
karlpokus / debounce.js
Created February 8, 2017 16:00
debounce in js
// from underscore.js
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// [wait] milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounceOG(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
@karlpokus
karlpokus / cloud9.md
Last active September 7, 2017 06:42
cloud 9 - free disk space from heroku cache

OUT OF DISK SPACE

It seems heroku caches lots of node modules in /home/ubuntu/.local/share/heroku/tmp. Just empty this dir and you'll be fine.

# in /home/ubuntu/.local/share/heroku
$ rm -rf tmp/*
# check
$ du -sh *
@karlpokus
karlpokus / gmail_shorts.md
Last active January 24, 2017 13:07
keyboard shortcuts in gmail - a selection
@karlpokus
karlpokus / fn.md
Created December 10, 2016 10:02
Functional programming in JS
@karlpokus
karlpokus / speed.md
Created December 8, 2016 14:09
Measure internet speed with node

Meaures from fast.com

$ npm i -g fast-cli
$ fast [> file]

Meaures from speedtest.net

@karlpokus
karlpokus / vue.md
Created December 8, 2016 10:20
vueJS for dummies

Remove item from list

<ul>
  <li v-for="(todo, index) in todos" v-on:click="remove(index)">
    {{ todo.text }}
  </li>
</ul>
var app = new Vue({
@karlpokus
karlpokus / indexoff.js
Last active November 29, 2016 12:12
implementation of indexof in js
Array.prototype.indexOff = function(x) {
if (this.length === 0) {
return -1
}
for (var i = 0; i < this.length; i++) {
if (this[i] === x) {
return i
}
}
return -1
@karlpokus
karlpokus / vim.md
Last active November 23, 2016 13:33
vim like a baos

the cli

# Open 1+ files
$ vim file
$ vim -p [file|*|*.md] [file]
# Pipe to vim
$ echo foo | vim -

the editor

@karlpokus
karlpokus / error.md
Created November 18, 2016 15:17
Proper error handling in node express

Proper error handling in node express

server

  • Place errorHandler after all routes and before .listen
  • Forget process.env.NODE_ENV
  • Use knas when raising errors if you need to produce http status codes
function errorHandler(err, req, res, next) {
  // err is either obj or string