Skip to content

Instantly share code, notes, and snippets.

@ricardobrg
ricardobrg / hide-bar.php
Created November 1, 2017 01:16
Hide wp bar
<?php
function hide_admin_bar() {
//could check user role here
return false;
}
add_filter( 'show_admin_bar', 'hide_admin_bar' );
@ricardobrg
ricardobrg / woocommerceinstalments.php
Last active November 23, 2020 13:29
Add instalments in product page
<?php
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
function woocommerce_total_product_price() {
global $woocommerce, $product;
// let's setup our divs
echo sprintf('<div id="product_total_price" style="margin-bottom:20px;display:none">%s %s</div>','Total do Produto','<span class="price">'.$product->get_price().'</span>');
echo sprintf('<div id="cart_total_price" style="margin-bottom:20px;display:none">%s %s</div>','Total do Carrinho','<span class="price">'.$product->get_price().'</span>');
?>
<script>
jQuery(function($){
@ricardobrg
ricardobrg / SplashActivity.java
Created April 25, 2018 15:20
Simplest Android Splash Screen
package br.com.brgweb.splashtest;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
public class SplashActivity extends AppCompatActivity {
@ricardobrg
ricardobrg / spinner.html
Created May 2, 2018 07:55
Pure CSS spinner loader
<style>
loader {
left: 50%;
top: 50%;
position: fixed;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%); }
.loader #spinner {
box-sizing: border-box;
stroke: #FB791A;
@ricardobrg
ricardobrg / enqueue.php
Last active July 18, 2023 09:11
Enqueue scripts in WordPress with defer or async
<?php
// This code is based in Mathew Horne blog post: https://matthewhorne.me/defer-async-wordpress-scripts/
//function to add async attribute
function add_async_attribute($tag, $handle) {
$scripts_to_async = array('my-js-handle-async', 'another-handle-async');
//check if this script is in the array
if (in_array($handle, $scripts_to_async)){
//return with async
return str_replace(' src', ' async="async" src', $tag);
@ricardobrg
ricardobrg / maxlength.html
Created June 6, 2018 03:06
input number maxlength with javascript oninput
<input type="number" step="1" min="1" max="999" maxlength="3" name="number" inputmode="numeric" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);">
@ricardobrg
ricardobrg / main.dart
Created August 7, 2018 06:58
Flutter app exit error
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
@ricardobrg
ricardobrg / fixed.js
Last active October 29, 2018 08:50
fixed sidebar with variable height
var fixed = false;
var sidebarTop = jQuery('#secondary').offset().top;
var sidebarHeight = jQuery('#secondary').height();
var windowHeight = jQuery(window).height();
var leftHeight = jQuery('.left-content-area').height();
if (windowHeight < sidebarHeight){
startPosition = sidebarTop + sidebarHeight - windowHeight;
fixPosition = windowHeight - sidebarHeight;
endPosition = leftHeight + sidebarTop - windowHeight;
}else{
@ricardobrg
ricardobrg / checkboxes.js
Last active December 2, 2018 12:59
jQuery checkboxes handling based on ids and classes with indeterminate property
jQuery(document).ready(function($){
$(":checkbox").click(function(){
let isChecked = $(this).prop('checked');
let id = $(this)[0].id;
let itemClasses = $(this).attr('class');
if (id != undefined && id != ""){
$("."+id).prop('checked',isChecked);
}
if (!isChecked){
if (itemClasses != undefined){
@ricardobrg
ricardobrg / logcat
Created April 3, 2019 13:37
Android 7.1.2 Google Pixel XL in AWS Device Farm
--------- beginning of main
04-02 11:02:32.310 5549 7959 I PTCommittedOperation: Receive new configuration for com.google.android.gms.magictether
04-02 11:02:32.341 5549 7679 E MagicTether: [MagicTetherInitializer] Invalid account list.
04-02 11:02:32.398 5581 7947 W ModuleInitIntentOp: Dropping unexpected action com.google.android.gms.phenotype.COMMITTED
04-02 11:02:32.402 5549 8068 I PTCommittedOperation: Receive new configuration for com.google.android.metrics
04-02 11:02:32.438 5549 7170 E MagicTether: [TetherListenerService] Invalid account list.
04-02 11:02:32.511 5581 7946 W ModuleInitIntentOp: Dropping unexpected action com.google.android.gms.phenotype.COMMITTED
04-02 11:02:32.518 5549 8068 I PTCommittedOperation: Receive new configuration for com.google.android.gms.walletp2p#config
04-02 11:02:32.598 5581 8028 W ModuleInitIntentOp: Dropping unexpected action com.google.android.gms.phenotype.COMMITTED
04-02 11:02:32.648 5549 8228 I PTCommittedOperation: Receive new configuration for