Skip to content

Instantly share code, notes, and snippets.

View kentbrew's full-sized avatar

Kent Brewster kentbrew

View GitHub Profile
@kentbrew
kentbrew / node-on-ec2-port-80.md
Last active February 4, 2024 19:14
How I Got Node.js Talking on EC2's Port 80

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);
@kentbrew
kentbrew / how-i-got-ssl-working-with-node.js
Created January 13, 2011 02:08
How I got SSL working on Node
// 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 January 25, 2011 03:34
Pro JS Design Patterns Sample Code
<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:
//
<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 February 3, 2011 15:11
In response to Adam Dachis' Lifehacker article, at http://lifehac.kr/ekdUVW
<!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 February 26, 2011 17:30
Safe Script Tag Insertion
// 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 February 26, 2011 20:14
How To Rotate 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 March 29, 2011 20:59
Hey, experts? Have I just fixed document.write?
We couldn’t find that file to show.
@kentbrew
kentbrew / behavior.js
Created April 15, 2011 04:35
Placeholders for Everyone
(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 September 28, 2011 21:26
Get your last few Twitter favorites.
// twitter favorites
(function (w, d, a) {
var $ = w[a.el] = {};
$.w = w;
$.d = d;
$.a = a;
$.f = (function () {
return {
listen : function (el, ev, fn) {