Skip to content

Instantly share code, notes, and snippets.

@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);
@wrboyce
wrboyce / gist:786460
Created January 19, 2011 17:12
pre-commit hook to automatically minify javascript/css
#!/usr/bin/zsh
COMPRESSOR=$(whence -p yui-compressor)
[ -z $COMPRESSOR ] && exit 0;
function _compress {
local fname=$1:t
local dest_path=$1:h
local min_fname="$dest_path/${fname:r}.min.${fname:e}"
$COMPRESSOR $1 > $min_fname
@gbakernet
gbakernet / load-google-maps.js
Created February 15, 2011 23:42
Load Google Maps API using jQuery Deferred.
/*!
* JavaScript - loadGoogleMaps( version, apiKey, language )
*
* - Load Google Maps API using jQuery Deferred.
* Useful if you want to only load the Google Maps API on-demand.
* - Requires jQuery 1.5
*
* Copyright (c) 2011 Glenn Baker
* Dual licensed under the MIT and GPL licenses.
*/
@greenido
greenido / fileBrowserHandler.htm
Created May 18, 2011 22:47
Simple test to FileSystem APIs (HTML5)
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Chrome File API tester</title>
<script>
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
@twaddington
twaddington / getInstanceLength.java
Created November 8, 2011 01:18
Simple method to parse an HttpResponse for a Content-Range header and extract the instance length (total size). Great for making partial-content requests.
/**
* <p>This method checks an HttpResponse for a Content-Range
* header and, if present, attempts to parse the instance-length
* from the header value.</p>
* <p>{@link http://tools.ietf.org/html/rfc2616#section-14.16}</p>
*
* @param response
* @return the total number of bytes for the instance, or a negative number if unknown.
*/
public static long getInstanceLength(HttpResponse response) {
// Init style shamelessly stolen from jQuery http://jquery.com
var Froogaloop = (function(){
// Define a local copy of Froogaloop
function Froogaloop(iframe) {
// The Froogaloop object is actually just the init constructor
return new Froogaloop.fn.init(iframe);
}
var eventCallbacks = {},
hasWindowEvent = false,
@tomerd
tomerd / gauge.js
Last active April 21, 2024 21:08
google style gauges using javascript d3.js
function Gauge(placeholderName, configuration)
{
this.placeholderName = placeholderName;
var self = this; // for internal d3 functions
this.configure = function(configuration)
{
this.config = configuration;
@jameskoster
jameskoster / header.php
Created February 3, 2012 12:47
WooCommerce - My Account link
<?php if ( is_user_logged_in() ) { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
<?php }
else { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?></a>
<?php } ?>
@jabbrwcky
jabbrwcky / InsecureHttpClient.java
Created February 6, 2012 13:15
A sample how to configure Apache HTTPClient (4.+) to accept SSL connections *without* certificate and hostname validation
package net.hausherr.sample;
import org.apache.http.client.CookieStore;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
@paolorossi
paolorossi / html5-video-streamer.js
Created March 7, 2012 13:21
Node.js HTML5 video streamer
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';