Skip to content

Instantly share code, notes, and snippets.

View tcorral's full-sized avatar

Tomás Corral Casas tcorral

  • Softonic.com
  • Barcelona
View GitHub Profile
@tcorral
tcorral / namespace
Created October 8, 2011 22:08
Function that creates a namespace, from a string, to be used in your application.
function namespace(sNamespace)
{
var oObj = window;
var aElements = sNamespace.split(".");
var nElement = 0;
var nLenElements = aElements.length;
var sElement = null;
for(; nElement < nLenElements; nElement++)
{
sElement = aElements[nElement];
@tcorral
tcorral / namespace
Created October 8, 2011 22:08
Function that creates a namespace, from a string, to be used in your application.
function namespace(sNamespace)
{
var oObj = window;
var aElements = sNamespace.split(".");
var nElement = 0;
var nLenElements = aElements.length;
var sElement = null;
for(; nElement < nLenElements; nElement++)
{
sElement = aElements[nElement];
@tcorral
tcorral / objects.js
Created October 30, 2011 11:36 — forked from kaaes/objects.js
ECMA5 object cheatsheet
/**
* Object descriptor
**/
var a = {
prop1 : 14
}
var descriptorObj1 = Object.getOwnPropertyDescriptor(a, 'prop1');
@tcorral
tcorral / Im.coffee
Created December 21, 2011 20:53
Im.js written in CS
do (window, document)->
'use strict'
bDebug = false
oContainerDiff = null
nMinPercentage = 100
bAsynchronous = false
nImagesLoaded = 0
aCanvas = []
fpLoop = _loop
proxyFloat = window.parseFloat
@tcorral
tcorral / buster_closure_bug
Created July 1, 2012 12:14
Sample buster test case inside a closure
(function(win, doc){
function setup()
{
}
function teardown()
{
}
buster.testCase( "SampleTest", {
setUp: setup,
tearDown: teardown,
@tcorral
tcorral / DefineSpecsAsModules.coffee
Created August 4, 2012 18:57
Mixing Require.js, Jasmine, Sinon.js and Backbone.
## ItemView.coffee in the specs/coffee folder ##
define ["ItemView"], (ItemView) ->
###
Specs for ItemView
###
describe "Item View", ->
###
Common setup and teardown
➜ 1.8pre git:(1.8pre) grunt
Running "selector:src/selector.js" (selector) task
<WARN> Unable to read "src/sizzle/sizzle.js" file (Error code: ENOENT). Use --force to continue. </WARN>
Aborted due to warnings.
# This error is caused by not having submodules pulled. Can be worked around by manually pulling submodules:
> git submodule update --init
# Next error is Windows only
@tcorral
tcorral / extend.js
Created November 15, 2012 09:54
Safe extend to bypass constructors that throw Errors.
/**
* This piece of code has been created to safely extend classes/objects in Javascript.
* After talk with a great friend that was upset trying to extend a class/object that throws an error
* if some parameter in the constructor of the class/object is missing.
*
* var Search = function ( sToSearch ) {
* if ( sToSearch == null ) { // Check if sToSearch is null or undefined
* throw new Error( 'Search needs a string to search' );
* }
* this.sToSearch = sToSearch;
@tcorral
tcorral / Calendar.js
Last active December 11, 2015 09:48
Calendar widget multilanguage
var CalendarLocale_EN = function()
{
this.firstDayOfWeek = Calendar.SUNDAY;
};
var CalendarWeekDays_EN = function()
{
this["long"] =
[
"Sunday",
"Monday",
@tcorral
tcorral / gist:4604119
Created January 23, 2013 10:26
Fixture Data workshop Hydra.js
{
"events":[
{
"id":1,
"day":25,
"month":3,
"year":2014,
"title":"Nisl ex vel qui illum.",
"description":"In minim sed consequat facilisis quis, dolore eum minim in dolore, feugait hendrerit euismod eum. Eros, iusto blandit nonummy luptatum.",
"thumbnail":"http://lorempixel.com/40/40/",