Skip to content

Instantly share code, notes, and snippets.

@kareniel
kareniel / Mock.js
Created January 12, 2018 20:51
Current setup for testing Angular.js code
function Mock (modules = ['ng', 'ngMock', 'campsite-ui']) {
this.injector = window.angular.injector(modules)
}
Mock.prototype.init = function (done) {
this.injector.invoke(($componentController) => {
this.$componentController = $componentController
// this.$DEPENDENCY = this.injector.get('$DEPENDENCY')
@kareniel
kareniel / clean-wof-data-dir.js
Created January 9, 2018 18:57
remove invalid json files from a wof data directory
var fs = require('fs')
var path = require('path')
var recursive = require('recursive-readdir')
recursive(path.join(__dirname, 'data'), function (err, files) {
if (err) return console.error(err)
files.forEach(function (file) {
fs.readFile(file, function (err, data) {
if (err) return console.error(err)
try {
@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)
@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 / neon-demo_echo.md
Last active March 11, 2024 15:25
echo a string in neon (rust & node)

echo a string in neon (rust & node

starting from the hello_world demo:

  1. we are gonna need the to_string method. but items from traits can only be used if the trait is in scope so we need to add Value to our use statement.

use neon::js::JsString;

@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 / 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 / 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 = {
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 / 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 }