Skip to content

Instantly share code, notes, and snippets.

View domenic's full-sized avatar

Domenic Denicola domenic

View GitHub Profile
@domenic
domenic / pseudo-elements-and-me.css
Created May 31, 2012 05:56
I am the master of psuedo elements!!
footer, footer::before, footer::after {
height: 342px;
}
footer {
background-image: url(../images/footer-center.png);
background-position: center top;
background-repeat: no-repeat;
bottom: 0;
left: 0;
@domenic
domenic / ee-to-promises.js
Created June 2, 2012 05:22
Event Emitters -> Promises
"use strict";
var Q = require("q");
module.exports = function fromEventEmitter(ee) {
var deferred = Q.defer();
ee.on("success", deferred.resolve);
ee.on("error", deferred.reject);
return deferred.promise;
@domenic
domenic / oauth2-restify.js
Created June 2, 2012 06:25
OAuth2 with Restify
"use strict";
var restify = require("restify");
var users = require("./users");
// The users module will have a getAuthorizationFromAccessTokenAsync promise-returning export. (Convert to callbacks if you wish).
// It rejects in cause of not authorized, or fulfills with a { scope, customerId } object if the user is authorized.
// The scope property indicates which scopes the user corresponding to a given access token has.
module.exports = function authPlugin(serverRequest, serverResponse, next) {
@domenic
domenic / http-mock-example.js
Created June 4, 2012 06:45
HTTP mocking library idea
var mockHttp = require("mock-http");
var a = mockHttp.server.request().errorsWith(new Error());
var b = mockHttp.server.request().respondsWith(mockHttp.response.errorsWith(new Error()));
var c = mockHttp.server.request().respondsWith("string");
var d = mockHttp.server.request().respondsWith("string", headersHash);
var A = mockHttp.server.response("text of response", optionalHeadersHash);
var B = mockHttp.server.response().data("text").error(new Error());
var C = mockHttp.server.response().data("text").data("more text");
@domenic
domenic / classes.js
Created June 6, 2012 22:18
DDDNYC talk notes
"use strict";
// Essentials of prototypes:
var carProto = {
drive: function () {
console.log("driving a " + this.color + " car");
}
};
<!DOCTYPE html>
<!-- File > New Project > Templates > JavaScript > Blank App; replace default.html with this -->
<html>
<head>
<meta charset="utf-8" />
<title>App2</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0.RC/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
@domenic
domenic / promise-retryer.js
Last active September 16, 2023 02:43
Generalized promise retryer
"use strict";
// `f` is assumed to sporadically fail with `TemporaryNetworkError` instances.
// If one of those happens, we want to retry until it doesn't.
// If `f` fails with something else, then we should re-throw: we don't know how to handle that, and it's a
// sign something went wrong. Since `f` is a good promise-returning function, it only ever fulfills or rejects;
// it has no synchronous behavior (e.g. throwing).
function dontGiveUp(f) {
return f().then(
undefined, // pass through success
@domenic
domenic / remove-bom.js
Created June 19, 2012 15:45
Adding BOM
var fs = require("fs");
var path = require("path");
var wrench = require("wrench");
var BOM_CHAR_CODE = 65279;
var BOM = String.fromCharCode(BOM_CHAR_CODE);
var fileNames = wrench.readdirSyncRecursive(process.cwd()).filter(function (fileName) {
return path.extname(fileName) === ".js";
});
@domenic
domenic / 1-index.html
Last active October 7, 2015 05:27
Proof of concept of ES5 data binding
<!DOCTYPE html>
<html>
<head>
<title>ES5 Data Binding Proof of Concept</title>
</head>
<body>
<section>
<label>
Name:
<input data-bind="name" type="text" />
@domenic
domenic / package.json
Created July 27, 2012 05:04
package.json for an app
{
"name": "cool-app-from-work",
"description": "Any identifying information has been anonymized.",
"version": "1.0.0-beta.3",
"author": "Our Org",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/our-org/our-app"
},