Skip to content

Instantly share code, notes, and snippets.

Avatar

Kent Brewster kentbrew

View GitHub Profile
@kentbrew
kentbrew / node-on-ec2-port-80.md
Last active May 1, 2021
How I Got Node.js Talking on EC2's Port 80
View node-on-ec2-port-80.md

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
View how-i-got-ssl-working-with-node.js
// works with node-0.2.4, not node-0.3.6; be SURE you got node to build with OpenSSL
//
// you will need working SSL key and cert, otherwise:
// openssl genrsa -out privatekey.pem 1024
// openssl req -new -key privatekey.pem -out certrequest.csr
// openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
//
// map port 8443 to 443 and 8080 to 80; see gist 776580 to do this on EC2
var http = require('http'), crypto = require('crypto'), fs = require("fs");
@kentbrew
kentbrew / jspat6_4.html
Created Jan 25, 2011
Pro JS Design Patterns Sample Code
View jspat6_4.html
<html>
<head>
<title>Chapter 6 Section 4, Pro JavaScript Design Patterns</title>
</head>
<body>
<script>
// this is straight from the code exampes at http://jsdesignpatterns.com/
// sadly, it fails with a syntax error. quoth JSLint:
//
View jspat6_4.html
<html>
<head>
<title>Chapter 6 Section 4, Pro JavaScript Design Patterns</title>
</head>
<body>
<script>
// this is straight from the code exampes at http://jsdesignpatterns.com/
// sadly, it fails with a syntax error. quoth JSLint:
//
@kentbrew
kentbrew / guessmynumber.html
Created Feb 3, 2011
In response to Adam Dachis' Lifehacker article, at http://lifehac.kr/ekdUVW
View guessmynumber.html
<!doctype html>
<html>
<head>
<title>Guess My Number</title>
</head>
<body>
<h3 id="t"></h3>
<ul id="o"></ul>
<input id="g" />
<button id="b">Guess</button>
@kentbrew
kentbrew / safeScriptInsertion.js
Created Feb 26, 2011
Safe Script Tag Insertion
View safeScriptInsertion.js
// When a script appends new SCRIPT tags to the HEAD or BODY, it can
// run into serious trouble. If it was originally included in the HEAD, the
// HEAD might not have fully rendered when it fires, and the BODY isn't there yet.
// And if it's in the BODY, older browsers may blow chunks if it tries to append
// SCRIPT tags to the HEAD.
//
// What seems to work: be HEAD/BODY agnostic. Look for the first SCRIPT tag on the
// page and insert before it.
var runScript = function(url) {
@kentbrew
kentbrew / Rotating an iPhone Movie
Created Feb 26, 2011
How To Rotate an iPhone Movie
View Rotating an iPhone Movie
Here be some notes on the insane set of gymnastics I have to go through every time
I fuck up and start recording video with my iPhone held vertically.
I do this a LOT. I don't know why it happens. Often I am standing over something and
recording it, and the phone doesn't understand that I actually mean to hold it
horizontally.
META QUESTIONS:
Why isn't there a way to prevent the phone from shooting video in vertical format? Who
@kentbrew
kentbrew / saferDocumentWrite.js
Created Mar 29, 2011
Hey, experts? Have I just fixed document.write?
We couldn’t find that file to show.
@kentbrew
kentbrew / behavior.js
Created Apr 15, 2011
Placeholders for Everyone
View behavior.js
(function (w, d, a) {
var $ = w[a.k] = {};
$.a = a;
$.w = w;
$.d = d;
$.f = (function () {
return {
getEl: function (v) {
// helper: which is the target of this event?
var el;
@kentbrew
kentbrew / Twitter Favorites widget
Created Sep 28, 2011
Get your last few Twitter favorites.
View Twitter Favorites widget
// twitter favorites
(function (w, d, a) {
var $ = w[a.el] = {};
$.w = w;
$.d = d;
$.a = a;
$.f = (function () {
return {
listen : function (el, ev, fn) {