Skip to content

Instantly share code, notes, and snippets.

View mattbasta's full-sized avatar
🌭
Still writing JavaScript

Matt Basta mattbasta

🌭
Still writing JavaScript
View GitHub Profile
.diff-line.line {
position: relative;
}
.diff-line:not(.gc).line::before {
-webkit-user-select:none;
pointer-events:none;
left: 10px;
color: transparent;
content: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
border-right: 1px dotted rgba(0, 0, 0, 0.5);
import hashlib
import hmac
import json
import urllib
import urllib2
import uuid
SECRET = "This is a value which should be unique to the service."

Avoid code duplication and reusing code is always an admirable goal. However, in some occasions, it's not a bad idea to duplicate a little bit of code in order to make your software better.

An Example

When writing a Node app, accessing a directory listing is fairly simple: the fs.readdir command provides a list of objects in a directory, and a call to fs.stat will tell you whether each object is a directory or a file.

That's fairly straightforward, but recursing (especially when using callbacks) can require some mental yoga. Each directory needs to keep track of how many subdirectories it expects to receive callbacks for and results need to be aggregated in pieces rather than sequentially.

When I needed a recursive directory listing this past week, I was tempted to use a library: why solve a solved problem? The glob library provides this functionality with very little effort:

@mattbasta
mattbasta / rainbow.js
Last active December 14, 2015 18:39 — forked from anonymous/rainbow.js
/*
Original graphicsbc source:
a0,0
p250,300
t20,0
L
10
Ha0 ,255,128
@mattbasta
mattbasta / strings.po
Last active December 15, 2015 02:49
Strings for Fireplace
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-03-27T20:42:19.302Z\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
var mockobj = mock({
utils: function() {
return { ... };
}
});
mockobj(['foomodule'], function(foomodule) {
test('foomodule', function(done) {
foomodule.should_not_explode();
done();
mock(function(patch) {
patch('utils', function() {
return { ... };
});
}, function() {
var foomodule = require('foomodule');
test('foomodule', function(done) {
foomodule.should_not_explode();
done();
mock({
utils: function() {
return { ... };
}
}, function() {
var foomodule = require('foomodule');
test('foomodule', function(done) {
foomodule.should_not_explode();
done();
$.fn.serializeObject = function() {
var data = {};
_.each($(this).serializeArray(), function(v, k) {
k = v.name;
v = v.value;
if (_.contains(k, '__prefix__')) {
return;
}
if (k.match(/\-\d+\-/g)) {
// Turn `users-0-name=Basta` into
#!/bin/bash
# Which version should we fetch?
b2gremote="https://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/"
appname="B2G"
if [ "$1" == "aurora" ]; then
b2gremote="https://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-aurora/"
appname="B2GAurora"
fi