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 / react_readme.md
Last active May 3, 2017 17:03
react for dummies

react for dummies

  • docs
  • JSX produces React "elements" via React.createElement()
  • wrap JSX in parens to get multiple lines
  • element != component
  • ok to have multiple root nodes
  • React elements are immutable
  • components are like functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen.

Functional and Class Components

@karlpokus
karlpokus / upload_compat.js
Last active March 21, 2017 08:24
client file upload - closure and promises
// assume <input id="files" type="file" multiple/>
var files = document.getElementById('files');
files.addEventListener('change', processFiles, false);
function processFiles() {
readFiles(this.files, upload);
}
function readFiles(files, cb) {
var payloads = [];
@karlpokus
karlpokus / mysql.js
Last active March 2, 2017 10:11
mysql - api, node, security for dummies
// pkg: mysql
// https://github.com/mysqljs/mysql#performing-queries
var mysql = require('mysql'),
connection = mysql.createConnection({
host:'localhost',
user:'bixa',
password:'pwd',
database:'foo'
});
@karlpokus
karlpokus / bash_boss.sh
Last active February 20, 2017 16:41
bash like a baos!
# cd from ls
cd `ls | grep bengt`
# ls by mtime
ls -t
# page through a file
less filename
# processes
top
ps -aux
# write file
@karlpokus
karlpokus / headless_pi.md
Created February 10, 2017 15:30
Setup raspberry pi 3 in headless mode
@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 / unique.js
Last active January 31, 2017 09:57
Unique items in array. Return count or items.
// data is an array
function unique(data) {
return data.reduce(function(base, item){
if (base.indexOf(item) < 0 ) {
base.push(item);
}
return base
}, [])
}
@karlpokus
karlpokus / gmail_shorts.md
Last active January 24, 2017 13:07
keyboard shortcuts in gmail - a selection