Skip to content

Instantly share code, notes, and snippets.

@karlwestin
karlwestin / gist:3487951
Created August 27, 2012 12:17
Handlebars logging - tips for debugging templates!
/*
* Use this to turn on logging: (in your local extensions file)
*/
Handlebars.logger.log = function(level) {
if(level >= Handlebars.logger.level) {
console.log.apply(console, [].concat(["Handlebars: "], _.toArray(arguments)));
}
};
// DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3,
@karlwestin
karlwestin / gist:4051467
Created November 10, 2012 15:55
Make the AR Drone connect to a network
#telnet into the drone (telnet 192.168.1.1)
#paste the following command:
killall udhcpd; iwconfig ath0 mode managed essid [ssid]; ifconfig ath0 [wanted ip] netmask 255.255.255.0 up;
#ex. killall udhcpd; iwconfig ath0 mode managed essid Roflcopter; ifconfig ath0 192.168.43.201 netmask 255.255.255.0 up;
@karlwestin
karlwestin / .gitconfig
Created May 23, 2011 13:34
Make git diff ignore whitespace and don't try to open jpgs and shit
# this can be put in [repo]/.git/config for local settings
# or ~/.gitconfig for global settings
# create a difftool "nodiff" that just returns true
# this path is for Mac. On linux it's /bin/true i guess
[diff "nodiff"]
command = /usr/bin/true
# make git ignore white space differences, many different possibilites here
@karlwestin
karlwestin / README.md
Last active April 22, 2019 08:07
Redux Stopwatch Example

Redux Stopwatch Example

Just an idea, to practice after reading about redux async actions and middleware

the important part is this function

let INTERVAL = 50
let runTimer = () => {
 return (dispatch, getState) => {
@karlwestin
karlwestin / gist:3163157
Created July 23, 2012 11:24
throttling a window.scroll handler for better performance
// underscore's throttle-metod
var throttle = function(func, wait) {
var context, args, timeout, throttling, more, result;
var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
return function() {
context = this; args = arguments;
var later = function() {
timeout = null;
if (more) func.apply(context, args);
@karlwestin
karlwestin / README.md
Created August 30, 2018 09:08
How does PouchDB choose adapter?

How does PouchDB choose adapter:

Source is in pouchdb-core

is it http or https? - use these adapters

is it not? - pick the first one in the list of 'preferred adapters'

@karlwestin
karlwestin / config.js
Created March 13, 2018 11:50
config without higher order function
const common = {}
let config = {}
export function setup = url => {
van: {
...common,
remoteDbUrl: process.env.REACT_APP_VAN_COUCHDB_URL || 'http://localhost:5984/',
dateFormats: {
long: 'D MMM, YYYY',
week: 'YYYY-[W]WW'
@karlwestin
karlwestin / gist:2393106
Created April 15, 2012 14:22
Nested models/collections and storage with Backbone.js and Backbone.LocalStorage
/*
* Example of using nested collections/models with backbone.js and backbone.js localStorage
*
* Read the complete blog post at karlwestin.posterous.com
*
* 1. run populate() from command line first time
* 2. reload the page (or open in another browser tab), and check the following:
*
* premier.at(0).get("name") => "Tottenham"
* premier.at(0).players.length => 3
@karlwestin
karlwestin / index.html
Created May 18, 2013 14:51
Example of using pubsub for communication between Polymer.js widgets. The purpose of this is not to demonstrate pubsub, but to show how to easily blend 'normal' javascript with Polymer components.
<!DOCTYPE html>
<html>
<head>
<title>Polymer</title>
<meta charset="utf-8" />
<script type="text/javascript" charset="utf-8" src="pubsub.js"> </script>
<script type="text/javascript" charset="utf-8" src="polymer/polymer.js"> </script>
<link rel="import" href="publisher.html">
<link rel="import" href="subscriber.html">
</head>
@karlwestin
karlwestin / test.js
Created December 12, 2013 11:05
Nice javascript unit testing (jasmine) trick: which spec takes the most time?
describe("test suite that you wanna perf", function() {
beforeEach(function() {
this.start = performance.now();
});
afterEach(function() {
console.log(jasmine.getEnv().currentSpec.description, performance.now() - this.start);
});
});