Skip to content

Instantly share code, notes, and snippets.

@PaulKinlan
PaulKinlan / range.js
Last active August 2, 2017 23:30
range.js
const range = function* (stop = 0, step = 1) {
const shouldStop = (n)=>stop >= 0 ? (n < stop) : (n > stop);
const interval = (n)=>stop >= 0 ? n + step : n - step;
let itr = function*() {
let i = 0;
while (shouldStop(i)) {
yield i;
i = interval(i);
}
};
@adactio
adactio / basicServiceWorker.js
Last active March 27, 2023 09:30
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
@max-mapper
max-mapper / test.js
Last active August 29, 2015 14:24
tape + http local server test scaffolding
// the two testing modules I like
var test = require('tape')
var spawn = require('tape-spawn')
var execspawn = require('npm-execspawn') // can spawn from require() scope, check it out!
// put this in outer scope so we can kill the local server at the end
var server
test('start test server', function (t) {
@kosamari
kosamari / _.R.js
Last active December 7, 2018 11:12
Underscore mixin to enable core R functions
_.mixin({
sum : function(data){
return _.reduce(data, function(memo, num){ return memo + num; }, 0);
},
mean : function(data){
return this.sum(data)/data.length
},
median : function(data){
return this.percentile(data,50);
},
@mathisonian
mathisonian / index.md
Last active March 22, 2023 05:31
requiring npm modules in the browser console

demo gif

The final result: require() any module on npm in your browser console with browserify

This article is written to explain how the above gif works in the chrome (and other) browser consoles. A quick disclaimer: this whole thing is a huge hack, it shouldn't be used for anything seriously, and there are probably much better ways of accomplishing the same.

Update: There are much better ways of accomplishing the same, and the script has been updated to use a much simpler method pulling directly from browserify-cdn. See this thread for details: mathisonian/requirify#5

inspiration

@mgreensmith
mgreensmith / Slack_solarized_themes
Last active May 2, 2024 18:14
Solarized themes for Slack
Solarized
#FDF6E3,#EEE8D5,#93A1A1,#FDF6E3,#EEE8D5,#657B83,#2AA198,#DC322F
Solarized Dark
#073642,#002B36,#B58900,#FDF6E3,#CB4B16,#FDF6E3,#2AA198,#DC322F
@mikepack
mikepack / setup_component.coffee
Created February 28, 2014 16:38
Ember Component Test Helper
AppTest.setupComponent = (name, content, options, setupCallback=null)->
beforeEach ->
Ember.$('<div id="test-container"><div id="test"></div></div>').appendTo('body');
Ember.run ->
AppTest.App = Ember.Application.create
rootElement: '#test'
// DISCLAIMER: This is not necessarily good code. It’s just code that I wrote
// as quickly as possible to do each task.
// 1
return 2*i;
// 2
return !(i%2);
@Olical
Olical / map.js
Created June 11, 2013 19:42
A JavaScript map implementation. Will be on my blog soon: http://oli.me.uk/
/**
* A simple map implementation. Uses two arrays to store the keys and values as well as indexOf to search through them.
*
* You could swap indexOf for a binary search if you need more speed: http://oli.me.uk/2013/06/08/searching-javascript-arrays-with-a-binary-search/
*
* @class
*/
function Map() {
this._createStorage();
}
@mattsacks
mattsacks / preventHistorySwipe.js
Created May 22, 2013 22:46
Prevent back/forward gestures when scrolling an element left/right on OS X
// prevent back/forward gestures when scrolling an element left/right on OS X
var preventHistorySwipe = function(element) {
// not even on the right platform bro
if (navigator.userAgent.indexOf('Macintosh') === -1) return;
element.addEventListener('mousewheel', function(e) {
var x = e.wheelDeltaX;
// scrolling up or down? then i don't give a shit
if (x === 0) return;