Skip to content

Instantly share code, notes, and snippets.

View kaiquewdev's full-sized avatar

Kaique Silva kaiquewdev

View GitHub Profile

Why declaring globals is better than exporting

The module pattern

During the past several years the way of managing javascript dependencies evolved bringing some advanced solutions. One of the concepts which became very popular today, is a module pattern. The beginning of this article explains the idea pretty well. This concept was then reused in many modern dependency-management solutions, and was finally suggested as a specification of AMD API, the most known implementation of which is probably the RequireJS.

Exporting feature, the problems of which are discussed in this text, is part of the module pattern. Strictly speaking, the module pattern itself has no relation to the dependency resolution, it is rather designed for managing and storing the data in a special way. But it naturally integrates as a base for the dependency management libraries.

Strophe.addConnectionPlugin("xdomainrequest", {
init: function () {
if (window.XDomainRequest) {
Strophe.debug("using XdomainRequest for IE");
// override the send method to fire readystate 2
if (typeof XDomainRequest.prototype.oldsend == 'undefined') {
XDomainRequest.prototype.oldsend = XDomainRequest.prototype.send;
XDomainRequest.prototype.send = function() {
XDomainRequest.prototype.oldsend.apply(this, arguments);
/*! normalize.css 2012-02-07T12:37 UTC - http://github.com/necolas/normalize.css */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}[hidden]{display:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}html,button,input,select,textarea{font-family:sans-serif}body{margin:0}a:focus{outline:thin dotted}a:hover,a:active{outline:0}h1{font-size:2em;margin:.67em 0}h2{font-size:1.5em;margin:.83em 0}h3{font-size:1.17em;margin:1em 0}h4{font-size:1em;margin:1.33em 0}h5{font-size:.83em;margin:1.67em 0}h6{font-size:.75em;margin:2.33em 0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}blockquote{margin:1em 40px}dfn{font-style:italic}mark{background:#ff0;color:#000}p,pre{margin:1em 0}pre,code,kbd,samp{font-family:monospace,serif;_font-family:'courier new',monospace;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@kaiquewdev
kaiquewdev / package.json
Created July 25, 2013 18:06
Package.json sample.
{
"name": "",
"version": "",
"private": false,
"preferGlobal": true,
"author": "Kaique da Silva <[email protected]>",
"description": "",
"contributors": [],
"bin": {},
"scripts": {
var auth = exports;
auth.login = function ( user, cb ) {
var query = 'SELECT id, password FROM users WHERE email = ?';
connection.query( query, user.login, function ( err, results ) {
var passwordMatch = hashes.verify( user.password, results[0]['password'] );
if ( !err && passwordMatch ) {
return cb( true );
var itens = [
'apple',
'grape',
'orange'
];
itens
.join(',')
.replace(/(\w+(?!=\,))/g, '<li>\$1<\li>')
.split(',');
#!/usr/bin/env node
(function () {
'use strict';
var request = require('request'),
fs = require('fs'),
cluster = require('cluster'),
nCPUs = require('os').cpus().length;
var imgs = [
'http://upload.wikimedia.org/wikipedia/commons/a/af/Flag_of_South_Africa.svg',
# coding: utf-8
print('Hello world!')
@kaiquewdev
kaiquewdev / template-draft1.js
Created January 4, 2013 18:14
Template engine test
var template = require('./template-engine');
template.engine.filter.add('sum', function (a, b) {
return Number(a) + Number(b);
});
var context = 'A soma de 5 + 5 é igual à {{sum(5, 5)}}';
console.log( template.engine.context.change(context, {}) );