Skip to content

Instantly share code, notes, and snippets.

@nucleartide
nucleartide / index.js
Created June 27, 2017 19:04
Import node modules into an Ember app, with tree shaking
/**
* This is an example of importing https://github.com/component/color-picker
* into an Ember app. However, you can import any node module.
*
* Create an in-repo addon:
*
* $ ember g in-repo-addon rollup
*
* You should have a file `lib/rollup/index.js`.
* Replace the contents of that file with the stuff below.
@nucleartide
nucleartide / hamster.js
Last active May 23, 2017 15:43
Flow comment types
// @flow
/* ::
export type Hamster = {
age: number,
birthday: Date,
}
*/
@nucleartide
nucleartide / newton.go
Created November 20, 2016 02:32
Go loops and functions exercise
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 0;; i++ {
@nucleartide
nucleartide / select-group-choose.js
Created September 28, 2016 22:10
Choose a grouped option when testing ember-power-select dropdowns
import Ember from 'ember';
import run from 'ember-runloop';
/**
* Copied from https://github.com/cibernox/ember-power-select/blob/master/test-support/helpers/ember-power-select.js
*/
function fireNativeMouseEvent(eventType, selectorOrDomElement, options = {}) {
let event = new window.Event(eventType, { bubbles: true, cancelable: true, view: window });
Object.keys(options).forEach((key) => event[key] = options[key]);
let target;
@nucleartide
nucleartide / gist:e6cb30ee15419def07f8cb8516c545d1
Created September 22, 2016 17:42
Make gifs on Mac (from @Kitler on ember-community's slack)
# Prerequisits
* ffmpeg (brew install ffmpeg)
* imagemagick (brew install imagemagick)
# Steps
1. Use quicktime to capture your video and save it
2. `ffmpeg -i source.mov -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif`
@nucleartide
nucleartide / wrap_node_module.js
Last active August 10, 2016 21:50
Ember.js: wrap node modules without using ember-browserify
#!/bin/sh
#
# This script imports node modules into your app without the use of
# ember-browserify. To use,
#
# $ ./wrap_node_module.js
#
# (For the sake of an example, I use Lodash below.)
#
// seeing if github always returns a 409 conflict - seems like it does
// this is also a good way of teasing out github's error responses, which are undocumented (or i haven't browsed the docs carefully enough)
const co = require('co')
const request = require('superagent')
const sleep = require('co-sleep')
const btoa = require('btoa')
const token = process.env.TOKEN
@nucleartide
nucleartide / simulator.js
Last active August 10, 2016 17:27
Slots Data Tool Simulator (aka concurrent GitHub file updating)
const co = require('co')
const request = require('superagent')
const atob = require('atob')
const btoa = require('btoa')
const sleep = require('co-sleep')
const token = process.env.TOKEN
if (!token) throw new Error('need token')
@nucleartide
nucleartide / explicit.js
Last active March 25, 2019 15:08
Explicit Go-style error handling with ES6 destructuring. No more try-catch!
function explicit(ctx, fn) {
return function() {
try {
const result = fn.apply(ctx, arguments)
return [null, result]
} catch (err) {
return [err, null]
}
}
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
people: [
{
name: 'jason'
},
{