Skip to content

Instantly share code, notes, and snippets.

@rnaffer
rnaffer / scrollTo.js
Created June 23, 2016 15:19
Angular SmothScrollTo Directiva
angular.module('app')
.directive('uiScrollGo', function() {
return {
restrict: 'AC',
link: function(scope, el, attr) {
el.on('click', function(e) {
var target = $('#' + attr.uiScrollGo);
if (target.length) {
$('html, body').animate({
@rnaffer
rnaffer / angular-flot.js
Last active June 21, 2016 14:00
Angular-Flot Directiva e Implementación
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Develer S.r.L.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@rnaffer
rnaffer / ui-select-required.js
Created June 6, 2016 16:35
ui-select Required Directive
app.directive('uiSelectRequired', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.uiSelectRequired = function(modelValue, viewValue) {
for(var prop in modelValue) {
if(modelValue.hasOwnProperty(prop))
return true;
}
@rnaffer
rnaffer / textEditor.js
Created June 2, 2016 19:41
Directiva ng-model para wysiwyg
app.directive('textEditor', function () {
return {
require: 'ngModel',
link: function(scope, element, attributes, controller) {
scope.$watch(attributes.ngModel, function(value) {
$(element).html(value);
});
element.bind('keyup mouseup', function(){
controller.$setViewValue(element.html());
if (!scope.$$phase) {
@rnaffer
rnaffer / SmartTable.html
Last active May 31, 2016 22:45
Angular Smart Table Like DataTables
<table st-table="displayedCollection" st-safe-src="rowCollection" class="table table-bordered table-striped no-border-top">
<thead>
<tr class="search-header">
<th colspan="6">
<span>Buscar:</span> <input st-search="" class="form-control input-sm" type="text"/>
</th>
</tr>
<tr>
<th st-sort="codigo" class="sortable">Código</th>
<th st-sort="nombre" class="sortable">Nombre</th>
@rnaffer
rnaffer / LaravelCommands
Last active March 3, 2016 15:31
Usefull console commands for Laravel (Windows)
/* Installation */
composer global require "laravel/installer"
/* New Project Using Laravel */
laravel new blog
/* New Project Using Composer */
composer create-project laravel/laravel nombre --prefer-dist
/* Rename Project */
@rnaffer
rnaffer / RecursiveSetTimeoutPattern.js
Last active October 27, 2015 18:57
Ejemplo del patrón de diseño "Recursive SetTimeout" con explicación.
// El orden empleando setInterval() puede ser impredecible ( 0 1 2 5 4 6 8 7).
// Invocar recursivamente a setTimeout() puede asegurar el orden de ejecución ( 0 1 2 3 4 5 6).
// Hasta que no finalize una ejecución no continua con las demás.
var ul = $('ul.log'),
index = 0;
setTimeout(function getDate() {
var started = new Date(),
@rnaffer
rnaffer / AsynchronousExecutionPattern.js
Created October 27, 2015 18:29
Ejemplo del patrón de diseño "Asynchronous Execution" con explicación.
// Las ejecuciones muy largas de codigo JavaScript tienden a bloquear el UI y dejar al navegador sin responder,
// sobre todo cuando se emplean bucles. Este patron emplea temporizadores para evitar precisamente este problema.
// Es un inconveniente bastante común en dispositivos móviles.
var buffer = function( items, iterFn, callback ) {
var i = 0,
len = items.length;
setTimeout(function() {
@rnaffer
rnaffer / TimerPattern.js
Created October 27, 2015 17:18
Ejemplo del patrón de diseño "Timer Pattern" con explicación
// Los temporizadores en JavaScript son: setTimeout() y setInterval().
// El primero se ejecuta una sola vez y el segundo se ejecuta continuamente.
// En ambos casos el primer parametro es la función que se ejecutará y el segundo el tiempo en milisegundos.
// El periodo mínimo es de 4ms y el temporizador solo se ejecuta cuando la función principal ha finalizado.
var i = 0;
var timer = setInterval(function() {
console.log( i );
i++;
@rnaffer
rnaffer / 0_reuse_code.js
Created October 27, 2015 03:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console