Skip to content

Instantly share code, notes, and snippets.

@esmevane
esmevane / dreamcode.ts
Created August 15, 2017 11:26
[ Typescript / Javascript / Chai / Draftjs ]: Wouldn't it be nice if there were Draft.js chai helpers?
import chai, { expect } from 'chai'
import { EditorState } from 'draft-js'
expect(editorState).to.have.content(contentState)
expect(contentState).to.eql.content(otherState)
expect(editorState).to.have.block(contentBlock)
@esmevane
esmevane / HasStylesheet.elm
Last active July 28, 2017 13:10
[ Elm / Stylesheets / Interop ]: Use Elm & Javascript interop to allow for CSS modules in Elm files
module HasStylesheet exposing (..)
import Html exposing (Html, div, text)
import Html.Attributes exposing (class)
import Stylesheets exposing (fetchClasses, getClass, onlyFor)
type Message
= NoOp
| ReceiveStyles Stylesheets.Message
@esmevane
esmevane / elm-react.tsx
Created December 20, 2016 15:30
[ Typescript / React ]: Recreating the elm architecture
import * as React from "react";
import { Component } from "react";
const styles: any = require("./styles.module.css");
type None = "None";
type Increment = "Increment";
type Decrement = "Decrement";
type Message = None | Increment | Decrement;
type Model = { total: number };
@esmevane
esmevane / gamasutra.css
Created October 20, 2016 21:34
The 12pt font is awful, Gamasutra
body {
font-size: 1em;
line-height: 1.6em;
}
.span-16 { width: 83% }
.span-20 { width: 100% }
@esmevane
esmevane / simple.js
Created April 2, 2016 17:30
[ Generators / Promises / Javascript / ES6 ]: Running generators synchronously in JS
function run(generator) {
let progress = generator()
let step = progress.next()
const iterate = (progress, { done, value }) => {
const isArrayValue = Array.isArray(value)
const invoke = (value) => {
let complete = new Promise(resolve => {
iterate(progress, progress.next(value)).then(resolve)
})
@esmevane
esmevane / robin-ignore.js
Created April 1, 2016 18:55
[ Robin / Javascript ]: Ignore annoying Robin users
var ignoreList = {};
function remove(username) {
var slice = Array.prototype.slice;
var messages = slice.call(document.querySelectorAll('.robin-message'));
messages.forEach(function(message) {
var messageFrom = message.querySelector('.robin-message--from');
if (messageFrom) {
@esmevane
esmevane / generator-flow-control.js
Created March 11, 2016 21:34
[ Javascript / ES6 / Generators / Promises ]: Create a method to implement async flow control with ES6 generators
import EventEmitter from 'events'
class GeneratorEngine {
constructor({ controller }) { this.controller = controller }
iterate(progress, step) {
if (step.done) { return step.value }
this.route(step.value, result => {
this.iterate(progress, progress.next(result))
@esmevane
esmevane / playlist-recover-all.js
Created January 30, 2016 22:09
[ Javascript / jQuery / Spotify ]: If you ever get hacked and need to restore a ton of playlists, use this snippet
var list = $('.playlist-restore button').toArray();
list.forEach(function(item) {
var index = list.indexOf(item);
var timeout = index * 1000;
var click = function() { item.click() };
setTimeout(click, timeout)
});
@esmevane
esmevane / async.es6
Created January 29, 2016 19:13
[ ES6 / Babel / ES2016 ]: Adapted version of async / await example from twilio
// Adapted from: https://www.twilio.com/blog/2015/10/asyncawait-the-hero-javascript-deserved.html
//
import Request from 'request'
function getQuote() {
let path = 'http://ron-swanson-quotes.herokuapp.com/quotes'
let request = (resolve, reject) =>
Request(path, (e, r, body) =>
resolve(JSON.parse(body).quote))
@esmevane
esmevane / README.md
Last active December 29, 2015 15:56
[ Ruby / Rake ]: Spec shame yourself.

Spec shame

Because you spiked out your entire gem or Rails app without bothering to write a single spec. Then you wanted to see your test coverage to get rolling on it, so you install simplecov and it said you had 95%! But of course, that's a lie. It just has no idea you have so many vacant specs.

Usage: time to shame yourself

Just require this file in your Rakefile, like so:

require File.join(__dir__, 'tasks/spec_shame.rb')