Skip to content

Instantly share code, notes, and snippets.

View mauriciodarocha's full-sized avatar

Mauricio Rocha mauriciodarocha

View GitHub Profile
@mauriciodarocha
mauriciodarocha / is_logged.js
Last active December 12, 2015 01:08
Função para verificar se usuário está "logado" em loja Vtex
/*
*
* Função para verificar se existe usuário logado em loja Vtex
*
* Uso:
* if(is_logged()) {
* // código se está logado
* } else {
* // código se NÃO está logado
* }
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@mauriciodarocha
mauriciodarocha / get_main_domain
Last active December 13, 2015 18:39
Retorna o nome principal do domínio.
/*
Ex. www.meusite.com.br, develop-meusite.vtexcommerce.com.br, loja.meusite.com.br, meusite.vtexcommerce.com.br, meusite.vtexcommercebeta.com.br... todos retornam "meusite".
********************************************
Uso:
Em multiloja pode-se usar como referência para aplicação de tags.
@mauriciodarocha
mauriciodarocha / fix_sku_selection.js
Created February 19, 2013 15:04
Conserta a seleção de sku pelo "Label". Faz o on/off funcionar. Para usar coloque dentro de uma função e execute a mesma ao entrar na página de produto.
var _removeUnavaliableStyle = window.removeUnavaliableStyle;
// function override
window.removeUnavaliableStyle = function (selector)
{
// fix on/off label style
if(typeof selector=="undefined")
jQuery(".topic label").removeClass("sku-picked");
_removeUnavaliableStyle(selector);
}
@mauriciodarocha
mauriciodarocha / gist:5321317
Last active December 15, 2015 20:49
Google Conversion Tag Image. Insere imagem para google ad services.
<script type="text/javascript">
$(document).ready(function (param) {
place_google_conversion_img_tag();
});
var place_google_conversion_img_tag = function () {
// não passa deste ponto se não for a página "finaliza-compra"
if(!$('body').hasClass("finaliza-compra")) return false;
// não passa deste ponto se já foi inserida a tag.
@mauriciodarocha
mauriciodarocha / MetaObject.php
Created May 30, 2016 23:27 — forked from CHH/MetaObject.php
PHP does Meta Programming too! (Requires PHP 5.4)
<?php
namespace CHH;
trait MetaObject
{
protected static $__metaClass;
static function setMetaClass(MetaClass $metaClass)
{
var adicionarProduto = function(sku,qtd,seller){
var id = sku;
var quantity = qtd||1;
var seller_id = seller||1;
var product = {
id: id,
quantity: quantity,
seller: seller_id
};
@mauriciodarocha
mauriciodarocha / dummy-web-server.py
Created September 16, 2016 02:28 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@mauriciodarocha
mauriciodarocha / delayApp.js
Last active August 23, 2018 03:01
delay loading of app
/** 201808222232 */
var delayApps = (function ($, window, document, undefined) {
return function (apps,delay) {
var _apps = "function"===typeof apps ? [apps] : apps instanceof Array ? apps : undefined;
if("undefined"===typeof apps&&!(apps instanceof Array)) { return false; }
var _self = this;
var _delay = delay || 10000;
var __timeout = _self.setTimeout(function () {
"object"===typeof console&&"function"===typeof console.log&&console.log('Starting apps.');
$.each(_apps,function (ndx,_app) {
public class MyClass {
public static void main(String args[]) {
String results = FizzBuzz(1,20);
System.out.println(results);
}
public static String FizzBuzz(int k, int l){
String n = "";
for(int i=k;i<=l;i++){
if(i%3==0)