Skip to content

Instantly share code, notes, and snippets.

View code-for-coffee's full-sized avatar

James code-for-coffee

  • Chicago, IL
View GitHub Profile
@dtipson
dtipson / workerFactory.js
Last active March 15, 2020 15:39
Template literals allow us to write string code suitable for workers. We can even import actual functions using toString. Blob urls allow us to turn all that content into a script for the worker to run, allowing us to create and run one with no external dependencies!
//actual function (must be a named function declaration for use w/ toString here)
function addOne(x){ return x+1 };
//the actual worker code can be written as a string
//template literals make that convienient because they support multiline
//note that the addOne function above can be used in this worker code, since we'll be importing it
const workerScript = `
self.addEventListener('message', function(e) {
var data = e.data;
console.log('worker recieved: ',data);
@Restuta
Restuta / the-bind-problem.jsx
Last active March 16, 2024 00:22
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));
@jayphelps
jayphelps / ofPropertyPathChanges.js
Last active June 15, 2021 18:09
RxJS observable of property value changes, given an object and property path
function isObject(value) {
// Avoid an old bug in Chrome 19-20
// See https://code.google.com/p/v8/issues/detail?id=2291
const type = typeof value;
return type === 'function' || (!!value && type === 'object');
}
function ofPropertyChanges(obj, key) {
if (isObject(obj) === false) {
return Rx.Observable.return(undefined);
@nbarraille
nbarraille / OrientationChangeAction.java
Last active January 30, 2023 00:04
An Espresso ViewAction that changes the orientation of the screen
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - Nathan Barraille
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@daniellevass
daniellevass / idiots-guide-to-littlebits-cloudbit-api.md
Last active May 22, 2018 19:48
Idiots Guide to Using littleBits cloudBit API

#Idiots Guide to Using littleBits cloudBit API

##Introduction

  1. Connect a cloudBit to your network using the instructions at http://control.littlebitscloud.cc/
  2. Find out your AccessToken
  • visit http://control.littlebitscloud.cc/
  • on the left hand side select any of your cloudBits
  • using the tab bar at the bottom select settings
  • scroll down and copy your AccessToken
@jpsullivan
jpsullivan / BundleConfig.cs
Created April 11, 2013 18:01
Precompile Handlebars templates using BundleTransformer
using System.Collections.Generic;
using System.Web.Optimization;
using BundleTransformer.Core.Orderers;
using BundleTransformer.Core.Transformers;
using BundleTransformer.Core.Translators;
using Ember;
namespace MyApp.App_Start
{
public class BundleConfig
@rweald
rweald / running-scalatra-on-heroku.md
Created December 14, 2012 02:34
Running Scalatra on Heroku

Instructions

###You will need to add the sbt-start-script plugin.

This plugin gives you a stage action which generates a script called target/start that can be used to run your application without pulling SBT into memory.

This can be accomplished by first adding the following line to project/plugins.sbt