Skip to content

Instantly share code, notes, and snippets.

View uhtred's full-sized avatar

Daniel França uhtred

View GitHub Profile
@uhtred
uhtred / querystring-json.js
Created March 23, 2016 18:07
JS: QueryString to JSON
queryStringToJson: function(querystring) {
var pairs = querystring.split('&');
var result = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, '%20') || '');
});
return JSON.parse(JSON.stringify(result));
@uhtred
uhtred / jquery-rest-config.js
Created March 22, 2016 18:36
JS: Jquery Rest Config
$.ajaxSetup({
contentType: 'application/json',
dataType: "json",
contentType: 'application/json'
});
$.ajaxPrefilter(function(options, originalOptions) {
if(options.type === 'post') {
options.data = JSON.stringify(originalOptions.data);
}
@uhtred
uhtred / custom-validate.js
Created March 14, 2016 21:55
JS: Jquery Validate Custom
$.validator.addMethod("cMinlength", function(value, element, param) {
var isValid = $.validator.methods.minlength.call(this, value, element, param.length);
$.validator.messages['cMinlength'] = param.message;
return isValid;
});
$.validator
.addClassRules({
'validate-name': {
@uhtred
uhtred / customDelete.restangular.js
Created March 9, 2016 20:07
JS: Restangular: customDelete with payload
return restangular
.all('subscriptions')
.customDELETE('', {}, {}, payload);
@uhtred
uhtred / rename-from-to.zsh
Last active February 4, 2016 14:09
ZSH: Rename From To
autoload -U zmv
zmv '(name)(*)' 'newName$2'
@uhtred
uhtred / sort-column.directive.js
Created January 28, 2016 16:46
Angular: Sort Column Directive
/*
@Deps font awesome icons, lodash
@Usage
<table>
<thead sort-column="sortPersons">
<tr>
<th sort-column-name="name">Name</tr>
@uhtred
uhtred / gist:ef1739b76971b3d0e985
Created January 25, 2016 15:59 — forked from guilherme/gist:9604324
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
# CHECK
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0
then
@uhtred
uhtred / map-pick.lodash.js
Created January 18, 2016 18:52
Map Pick Lodash
(function() {
'use strict';
function mapPick(collection, keys) {
return _.map(collection, _.partialRight(_.pick, keys));
}
_.mixin({
'mapPick': mapPick
});
{
"name": "pushUi",
"version": "0.0.0",
"devDependencies": {
"bower": "^1.6.5",
"browser-sync": "^2.10.1",
"del": "^2.2.0",
"gulp": "^3.9.0",
"gulp-angular-filesort": "^1.1.1",
"gulp-autoprefixer": "^3.1.0",
@uhtred
uhtred / alias.zsh
Created December 16, 2015 17:08
NPM Fresh Install
alias npm-fresh-install="rm -rf node_modules && npm cache clean && npm install"