Skip to content

Instantly share code, notes, and snippets.

View jdalton's full-sized avatar

John-David Dalton jdalton

View GitHub Profile
@ralphholzmann
ralphholzmann / _with.js
Created April 25, 2012 19:35
JavaScript with-like function
var obj = {
"ralph" : 1,
"jon" : 2,
"alex" : 3
};
function _with( fn, data ) {
var keys = Object.keys( data ),
values = keys.map(function( key ) {
@paulmillr
paulmillr / active.md
Last active April 23, 2024 17:32
Most active GitHub users (by contributions). http://twitter.com/paulmillr

Most active GitHub users (git.io/top)

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Wed, 21 Sep 2022 till Thu, 21 Sep 2023.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
 .filter(user => user.followers > 1000)
@bobrik
bobrik / benchmark.js
Created July 11, 2012 10:12
lodash objectDifference implementation and benchmark code
(function(module) {
var Benchmark = require('../vendor/benchmark.js/benchmark.js'),
_ = require('../vendor/underscore/underscore.js'),
lodash = require('../lodash.js');
var numbers = [],
fourNumbers = [5, 25, 10, 30],
twoNumbers = [12, 21],
i;
@jameswomack
jameswomack / javascript_background_thread.js
Created September 11, 2012 06:41
Extend function prototype to run a function as a WebWorker
Function.prototype.runOnBackgroundThread = function (aCallback) {
var _blob = new Blob(['onmessage = '+this.toString()],{"type":"text/javascript"});
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob));
_worker.onmessage = aCallback;
_worker.postMessage();
}
var _test = function () {
postMessage((1+1).toString());
}
@junosuarez
junosuarez / top 1000
Created November 17, 2012 11:27
common english words which aren't npm modules yet
in
was
the
of
her
and
his
he
you
for
@WebReflection
WebReflection / inherit.js
Last active October 16, 2018 16:26
a meaningful shim limited to the first argument only of `Object.create()`, able to create empty dictionaries too such `inherit(null)` even in older browsers, down to IE5, without `__proto__` and/or without ES5 `Object.create()` support.
/*!(C) WebReflection *//** @license Mit Style */
// inspired by https://gist.github.com/4395291
this.inherit || (this.inherit = function(create){
if (!create) {
if ({__proto__:null} instanceof Object) {
for (var
Null = function Null() {},
doc = document,
html = doc.documentElement,
iframe = html.insertBefore(
@dherman
dherman / nans.js
Last active December 15, 2015 11:19
a NaN isn't a NaN isn't a NaN
function bufferBytes(buffer) {
return [].map.call(new Uint8Array(buffer), function(x) {return x})
}
function nanBytes(nan) {
var a = new Float64Array(1);
a[0] = nan;
return bufferBytes(a.buffer);
}
@henrahmagix
henrahmagix / map-with-filter-differences.js
Last active December 20, 2015 06:49
Difference in map between underscore/lodash and jQuery/Zepto.
// Difference in map between underscore/lodash and jQuery/Zepto.
//
// $ allows filtering at the same time; _ does not.
//
// In your client-side JavaScript apps that use _ and $, this can come as a
// surprise since the assumption is that all your map, each, filter, etc. needs
// are fulfilled by _, and you'd be right to use them for speed since they
// alias native methods where available. However, sometimes $ can be useful,
// and this is one such case where that's true.
//

RegExp.escape(string)

Computes a new version of a String value in which certain characters have been escaped, so that the regular expression engine will interpret any metacharacters that it may contain as character literals.

When the escape function is called with one argument string, the following steps are taken:

  1. Let string be ToString(string).
  2. ReturnIfAbrupt(string).
  3. Let length be the number of characters in string.
  4. Let R be the empty string.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Live demo of Nosy Facetype by Rory Harnden</title>
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono:400,400italic' rel='stylesheet' type='text/css'>
<style type="text/css">
@font-face {
font-family: "Nosy";
src: url(NOSY_Facetype_by_Rory_Harnden.otf) format("opentype");