Skip to content

Instantly share code, notes, and snippets.

View chilts's full-sized avatar

Andrew Chilton chilts

View GitHub Profile
@chilts
chilts / lock.js
Last active December 17, 2015 09:39
Lock API using Redis
var redis = require('redis');
var redlock = require('redlock');
var getLock2 = redlock({
client : client,
prefix : 'lock:', // optional
});
var getLock2 = redlock({
// same credentials as redis.createClient()
@chilts
chilts / speed-comparison.js
Created August 26, 2013 19:56
Gist to compare two ways of creating the string for flake (https://npmjs.org/package/flake) IDs. I suspect the construction of the array far outweighs the construction of the string.
var t1, t2, t3;
var i;
const TOP = 1000000000;
var tsHex = '013c798f75ad';
var counterHex = '0000';
var pidHex = '1154';
var macHex = '984be1b8b104';
t1 = Date.now();
@chilts
chilts / README.md
Last active December 26, 2015 23:19
Inconsistency in how whois.srs.net.nz works compared to whois.verisign-grs.com.

It seems that typing domain example.com means "give me this domain only", but just saying "example.com" is a query for things with example.com in them.

With the SRS, if I type nodejs.geek.nz it returns the details as though it is a domain command like above, but typing domain nodejs.geek.nz gives 500 Invalid characters in query string.

i.e. either it is not recognised as a valid command or a valid query.

(Note: I'm going off what I see, I'm not sure what it should actually do.)

Does that help?

@chilts
chilts / alexa.js
Created October 30, 2013 09:27
Getting the Alexa top 1 million sites directly from the server, unzipping it, parsing the csv and getting each line as an array.
var request = require('request');
var unzip = require('unzip');
var csv2 = require('csv2');
request.get('http://s3.amazonaws.com/alexa-static/top-1m.csv.zip')
.pipe(unzip.Parse())
.on('entry', function (entry) {
entry.pipe(csv2()).on('data', console.log);
})
;
@chilts
chilts / paramify.js
Created November 4, 2013 05:13
Alternative proposal ... not backwards compatible
var http = require('http')
var paramify = require('paramify')
var router = paramify()
router.get('intro/:greeting', intro)
router.get('showtimes/:start/:end', showtimes)
router.default(notFound);
http.createServer(router).listen(1337, '127.0.0.1')
@chilts
chilts / gist:7920015
Created December 11, 2013 22:54
Symmetrical comments
// I used to do this:
/*
*
* For long comments. This was in 1994.
*
*/
// Then I did this:
diff --git a/mailer.js b/mailer.js
index d5a46c6..5518639 100644
--- a/mailer.js
+++ b/mailer.js
@@ -67,6 +67,13 @@ module.exports = function (config, log) {
var p = P.defer()
var remaining = config.i18n.supportedLanguages.length * types.length;
+
+ function checkRemaining() {
@chilts
chilts / npm-ls-after-npm-dedupe.txt
Last active August 29, 2015 13:57
npm ls inside fxa-content-server
fxa-content-server@0.0.5 /home/chilts/src/chilts-fxa-content-server
├── abbrev@1.0.4
├─┬ argparse@0.1.15
│ ├── underscore@1.4.4
│ └── underscore.string@2.3.3
├── aws-sign@0.3.0
├── aws-sign2@0.5.0 extraneous
├── bluebird@1.0.7
├─┬ bower@1.2.8
│ ├── archy@0.0.2
return Client.create(config.publicUrl, 'a+b+c@example.com', pwd)
.then(
function (c) {
return c.destroyAccount()
},
function (err) {
t.equal(err.errno, 101, 'unusual email is not invalid')
}
)
test(
'/account/create with a variety of malformed email addresses',
function (t) {
var pwd = '123456'
// See: http://en.wikipedia.org/wiki/Email_address#Valid_email_addresses
var emails = [
'notAnEmailAddress',
'\n@example.com',
'me@hello world.com',