Skip to content

Instantly share code, notes, and snippets.

View nzakas's full-sized avatar

Nicholas C. Zakas nzakas

View GitHub Profile
@nzakas
nzakas / simplemap.js
Created April 3, 2014 17:38
A simple map implementation for JavaScript (not intended to be an ES6 polyfill)
function SimpleMap() {
this._data = {};
}
SimpleMap.prototype = {
get: function(key) {
return this.has(key) ? this._data[key] : null;
},
@nzakas
nzakas / codepoints.js
Created March 9, 2014 01:17
Will this do what it claims to do in ES6?
// will this work for getting the number of code points in an ES6 string?
function codePointLength(text) {
var result = text.match(/./gu);
return result ? result.length : 0;
}
console.log(codePointLength("abc")); // 3
console.log(codePointLength("𠮷bc")); // 3
@nzakas
nzakas / pull_request.json
Last active August 29, 2015 13:57
GitHub WebHook Payloads
{
"action": "opened",
"number": 3,
"pull_request": {
"url": "https://api.github.com/repos/nzakas/APITest/pulls/3",
"id": 13182048,
"html_url": "https://github.com/nzakas/APITest/pull/3",
"diff_url": "https://github.com/nzakas/APITest/pull/3.diff",
"patch_url": "https://github.com/nzakas/APITest/pull/3.patch",
"issue_url": "https://api.github.com/repos/nzakas/APITest/issues/3",
@nzakas
nzakas / chrome_output.txt
Created February 27, 2014 19:13
Is this a Node.js bug?
value1: {"stack":"MyStack","type":"MyType"} true
value2: {"stack":"MyStack","message":"MyError"} true
value3: {"stack":"MyStack","message":"MyError"} true
value4: {"stack":"MyStack","type":"MyType"} true
@nzakas
nzakas / npm-debug.log
Created February 27, 2014 17:30
npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'c:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'publish' ]
2 info using [email protected]
3 info using [email protected]
4 verbose publish [ '.' ]
5 verbose cache add [ '.', null ]
6 verbose cache add name=undefined spec="." args=[".",null]
7 verbose parsed url { protocol: null,
@nzakas
nzakas / gist:8757103
Created February 1, 2014 19:14
ESLint V8 profile
Code move event for unknown code: 0xf0043840
Code move event for unknown code: 0xf02402e0
Code move event for unknown code: 0xf035af60
Code move event for unknown code: 0xf045ce00
Statistical profiling result from v8.log, (5296 ticks, 3426 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
3426 64.7%
@nzakas
nzakas / versioning.md
Created November 24, 2013 23:01
Versioning in a repo

Versioning in a Repository

Lately I've been doing a lot of thinking around versioning in repositories. For all the convenience and ubiquity of package.json, it does sometimes misrepresent the code that is contained within a repository. For example, suppose I start out my project at v0.1.0 and that's what's in my package.json file in my master branch. Then someone submits a pull request that I merge in - the version number hasn't changed even though the repository now no longer represents v0.1.0. The repository is actually now in an intermediate state, in between v0.1.0 and the next official release.

To deal with that, I started changing the package.json version only long enough to push a new release, and then I would change it to a dev version representing the next scheduled release (such as v0.2.0-dev). That solved the problem of misrepresenting the version number of the repository (provided people realize "dev" means "in flux day to day"). However, it introduced a yucky workflow that I really hate

@nzakas
nzakas / gist:7015508
Created October 16, 2013 21:48
Async event emitter

What I'm considering for an async event emitter is a situation like this:

  1. I want to be able to fire events before something happens and after something happens.
  2. Each of the event handlers may do an async process.
  3. I need to know after all of the "before" event handlers have completed before doing the actual action that I'm saying will happen.

A synchronous example would look like:

emitter.emit('beforewrite');
@nzakas
nzakas / gist:5511916
Created May 3, 2013 17:47
Using GitHub inside a company

I'm doing some research on how companies use GitHub Enterprise (or public GitHub) internally. If you can help out by answering a few questions, I'd greatly appreciate it.

  1. What is the primary setup? Is there an organization and each official repo is owned by that organization?
  2. Does every engineer have a fork of each repo they're working on?
  3. Are engineers allowed to push directly to the official repo? Or must all commits go through a pull request?
  4. Do engineers work on feature branches on the main repo or on their own forks?
  5. Do you require engineers to squash commits and rebase before merging?
  6. Overall, what is the workflow for getting a new commit into the main repository?
  7. What sort of hooks do you make use of?
  8. Are there any ops issues you encountered? (Scaling, unforeseen downtime, etc.)
@nzakas
nzakas / type-declarations.js
Created December 14, 2012 22:27
Experiment: Simple way to define types, including prototypal inheritance, in JavaScript
/*
* This is just an experiment. Don't read too much into the fact that these are global variables.
* The basic idea is to combine the two steps of defining a constructor and modifying a prototype
* into just one function call that looks more like traditional classes and other OO languages.
*/
// Utility function
function mixin(receiver, supplier) {
if (Object.getOwnPropertyDescriptor) {