Skip to content

Instantly share code, notes, and snippets.

View guilhermehn's full-sized avatar

Guilherme Nagatomo guilhermehn

  • PagSeguro
  • Brasil, São Paulo
View GitHub Profile
@guilhermehn
guilhermehn / gist:3916191
Created October 19, 2012 04:14
HTML+jQuery+CSS: Flip menu
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flip Menu</title>
<style type="text/css">
body {
text-align: center;
background: #676767;
font-family: helvetica;
}
@guilhermehn
guilhermehn / gist:3916199
Created October 19, 2012 04:17
Javascript: Switch stylesheets
function trocarcss(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
@guilhermehn
guilhermehn / gist:3916224
Created October 19, 2012 04:23
Javascript: Create Gradient
/*************************
Cross Browser Gradient Backgrounds
v1.0
Last Revision: 11.03.2005
steve@slayeroffice.com
please leave this notice in tact.
should you improve upon this code, please
@guilhermehn
guilhermehn / gist:3916241
Created October 19, 2012 04:27
Javascript: Sort arrays config
function crescente (index1, index2){return index1 - index2;}
function decrescente (index1, index2){return index2 - index1;}
var ar = [2, 5, 4, 9, 1, 3, 6, 7, 8, 0];
ar.sort(crescente);
ar.sort(decrescente);
@guilhermehn
guilhermehn / gist:5506304
Last active December 16, 2015 22:20
AngularJS directive - Uppercas
angular.module('ng', []).directive('uppercase', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl){
// Cria o parsers
var _uppercase = function(inputValue){
var uppercased = angular.uppercase(inputValue);
if(uppercased !== inputValue){
modelCtrl.$setViewValue(uppercased);
modelCtrl.$render();
@guilhermehn
guilhermehn / gist:5506328
Created May 2, 2013 23:48
AngularJS directive - strip special characters
angular.module('ng', []).directive('removeSpecials', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl){
var clearString = function(inputValue){
if(inputValue && inputValue.length){
var cleanString = inputValue
.replace(/(^\s+)|(\s+$)/g, '')
.replace(/[\d\-\.\/\\\[\]\,\_\*\|\;\:\'\~\^\´\`\¨\%$$\@\!\(\)\=\+\#\¹\²\³\£\¢\¬\&<\>\°\º\ª\?]/g, '')
.replace(/\s+/g, ' ')
@guilhermehn
guilhermehn / gist:5538436
Created May 8, 2013 05:30
Download e conversao de video do youtube para mp3
youtube-dl --max-quality mp4 {{link}}
ffmpeg -i {{arquivo baixado}} -ab 256000 -ar 44100 {{nome do arquivo de audio}}.mp3
@guilhermehn
guilhermehn / gist:5731713
Last active December 18, 2015 05:19
AngularJS ngDisabled directive
angular.module('app', [])
.directive('ngDisabled', [function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
if(scope.$eval(attrs.ngDisabled)){
element.attr('disabled', 'disabled');
}
}
};
@guilhermehn
guilhermehn / gist:5833114
Created June 21, 2013 18:07
tuenti_secure JSON parser
function tuenti_secure(string) {
var regexp1 = /^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/,
regexp2 = /\\./g,
regexp3 = /"[^"\\\n\r]*"/g;
if (!string || typeof string !== "string") {
return null;
}
if (regexp1.test(string.replace(regexp2, "@").replace(regexp3, ""))) {
return null;
}
@guilhermehn
guilhermehn / gist:5978751
Created July 11, 2013 20:06
Regex to remove console.* lines Example: http://regexr.com?35i19
(\s|\t)+?console\.[^;]+;