Skip to content

Instantly share code, notes, and snippets.

@kareniel
kareniel / debounce.js
Last active February 21, 2016 06:59
throttle function, that fires a message every 250ms by default (rather than at the end of a burst of events).
function throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) {
@kareniel
kareniel / deathBy_inception.js
Last active April 7, 2016 01:47
How to lose a value within a recursive function.
let tree = {
name: "A",
parent: {
name: "B",
parent: {
name: "C",
parent: {
name: ""
}
}
@kareniel
kareniel / remote.js
Created April 8, 2016 14:38
Calls a function based on the value it receives.
function remote(action) {
const actions = { open, close, reset }[action]()
function open() { console.log('opened') }
function close() { console.log('closed') }
function reset() { console.log('reset') }
}
remote('open') // 'opened'
@kareniel
kareniel / exportcsv.service.js
Created May 10, 2016 21:06
AngularJS service that takes a collection and returns a CSV file download
exportcsv.$inject = ['$sce']
function exportcsv($sce) {
const defaultOptions = {
filename: 'export'
}
return { toCSV }
export default function NgReduxStub() {
const ctrl = this
ctrl.selectedState = ""
ctrl.target = ""
ctrl.mapState = (state) => ({})
ctrl.push = (selectedState) => {
if (!isPlainObject(selectedState)) {
throw 'selectedState must be a plain object'
}
@kareniel
kareniel / resizable.js
Created October 28, 2016 20:57
Useful functions to create a resizable sidebar. Adapted from https://github.com/RickStrahl/jquery-resizable
// assumes the existence of a React component called `component`
const el = this.refs.sidebar.getDOMNode()
let startPos, startTransition
component.addEventListener('mousedown', startDragging)
component.addEventListener('touchstart', startDragging)
function getMousePosition (e) {
var pos = {
@kareniel
kareniel / selenium-webdriver-3.0.1.diff
Created November 13, 2016 17:53
diffs between versions 3.0.0-beta-3 & 3.0.1 of selenium-webdriver
diff --recursive --unified --exclude test --exclude Makefile 3.0.0-beta-3/CHANGES.md 3.0.1/CHANGES.md
--- 3.0.0-beta-3/CHANGES.md 2016-09-21 12:03:36.000000000 -0400
+++ 3.0.1/CHANGES.md 2016-11-08 17:27:02.000000000 -0500
@@ -1,3 +1,63 @@
+## v3.0.1
+
+* More API adjustments to align with native Promises
+ - Deprecated `promise.fulfilled(value)`, use `promise.Promise#resolve(value)`
+ - Deprecated `promise.rejected(reason)`, use `promise.Promise#reject(reason)`
+* When a `wait()` condition times out, the returned promise will now be
@kareniel
kareniel / bitbucket-ssh.md
Created July 26, 2017 19:49
make sure npm install works with private bitbucket repos as dependencies
  1. generate a public/private key pair in ~/.ssh/keys
  2. add the public key to your bitbucket account
  3. copy your private key to your user's home directory on your server scp -i "campsite-geo.pem" bitbucket_rsa USERNAME@REMOTE-IP:/home/USERNAME/.ssh/keys/bitbucket_rsa
  4. add bitbucket to your ssh config file printf "Host bitbucket.org\n User git\n IdentityFile ~/.ssh/keys/bitbucket_rsa" >> ~/.ssh/config
  5. make sure your .ssh folder has the right permissions chmod 700 ~/.ssh
  6. make sure your private key has the right permissions chmod 600 ~/.ssh/keys/bitbucket_rsa
@kareniel
kareniel / emitter.js
Created October 5, 2017 13:30
Minimal event emitter implementation
module.exports = Emitter
function Emitter () {
if (!(this instanceof Emitter)) return new Emitter()
this._listeners = {}
}
Emitter.prototype.emit = function (eventName, data) {
const listeners = this._listeners[eventName]
@kareniel
kareniel / index.js
Last active October 27, 2017 23:24
requirebin sketch
const html = require('choo/html')
const Nanocomponent = require('nanocomponent')
function CardForm () {
if (!(this instanceof CardForm)) return new CardForm()
this.error = ''
Nanocomponent.call(this)
}
CardForm.prototype = Object.create(Nanocomponent.prototype)