Skip to content

Instantly share code, notes, and snippets.

View ricardobeat's full-sized avatar

Ricardo Tomasi ricardobeat

View GitHub Profile
@tobitailor
tobitailor / def.js
Created July 13, 2010 23:32
Simple Ruby-style inheritance for JavaScript
/*
* def.js: Simple Ruby-style inheritance for JavaScript
*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*
*
* Example:
*
* def ("Person") ({
@jameshartig
jameshartig / gist:762874
Created January 2, 2011 22:20
Get IP of user in node.js and CloudFlare-compatible
function getIP(req) {
var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
//check for cloudflare
try {
if (req.headers['cf-connecting-ip']) {
var ipParts = ip_address.split(".");
var cloudFlare = false;
switch (parseInt(ipParts[0])) {
case 204:
//(204.93.177.0 - 204.93.177.255)
@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);
require.extensions[".json"] = function (module, filename) {
module.exports = JSON.parse(require("fs").readFileSync(filename, "utf8"))
}
@jed
jed / LICENSE.txt
Created May 20, 2011 13:27 — forked from 140bytes/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@LeverOne
LeverOne / LICENSE.txt
Created October 24, 2011 04:17 — forked from jed/LICENSE.txt
generate random v4 UUIDs (107 bytes)
DO WTF YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Alexey Silin <pinkoblomingo@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WTF YOU WANT TO PUBLIC LICENSE
foo
(
function( ) {
return bar(
'foo' ) ;
},
function
()
{
return 'bar'
@maettig
maettig / LICENSE.txt
Created February 7, 2012 03:56 — forked from 140bytes/LICENSE.txt
encodeJavaScriptString in 140byt.es
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Thiemo Mättig <http://maettig.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@roquin
roquin / spark_matrix.py
Created February 23, 2012 12:49
A helper function for cs373 from udacity
# usage: spark_matrix([[0.1, 0.5, 0.3],
# [0.0, 1.0, 0.8],
# [0.1, 0.2, 0.1]])
# ▁▅▃
# ▁█▇
# ▁▂▁
#
# If you get encoding errors, uncomment and add next 5 lines to the start of file.
# #!/usr/bin/env python
# # -*- coding: utf-8 -*-
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#