Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / scroll.html
Created June 27, 2016 16:20
Scroll Position Directiva e implementación - Se usa una marca para medir la distancia del scroll y realizar una accn.
<span scroll-position="scroll"></span>
<div ng-class="{show: scroll > 400, hide: scroll <= 400}">
<h2>I'm here</h2>
</div>
@rnaffer
rnaffer / tableToSql.js
Created August 1, 2016 16:39
Export table to excel with pure javascript
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><?xml version="1.0" encoding="UTF-8" standalone="yes"?><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) };
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table);
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML };
window.location.href = uri + base64(format(template, ctx));
};
@rnaffer
rnaffer / comandos
Last active August 4, 2016 03:24
Comandos comunes Api generator infyom labs
Generar api desde tabla
php artisan infyom:api $MODEL_NAME --fromTable --tableName=$TABLE_NAME
Test api
vendor\bin\phpunit
@rnaffer
rnaffer / helpers.js
Last active February 22, 2017 15:48
Usefull Javascript functions
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}