Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
leocavalcante / gist:1357930
Created November 11, 2011 12:52
fibonacci
for (var i=0,n=1;i<=21;n=(i+=n)-n) i;
@leocavalcante
leocavalcante / observer.js
Created June 25, 2012 14:29
javascript observer object
(function ( global, undefined ) {
var observer = {},
topics = {};
observer.on = function ( topic, fn ) {
if ( !topics[topic] ) topics[topic] = [];
topics[topic].push( fn );
return topics[topic].length - 1;
};
observer.trigger = function () {
var args = Array.prototype.slice.call( arguments ),
@leocavalcante
leocavalcante / slugify.js
Created June 25, 2012 15:19
slug strings
(function ( global, undefined ) {
function slugify ( str ) {
return str
.toLowerCase()
.replace( /á|à|â|ã/g, 'a' )
.replace( /é|è|ê/g, 'e' )
.replace( /í|ì|î/g, 'i' )
.replace( /ó|ò|ô|õ/g, 'o' )
.replace( /ú|ù|û/g, 'u' )
.replace( /ç/g , 'c' )
@leocavalcante
leocavalcante / month-name.js
Created June 25, 2012 15:51
returns the name of the given month (pt)
(function ( global, undefined ) {
var months = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
function monthName ( month, short ) {
month = parseInt( month ) - 1;
return short && month !== 4 ? months[month].slice( 0, 3 ) : months[month];
}
global.monthName = global.monthName || monthName;
} ( this ));
(function ( context, undefined ) {
function instance ( node ) {
if ( node.id && !global[node.id] )
global[node.id] = node;
if ( node.children.length )
for ( var i = 0, l = node.children.length ; i < l ; i++ )
instance( node.children[i] );
}( context );
} ( document.body ));
var MOUT = window.MOUT || {};
(function (module) {
var _rKind = /^\[object (.*)\]$/,
_toString = Object.prototype.toString,
UNDEF;
function kindOf(val) {
if (val === null) {
return 'Null';
} else if (val === UNDEF) {
<?php
class DataLayer {
public $header;
public $data;
public function __construct ($header, $data) {
$this->header = $header;
$this->data = $data;
}
public function get ($key) {
return $this->data[array_search($key, $this->header)];
@leocavalcante
leocavalcante / eloquent_example.php
Last active December 17, 2015 02:48
Laravel 4 - Eager Load Constraints
<?php
Quota::with(
array(
'codes' => function($query) {
$query->where('number', '=', 11);
}
)
)
->where('label', '=', 'foo')
@leocavalcante
leocavalcante / app.js
Created May 16, 2013 15:10
AngularJS + require.js example
define([
'angular',
'bar_controller',
'router'
],
function(angular, barCtrl, router)
{
var app,
appName = 'foo';
@leocavalcante
leocavalcante / gist:5671054
Last active December 17, 2015 20:58
number format API example
<!-- prefix : thousands : decimals : numdecimals : sufix -->
<!-- $ 1,234.567 -->
<input type="text" data-numformat="$ :comma:dot:3:">
<!-- R$ 1.234,56 reais -->
<input type="text" data-numformat="R$ :dot:comma:2: reais">
<!-- 1234.56 -->
<input type="text" data-numformat="::dot:2:">