Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View weslleyaraujo's full-sized avatar
💤

Weslley Araujo weslleyaraujo

💤
View GitHub Profile
@weslleyaraujo
weslleyaraujo / login.php
Last active December 19, 2015 07:59
Login library for CI
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter Login Class
* This class enables you to have a simple login route and permission levels
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author Weslley Araujo (http://weslleydeveloper.com)
def date_to_unix(time)
Time.parse(time).to_i
end
def in_progress(start_time, end_time, time_now = (Time.new.strftime '%d/%m/%Y'))
now = date_to_unix(time_now)
if date_to_unix(start_time) <= now
date_to_unix(end_time) < now ? false : true
else
false
@weslleyaraujo
weslleyaraujo / gist:8268509
Created January 5, 2014 13:54
Simple function to padding your number
function padding(str, len, char) {
return (Array(len).join(char)+str).substr(-len);
}
padding(1, 2, 0) // 01
padding(1, 2, 0) // 02
padding(1, 2, 0) // 27
var users = [
'yellow',
'green',
'pink',
'blue'
];
var sepa = [];
for (var i in users) {
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@weslleyaraujo
weslleyaraujo / trunc.js
Created March 10, 2014 14:03
Truncate string
String.prototype.trunc = function(n){
return this.length>n ? this.substr(0,n-1)+'&hellip;' : this;
};
var slug = function (text) {
return text
.toLowerCase()
.replace(/[^\w ]+/g,'')
.replace(/ +/g,'-');
};
var truncate = function(string, n, terminator) {
if (typeof string !== 'string') {
return;
}
var lastIndex = string.lastIndexOf(' ', n), ret = string.toString();
if(ret.length <= n) return ret;
if (lastIndex != -1) {
var fn = function even (n) {
if (n === 0) {
return true
}
else return !even(n - 1)
}
fn(5);
//=> false
@weslleyaraujo
weslleyaraujo / prototype-pattern.js
Last active August 29, 2015 14:01
Pattern for private methods using prototype
var ClassName = (function () {
var
// here is the place to inject private methods
_private = {},
// all attributes values goes here
attributes = {
};
function ClassName (args) {