Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar

Luiz Bills luizbills

View GitHub Profile
@luizbills
luizbills / code.js
Created April 21, 2024 23:52
Draw a cube in canvas #litecanvas
litecanvas()
function init () {
loadScript('https://unpkg.com/@litecanvas/plugin-more-shapes/dist/dist.js', (res) => {
if (res) plugin(pluginMoreShapes)
})
size = 100
x = WIDTH/2 - size/2
y = HEIGHT/2 - size/2
@luizbills
luizbills / code.js
Created April 9, 2024 02:12
move points towards a angle #litecanvas #gamedev
litecanvas();
const max = 3
const dist = 360 / max
function init () {
x = CENTERX
y = CENTERY
a = 0
}
@luizbills
luizbills / code.php
Last active March 26, 2024 15:40
Change message of "WooCommerce Force Authentification Before Checkout" plugin
<?php
/*
english: put the below code in your functions.php
português: coloque o código abaixo no seu functions.php ou siga este guia: https://bit.ly/2Nn0SvD
*/
add_filter( 'wc_force_auth_message', function ( $message ) {
return 'your new message/sua nova mensagem';
} );
@luizbills
luizbills / mini-jquery.js
Last active February 16, 2024 12:30
jQuery-inspired DOM manipulation using modern JavaScript
const $ = (selector, root = document) => root.querySelector(selector);
const $$ = (selector, root = document) => root.querySelectorAll(selector);
const on = (el, evt, cb, opts) => el.addEventListener(evt, cb, opts);
const once = (el, evt, cb) => el.addEventListener(evt, cb, { once: true });
const off = (el, evt, cb) => el.removeEventListener(evt, cb);
@luizbills
luizbills / code.php
Created February 14, 2024 16:58
Make a woocommerce coupon valid only in certain period of the day
<?php
/**
* @param bool $is_valid
* @param \WC_Coupon $coupon Coupon data.
* @return bool
*/
add_filter( 'woocommerce_coupon_is_valid', function ( $is_valid, $coupon ) {
if ( ! $is_valid ) return false;
@luizbills
luizbills / code.php
Last active December 28, 2023 13:36
Validar CPF ou CPNJ
<?php
function is_cnpj ( $value ) {
// extrai somente os números
$cnpj = \preg_replace( '/[^0-9]/', '', (string) $value );
// valida o tamanho
if ( strlen( $cnpj ) !== 14 ) return false;
// verifica se todos os digitos são iguais
if ( preg_match( '/(\d)\1{13}/', $cnpj ) ) return false;
// valida primeiro dígito verificador
@luizbills
luizbills / code.php
Last active December 18, 2023 20:09
WordPress CPT Model
<?php
/**
* Model to manipulate posts in WordPress
* @abstract
*/
abstract class Post_Model {
/**
* @var \WP_Post $post
*/
@luizbills
luizbills / readme.md
Created December 14, 2023 23:20 — forked from xem/readme.md
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@luizbills
luizbills / main.php
Last active December 2, 2023 16:58
Custom shipping method for WooCommerce (minimal boilerplate required)
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Hooks
add_action( 'plugins_loaded', 'yourprefix_include_shipping_method' );
add_action( 'woocommerce_shipping_methods', 'yourprefix_register_shipping_method' );
@luizbills
luizbills / guide.md
Last active December 2, 2023 15:48
Manually install linux applications desktop files

Manually install linux applications desktop files

Create a desktop file:

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/home/path/to/app/binary