Skip to content

Instantly share code, notes, and snippets.

@codexico
codexico / gist:8568280
Created January 22, 2014 22:02
char list to accept from user
function inputOnlyLetters () {
var re_letters= /^[ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]+$/gi;
var re_not_letters= /[^ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]/gi;
$('.not-number').on('keyup', function() {
var input = this;
// user needs some time to write chars that need two strokes, like ç => ' + c
window.setTimeout(function(){
<snippet>
<content><![CDATA[
console.log('${1:this} = ', ${1:snippet});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>clog</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
<snippet>
<content><![CDATA[
console.log(${1:this});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>log</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
@codexico
codexico / stringWidth stringWordCrop
Created April 9, 2013 22:48
Crop string by width and word and append " ...".
// http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
function stringWidth(s, className) {
var c = className || "",
o = $('<div class="' + c + '">' + s + '</div>')
.css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden'})
.appendTo($('body')),
w = o.width();
o.remove();
@codexico
codexico / utils.js
Created April 4, 2013 15:59
getUrlParameter javascript
var getURLParameter = function (name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[undefined,""])[1].replace(/\+/g, '%20'))||null;
};
@codexico
codexico / pvt.fb.js
Created April 1, 2013 16:52
scrollTo animate Facebook
// http://stackoverflow.com/questions/7193425/how-do-you-animate-fb-canvas-scrollto
function scrollTo(y){
FB.Canvas.getPageInfo(function(pageInfo){
$({y: pageInfo.scrollTop}).animate(
{y: y},
{duration: 1000, step: function(offset){
FB.Canvas.scrollTo(0, offset);
}
});
@codexico
codexico / main.js
Created February 19, 2013 20:02
solucao para o fade nos ies
$(function() {
if (jQuery.browser.msie)
$('img[src$=".png"]').each(function() { // must have quotes around .png
this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+this.src+",sizingMethod='scale')";
});
});
@codexico
codexico / utils.js
Created January 28, 2013 16:44
date utils
//http://stackoverflow.com/questions/7388001/javascript-regex-to-validate-date
//http://jsfiddle.net/mplungjan/Mqh8D/
var isDate = function (str) {
var parms = str.split(/[\.\-\/]/);
var yyyy = parseInt(parms[2],10);
var mm = parseInt(parms[1],10);
var dd = parseInt(parms[0],10);
var date = new Date(yyyy,mm-1,dd,0,0,0,0);
return mm === (date.getMonth()+1) && dd === date.getDate() && yyyy === date.getFullYear();
}
//http://tryhandlebarsjs.com/
//{{#list_fl people}}{{firstName}} {{lastName}}{{/list_fl}}
{
people : [
{ firstName: "Yehuda", lastName: "Katz" },
{ firstName: "Carl", lastName: "Lerche" },
{ firstName: "Alan", lastName: "Johnson" }
]
var matched, browser;
// Use of jQuery.browser is frowned upon.
// More details: http://api.jquery.com/jQuery.browser
// jQuery.uaMatch maintained for back-compat
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||