Skip to content

Instantly share code, notes, and snippets.

View victorvhpg's full-sized avatar
🎯
Focusing

Victor Hugo victorvhpg

🎯
Focusing
View GitHub Profile
@victorvhpg
victorvhpg / Chamando_WebMethod _com_jQuery.js
Last active December 10, 2015 21:48
"Chamando WebMethod com jQuery" simples metodo para facilitar a chamada de um webmetodo usando jQuery ajax
!function ($) {
//o metodo static webMetodo retorna um objeto jqXHR (enfim o retorno do $.ajax)
$.webMetodo = function (param) {
return $.ajax({
type: "POST",
contentType: "application/json",
//aqui eh o 'payLoad' deve ser uma string no formato JSON
//para o servidor poder entender
data: JSON.stringify(param.parametros),
dataType: "json",
@victorvhpg
victorvhpg / carregadorRecursos.js
Last active December 16, 2015 06:39
carregador de cache de recursos
var carregadorRecursos = function() {
var _todosRecursos = {};
return {
formatoAudioSuportado: (function() {
var suporta = {};
var audio = document.createElement("audio");
var formatos = {
ogg: 'audio/ogg; codecs="vorbis"',
wav: 'audio/wav; codecs="1"',
webma: 'audio/webm; codecs="vorbis"',
@victorvhpg
victorvhpg / teclado.js
Created April 16, 2013 02:48
captura/detecta teclas.....
!function(window, document) {
var teclado = {
teclas: {
ESQUERDA: 37,
CIMA: 38,
DIREITA: 39,
BAIXO: 40,
ESPACO: 32
},
teclasPressionadas: {},
@victorvhpg
victorvhpg / ajaxUpload.js
Created February 2, 2014 03:05
upload de arquivo com jquery ajax - fle upload ajax
(function($){
//=========================================================================================
$.ajaxUpload = function(config) {
var formData = new FormData();
var data = config.data;
for(var i in data){
formData.append(i, data[i]);
}
return $.ajax({
type: "POST",
@victorvhpg
victorvhpg / paginacao.js
Created February 2, 2014 03:10
paginacao de table
var Paginacao = (function($) {
"use strict";
var Paginacao = function() {
this.qtdRegistroPorPagina = 10;
this.qtdDePaginacao = 7;
this.template = ["<ul data-pg=\"container\" class=\"pagination\" > ",
"<li data-pg=\"anterior\" ><a href=\"javascript:;\">&laquo;</a></li>",
"<li data-pg=\"numeros\" > <a href=\"javascript:;\"> {@numero} </a> </li>",
"<li data-pg=\"proximo\" ><a href=\"javascript:;\">&raquo;</a></li> ",
"</ul>"
@victorvhpg
victorvhpg / clona.sh
Last active August 29, 2015 14:10
Clonar todos os repositorios publicos de um usuário - github
#!/bin/bash
#id do usuario
USUARIO="victorvhpg"
# pega json que contem todos os repositorios e extrai as URLs
LISTA_URL_CLONES=`curl --silent https://api.github.com/users/${USUARIO}/repos -q | grep "\"clone_url\"" | awk -F': "' '{print $2}' | sed -e 's/",//g'`
#para cada url faz um 'git clone'
for URL in $LISTA_URL_CLONES; do
@victorvhpg
victorvhpg / ajaxPromise.js
Last active August 29, 2015 14:10
exemplo ajax com promise
function ajaxPromise(config) {
return new Promise(
function(resolve, reject) {
var xhr = new XMLHttpRequest();
var p = [];
var parametros = null;
config.parametros = config.parametros || {};
for (var parametro in config.parametros) {
p.push(parametro + "=" + config.parametros[parametro]);
}
@victorvhpg
victorvhpg / comparacao.js
Created November 24, 2014 04:59
Comparação callbacks / Promise
//callbacks dentro de callbacks
algumaCoisa1(function(resposta1) {
//...
algumaCoisa2(function(resposta2) {
//...
algumaCoisa3(function(resposta3) {
//...
acaoFinal(resposta3);
});
});
@victorvhpg
victorvhpg / jQueryAMD.js
Created December 1, 2014 05:48
jQueryAMD
(function(window) {
"use strict";
//criamos uma funcao auto executavel que recebe uma function "fnCriaPlugin"
//que eh a implementacao do nosso plugin
(function(fnCriaPlugin) {
//agora eh so verificar se possui AMD ou nao
if (typeof define === "function" && define.amd) {
// COM suporte AMD
//entao registra o plugin com a depedencia jquery
@victorvhpg
victorvhpg / install.sh
Created January 1, 2015 06:25
instalar apache
sudo apt-get install apache2 apache2-utils