Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
ryanflorence / static_server.js
Last active April 26, 2024 16:18
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@csanz
csanz / encrypt_decrypt.js
Created August 30, 2011 16:06
Simple String Encryption & Decryption with Node.js
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
@jhurliman
jhurliman / base64.js
Created September 29, 2011 06:39 — forked from Marak/base64.js
An extremely simple implementation of base64 encoding / decoding using node.js Buffers (plus url-safe versions)
/*
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
*
* (C) 2010, Nodejitsu Inc.
* (C) 2011, Cull TV, Inc.
*
*/
var base64 = exports;
@vybs
vybs / rhino_dust.java
Created January 17, 2012 02:15
Sample code to rendering dust template using Rhino
package com.linkedin.dust.renderer;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.JavaScriptException;
@ryandotsmith
ryandotsmith / a-backbone-js-demo-app-sinatra-backend.md
Created January 22, 2012 01:42
Backbone demo app with sinatra backend

A Backbone.js demo app (Sinatra Backend)

Oct 16 2010

Updates

  • 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments

In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].

@utsengar
utsengar / Sync_Async_loading_handlebars.js
Created April 2, 2012 20:41
synchronous and asynchronous loading of handlebars templates
/*
* This decorates Handlebars.js with the ability to load
* templates from an external source, with light caching.
*
* To render a template, pass a closure that will receive the
* template as a function parameter, eg,
* T.render('templateName', function(t) {
* $('#somediv').html( t() );
* });
* Source: https://github.com/wycats/handlebars.js/issues/82
@Jimbly
Jimbly / gist:2346805
Created April 9, 2012 21:54
Adding keep alive for https connections
function addKeepAliveTimeout(agent) {
function fail(msg) {
console.warn(msg + ', node version: ' + process.version);
return agent;
}
// Check it's what we expect
var old_listeners = agent.listeners('free');
if (!old_listeners || old_listeners.length !== 1) {
return fail('Unexpected lacking "free" listener');
}
@gasman
gasman / pnginator.rb
Created April 30, 2012 18:08
pnginator: pack Javascript into a self-extracting PNG
#!/usr/bin/env ruby -w
# pnginator.rb: pack a .js file into a PNG image with an HTML payload;
# when saved with an .html extension and opened in a browser, the HTML extracts and executes
# the javascript.
# Usage: ruby pnginator.rb input.js output.png.html
# By Gasman <http://matt.west.co.tt/>
# from an original idea by Daeken: http://daeken.com/superpacking-js-demos
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Backbone.js • TodoMVC</title>
<link rel="stylesheet" href="../../assets/base.css">
<!--[if IE]>
<script src="../../assets/ie.js"></script>
<![endif]-->