Skip to content

Instantly share code, notes, and snippets.

View carlosvillu's full-sized avatar
🏠
Working from home

Carlos Villuendas Zambrana carlosvillu

🏠
Working from home
View GitHub Profile
// HOWTO: load LABjs itself dynamically!
// inline this code in your page to load LABjs itself dynamically, if you're so inclined.
(function (global, oDOC, handler) {
var head = oDOC.head || oDOC.getElementsByTagName("head");
function LABjsLoaded() {
// do cool stuff with $LAB here
}
@carlosvillu
carlosvillu / install_node.sh
Created August 4, 2011 17:22
Configure NodeJs + NPM + NGINX
#!/bin/bash
NODE_VERSION=0.4.10
NPM_VERSION=1.0.22
sudo apt-get update
sudo apt-get install -y build-essential git-core nginx libssl-dev pkg-config curl
# Install node
mkdir -p $HOME/local/node
git clone git://github.com/joyent/node.git
@carlosvillu
carlosvillu / mongod init script
Created August 21, 2011 11:19 — forked from joonyou/mongod init script
mongodb start script
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
@carlosvillu
carlosvillu / main.js
Created October 1, 2011 00:02
Uso de la función call
jQuery(function(){
jQuery('input[type=submit]').click(function(evt){
evt.preventDefault();
var string = jQuery('input[type=text]').val();
var simpleParser = {},
advancedParser = {},
wonderfulParser = {};
PARSER.call(simpleParser);
@carlosvillu
carlosvillu / formas.js
Created October 10, 2011 17:15
Como crear clases y herencias en JS
var Forma = function(){};
Forma.prototype = {
getArea: function()
{
console.log('Get Area from Forma');
}
};
var Cuadrado = function()
{
@carlosvillu
carlosvillu / gist:1451530
Created December 9, 2011 13:32
Lazy pattern para isMobile
var isMobile = function() {
var result = false;
for (var i = 0, len = SUPPORTED_OS.length; i < len && !result; i++) {
var mobile_os = SUPPORTED_OS[i];
$.os[mobile_os] && (result = true);
}
return isMobile = result;
};
(function() {
var google, nock, req, request;
request = require('http').request;
nock = require('nock');
google = nock("www.google.com").get('/').reply(200, {
response: "ok!"
});
@carlosvillu
carlosvillu / i18n.coffee
Created August 23, 2012 23:22
Idea para tener i18n con Require
class I18n
constructor: (@dicc={}) ->
_: (text) ->
@dicc[text] or text
browserLanguage = navigator.language ||
navigator.userLanguage ||
'en'
@carlosvillu
carlosvillu / runner-mocha.coffee
Created August 25, 2012 17:36
Runner for phantom and mocha
system = require('system')
##
# Wait until the test condition is true or a timeout occurs. Useful for waiting
# on a server response or for a ui change (fadeIn, etc.) to occur.
#
# @param testFx javascript condition that evaluates to a boolean,
# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
# as a callback function.
# @param onReady what to do when testFx condition is fulfilled,
@carlosvillu
carlosvillu / gist:3492897
Created August 27, 2012 22:24
Precompilo en el server templates Jade y los hago AMD compatibles
task 'build:client:jade', 'Compile Jade template to generate AMD complient modules', (file) ->
dir = "#{__dirname}/application/templates"
readdir dir, (err, files) ->
throw err if err
files.forEach (file, index) ->
console.log "application/templates/#{file}"
module = "define(function(require){var template = {{compiled}};return template;});"
template = readFileSync "#{dir}/#{file}", 'utf8'
compiled = module.replace /{{compiled}}/, jade.compile(template, client: true).toString()
writeFileSync "#{__dirname}/public/js/internal/templates/#{file.replace /.jade/, '.js'}", compiled, 'utf8'