Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jed's full-sized avatar

Jed Schmidt jed

View GitHub Profile
var crypto = require("crypto")
module.exports = function() {
var bytes = crypto.randomBytes(16)
bytes[6] &= 0x0f // 0000xxxx
bytes[6] += 0x40 // 0100xxxx
bytes[8] &= 0x3f // 00xxxxxx
bytes[8] += 0x80 // 10xxxxxx
@jed
jed / README.md
Last active December 27, 2015 15:09
Use U+200B to evade Twitter's DM malware flagging

Use this bookmarklet to escape the URL of the current page and evade Twitter's broken malware link flagging. It prepends all periods with a zero-width space, which Chrome, Firefox, and Safari all seem to ignore. Twitter's server won't recognize it as a link (yet), but the Twitter client will, which means it remains clickable in the DM pane.

For example: https://twitter.com/ will get flagged as malware in a DM, while https://twitter​.com/ won't. They look the same, but the latter has a ZWSP before the . in .com.

@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active February 25, 2024 17:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@jed
jed / monotonic-timestamp.js
Last active December 20, 2015 00:59
returns unique timestamps, delays subsequent calls if called more than once per millisecond.
var then = Date.now()
function monotonicTimestamp(cb) {
var now = Date.now()
now > then
? setImmediate(cb, null, then = now)
: setTimeout(cb, then - now, null, ++then)
}
_ ___ _ ___ _ _ ___ _ _ ___ _ ___ ___ _ _
| | | __| /_\ | _ \ \| | | __| \| |/ __| | |_ _/ __| || |
| |__| _| / _ \| / .` | | _|| .` | (_ | |__ | |\__ \ __ |
|____|___/_/ \_\_|_\_|\_| |___|_|\_|\___|____|___|___/_||_|
@jed
jed / level-incremental-id.js
Last active December 17, 2015 04:29
an approach for incremental ids using levelup.
var levelup = require("levelup")
var path = __dirname + "db"
var options = {encoding: "json"}
var db = levelup(path, options)
function id(cb) {
if (typeof cb != "function") throw new TypeError
if (!id.queue) {
id.queue = []
$ npm -g install local-tld
npm http GET https://registry.npmjs.org/local-tld
npm http 304 https://registry.npmjs.org/local-tld
> local-tld@3.0.6 preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall
++ id -u
+ '[' 501 -eq 0 ']'
+ SUDO=sudo
@jed
jed / rendering_templates_obsolete.md
Created October 19, 2012 05:07
Rendering templates obsolete

(tl;dr DOM builders like [domo][domo] trump HTML templates on the client.)

Like all web developers, I've used a lot of template engines. Like most, I've also written a few of them, some of which even [fit in a tweet][140].

The first open-source code I ever wrote was also one of the the first template engines for node.js, [a port][node-tmpl] of the mother of all JavaScript template engines, [John Resig][jresig]'s [micro-templates][tmpl]. Of course, these days you can't swing a dead cat without hitting a template engine; one in eight packages on npm ([2,220][npm templates] of 16,226 as of 10/19) involve templates.

John's implementation has since evolved and [lives on in Underscore.js][underscore], which means it's the default choice for templating in Backbone.js. And for a while, it's all I would ever use when building a client-side app.

But I can't really see the value in client-side HTML templates anymore.

@jed
jed / jsconf_does_disney.md
Created October 6, 2012 08:22
2012 JavaScript Roundup, Disney-style @ JSCONF EU 4ß

Objective-C (to the tune of Under the Sea)

If you're shipping iOS apps,

and dream of the bucks you'll make,

you might think of "going native",

but Xcode's a big headache.

@jed
jed / ec2-nodejs.sh
Created August 27, 2012 06:06
installing node on a new ec2 instance (amazon AMI)
sudo yum update
sudo yum install -y gcc-c++.x86_64
sudo yum install -y openssl-devel.x86_64
sudo yum install -y make.x86_64
sudo yum install -y git
git clone git://github.com/joyent/node.git
cd node