Skip to content

Instantly share code, notes, and snippets.

Avatar

Ricardo Gonçalves ricardobrg

View GitHub Profile
@ricardobrg
ricardobrg / post.md
Created Mar 12, 2020 — forked from vinicius73/post.md
["LÓGICA DE PROGRAMAÇÃO" É BOBAGEM, e explicarei porquê.]
View post.md

#["LÓGICA DE PROGRAMAÇÃO" É BOBAGEM, e explicarei porquê.]

Se preparem que o texto é longo.

Várias vezes chegam novatos aqui perguntando como começar, e a galera diz "estuda lógica primeiro, depois vai pra linguagem X". Vivo dizendo que é bobagem. Ontem, em particular, falei isso, e vieram várias pessoas por inbox me perguntar porquê (e uma pra me xingar, achando que falei por arrogância).

Pra facilitar, eu vou escrever uma boa explicação de porquê "lógica de programação" é furada, doa a quem doer, e postar na APDA e no fórum da EnergyLabs (para futuras referências, porque esse assunto vai voltar, ctz).

@ricardobrg
ricardobrg / price_qtd.php
Created Jan 27, 2020
Woocommerce price quantities
View price_qtd.php
add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' );
// Change and return $price_html variable using the $price and weight amount
function wb_change_product_html( $price ) {
$price_html = '<span class="amount">' . $price . ' per kg </span>'; // change weight measurement here
return $price_html;
}
add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' );
// Change the cart prices with $price variable and weight amount
View is_happening_now.js
function is_happening_now(talk) {
// take talk.datetime in ms from epoch
let talkTime = new Date(talk.datetime).getTime();
// calculate talkend in ms from epoch
let talkEnd = talkTime + (talk.duration * 60000);
// take current epoch time in browser`s timezone
let now = new Date().getTime();
// Return boolean true if talk is happening now or false.
return now > talkTime && now < talkEnd;
}
@ricardobrg
ricardobrg / logcat
Created Apr 3, 2019
Android 7.1.2 Google Pixel XL in AWS Device Farm
View logcat
--------- 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
@ricardobrg
ricardobrg / checkboxes.js
Last active Dec 2, 2018
jQuery checkboxes handling based on ids and classes with indeterminate property
View checkboxes.js
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 / fixed.js
Last active Oct 29, 2018
fixed sidebar with variable height
View fixed.js
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 / main.dart
Created Aug 7, 2018
Flutter app exit error
View main.dart
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 / maxlength.html
Created Jun 6, 2018
input number maxlength with javascript oninput
View maxlength.html
<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 / enqueue.php
Last active Apr 10, 2019
Enqueue scripts in WordPress with defer or async
View enqueue.php
<?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 / spinner.html
Created May 2, 2018
Pure CSS spinner loader
View spinner.html
<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;
You can’t perform that action at this time.