Skip to content

Instantly share code, notes, and snippets.

@dtan
dtan / custom_logger.js
Created March 29, 2012 15:59
Custom javascript logger
(function (undefined) {
// handles all the console methods to make the console persistent, mainly for IE
if (window.console === undefined) {
window.console = {};
}
(function () {
var methods = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"],
i = methods.length;
for ( ; i--; ) {
if ( !window.console[ methods[i] ] ) {
@dtan
dtan / app.js
Created December 21, 2011 07:52
basic set up - express for node.js
var express = require('express');
app = module.exports = express.createServer(),
viewEngine = 'jade',
stylus = require('stylus'),
nib = require('nib');
app.configure('development', function(){
var stylusMiddleware = stylus.middleware({
src: __dirname + '/stylus/', // .styl files are located in `/stylus`, must match /public folder structure
dest: __dirname + '/public/', // .styl resources are compiled `/stylesheets/*.css`
@dtan
dtan / events-manager.js
Created October 19, 2011 21:48
javascript observer pattern
var MyNs = {
events: {
Manager: {}
}
};
/**
* This creates a new Publisher/Subscriber object
* @example:
var eventManager = new MyNs.events.Manager,
@dtan
dtan / jade_stylus_sublime.md
Created August 10, 2011 03:47 — forked from csanz/jade_stylus_sublime.md
Getting Jade and Stylus working w/ Sublime Text 2

Download Jade and Stylus bundles

https://github.com/miksago/jade-tmbundle
https://github.com/LearnBoost/stylus/tree/master/editors

~/Downloads/

Create directories:

cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages

@dtan
dtan / gist:1073845
Created July 9, 2011 18:58
using partials in express
folder structure:
- views
- login.jade
- partials
- form
- input.jade
// ======= login.jade:
h1= title
@dtan
dtan / gist:1055024
Created June 29, 2011 21:25
node make failure
Waf: Entering directory `/home/admin/sources/node/build'
DEST_OS: linux
DEST_CPU: x64
Parallel Jobs: 1
Product type: program
[ 1/33] copy: src/node_config.h.in -> build/default/src/node_config.h
[ 2/33] copy: tools/nodejs.pc.in -> build/default/tools/nodejs.pc
[ 3/33] cc: deps/libeio/eio.c -> build/default/deps/libeio/eio_1.o
/usr/bin/gcc -rdynamic -D_GNU_SOURCE -pthread -g -O3 -DHAVE_OPENSSL=1 -DHAVE_MONOTONIC_CLOCK=1 -DX_STACKSIZE=65536 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_FDATASYNC=1 -DARCH="x64" -DPLATFORM="linux" -D__POSIX__=1 -Wno-unused-parameter -D_FORTIFY_SOURCE=2 -Idefault/deps/libeio -I../deps/libeio -Idefault -I.. ../deps/libeio/eio.c -c -o default/deps/libeio/eio_1.o
[ 4/33] cc: deps/http_parser/http_parser.c -> build/default/deps/http_parser/http_parser_3.o
@dtan
dtan / gist:1054996
Created June 29, 2011 21:12
output of node build
~$:/sources/node# ./configure
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for program gcc or cc : /usr/bin/gcc
Checking for gcc : ok
Checking for library dl : yes
Checking for openssl : not found
@dtan
dtan / tls.js
Created June 25, 2011 15:46
node tls e
var tls = require('tls')
, fs = require('fs')
, host = 'localhost'
, port = 4001
, options = {
pkey: fs.readFileSync('keys/ssl.key'),
cert: fs.readFileSync('keys/ssl.crt')
}
, handler = function (s) {
s.write('welcome to a secure connection!');
@dtan
dtan / example_page.xsl
Created March 30, 2011 13:05
Convert XML to JSON output
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:json="http://json.org/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- this is in the context of Symphony CMS, hence ../utilities -->
<xsl:import href="../utilities/xml2json.xsl"/>
<xsl:output omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
@dtan
dtan / gist:733829
Created December 8, 2010 20:10
sniff out iframe and resize
(function (window) {
function sendChangeHeightMessage() {
var newHeight = window.location.search.substring(1),
par = window.parent.parent,
frameId = 'iframe_sparq',
el = par.document.getElementById(frameId);
if (el != null) {
if (newHeight != "") {
//alert(window.location.search.substring(1));