Skip to content

Instantly share code, notes, and snippets.

View nzakas's full-sized avatar
💭
GitHub time is limited currently. Please be patient.

Nicholas C. Zakas nzakas

💭
GitHub time is limited currently. Please be patient.
View GitHub Profile
@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 npm@1.3.5
3 info using node@v0.10.15
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) {
@nzakas
nzakas / contest.js
Created November 23, 2012 22:21
Contest
/*
* Contest to win one of my books. If you're in the United States, you can choose either
* Professional JavaScript for Web Developers or Maintainable JavaScript and I will send
* you a signed copy. If you're outside the United States, I will send you the PDF version
* of either book. Good luck!
*
* Rules
* 1. Assume this is the only code! Don't worry about real world situations.
* 2. You can use anything defined in ECMAScript 5 to solve the problem (no DOM, BOM, etc.)
* 3. There is more than one correct answer but only the first correct answer wins.
@nzakas
nzakas / replace-apache.sh
Created September 14, 2012 00:17
Replace Apache with nginx on Elastic Beanstalk AMI (Tomcat7/32-bit)
#!/bin/sh
# IMPORTANT: Run this script as sudo or else it won't work
# Original script: http://my.safaribooksonline.com/book/programming/java/9781449309558/hacking-elastic-beanstalk/hackingelectric#X2ludGVybmFsX0ZsYXNoUmVhZGVyP3htbGlkPTk3ODE0NDkzMDk1NTgvSV9zZWN0MTRfZDFlMjAyNQ==
echo 'Installing nginx...sit tight'
yum -y install nginx
echo 'Fixing nginx configuration'
sed -i 's/ 1;/ 4;/g' /etc/nginx/nginx.conf
rm /etc/nginx/conf.d/default.conf
@nzakas
nzakas / spawn.js
Created August 24, 2012 23:56
Devil spawn
#!/usr/bin/env node
var child = require('child_process');
var cp = child.spawn("dir", [""]);
cp.stdout.on("data", function(data) {
console.log(data.toString());
});
cp.stderr.on("data", function(data) {
console.error(data.toString());