Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
ricardodantas / gist:5659038
Last active December 17, 2015 19:18
Simula Jquery ($.live())
/*
* Pode ser usado o elmento pai do elemento que você quer manipular ou então usar o body
*/
// live() for Jquery >= 1.7
$('body').on('hover','.ElementoAlvo',function(){
//...
});
@ricardodantas
ricardodantas / install_node_and_yeoman.sh
Created June 14, 2013 23:08
Install node on Mac OS.
#!/bin/sh
npm uninstall npm -g
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew install node
npm install -g yeoman
npm install -g yo generator-generator
@ricardodantas
ricardodantas / url_parse.js
Created June 17, 2013 22:31
Get / parse URL via javascript
// If URL is http://www.somedomain.com/account/search?filter=a#top
window.location.pathname // /account/search
// For reference:
window.location.host // www.somedomain.com (includes port if there is one)
window.location.hostname // www.somedomain.com
window.location.hash // #top
window.location.href // http://www.somedomain.com/account/search?filter=a#top
@ricardodantas
ricardodantas / search_string
Created June 19, 2013 16:31
Search string in C#
class StringSearch
{
static void Main()
{
string str = "A silly sentence used for silly purposes.";
System.Console.WriteLine("'{0}'",str);
bool test1 = str.StartsWith("a silly");
System.Console.WriteLine("starts with 'a silly'? {0}", test1);
@ricardodantas
ricardodantas / Gruntfile.js
Last active December 19, 2015 03:49
Grunfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
// options: {
// banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
@ricardodantas
ricardodantas / import-system-gems-to-rvm
Created July 13, 2013 00:02
Import system's gems into rvm gems
rvm use system;rvm gemset export system.gems;rvm use 1.9.3;rvm gemset import system.gems
// Example:
JavaScript.load("/javascripts/something.js");
// With callback (that’s the good thing):
JavaScript.load("http://www.someawesomedomain.com/api.js", function() {
API.use(); // or whatever api.js provides ...
});
@ricardodantas
ricardodantas / install-ubuntu-webserver-php+ruby+nginx.sh
Last active October 27, 2019 11:52
Install NGINX, PHP, RUBY on Ubuntu server 12.0.4. Run as root.
clear
echo "Installing PHP environment..."
echo "---"
apt-get install php5-cli php5-cgi php5-common php5-curl php5-dev php5-gd php5-mcrypt php5-mhash
apt-get install php5-mysql libmysqld-dev
apt-get install php5-fpm
echo "---"
echo "Installing Ruby environment + NGINX..."
echo "---"
@ricardodantas
ricardodantas / validacao+mascara.js
Last active April 30, 2025 12:45
Máscara e validação de RG, CNPJ, CPF, etc...
// JavaScript Document
// adiciona mascara para rg
// Cada estado têm regras e quantidades diferentes de números no registro. Por isso,
// não há uma maneira confiável de fazer a validação do mesmo.
function MascaraRg(v0,errChar='?'){
const v = v0.toUpperCase().replace(/[^\dX]/g,'');
return (v.length==8 || v.length==9)?
v.replace(/^(\d{1,2})(\d{3})(\d{3})([\dX])$/,'$1.$2.$3-$4'):
(errChar+v0)
@ricardodantas
ricardodantas / extbCarrinhoFlutuante.js
Last active December 20, 2015 21:19
extbCarrinhoFlutuante.js
var CarrinhoFlutuante = {
getProductImage: function(product_id,element_to_insert){
$.ajax({
url: '/produto/sku/'+product_id,
type: 'get',
dataType: 'json',
success: function(data, textStatus, xhr) {
var image_path = data[0].Images[0][0].Path;