Skip to content

Instantly share code, notes, and snippets.

View castroalves's full-sized avatar
🏠
Working from home

Cadu de Castro Alves castroalves

🏠
Working from home
View GitHub Profile
$estados = array( "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RO", "RS", "RR", "SC", "SE", "SP", "TO" );
@castroalves
castroalves / linkedin-mass-unfollow.js
Created July 7, 2020 15:40
Linkedin Mass Unfollow
(() => {
let count = 0;
function getAllButtons() {
return document.querySelectorAll('button.is-following') || [];
}
async function unfollowAll() {
const buttons = getAllButtons();
@castroalves
castroalves / pergaminho.php
Last active April 20, 2020 10:58
Solução do Pergaminho de Fasdal
<?php
/**
* Usage: run `php pergaminho.php` on Terminal
*
* @author Cadu de Castro Alves <https://github.com/castroalves>
*/
$encrypted_message = 'VNWRWJ BQJAXW YXBBDR BJWPDN ANJU. YANLRBJVXB MNUJ YJAJ ANBBDBLRCJA X NGNALRCX MN VXACXB N RWRLRJA J MNBCADRLJX CXCJU MN OJBMJU.';
$decrypted_message = 'FASDAL DE CU EH ROLA';
@castroalves
castroalves / acf-form-disable-post-content-settings.php
Created March 18, 2020 23:50
Disables tabs and media upload button in post content field. It also sets basic toolbar.
/**
* Disables tabs and media upload button in post content field
*
* @param $field
*
* @return mixed
*
* @author Cadu de Castro Alves <cadudecastroalves@gmail.com>
*/
function rpa_hub_disable_post_content_settings( $field ) {
@castroalves
castroalves / php-anonymous-function-in-arrays.php
Last active March 11, 2020 16:32
Small experiment using anonymous functions in arrays
<?php
$form = [
'action' => 'http://nextbike.com',
'target' => '_blank',
'method' => 'POST',
'fields' => [
['type' => 'text', 'name' => 'first_name', 'label' => 'First Name'],
['type' => 'text', 'name' => 'last_name', 'label' => 'Last Name'],
['type' => 'date', 'name' => 'birthday', 'label' => 'Birthday'],
/**
* Book CPT for testing purposes
*/
function cpt_book()
{
register_post_type(
'cpt_book',
array(
'labels' => array(
'name' => __('Books'),
@castroalves
castroalves / batches.json
Created November 1, 2019 14:05
Mailchimp API - Start a batch operation
{
"operations": [
{
"method": "DELETE",
"path": "lists/d8be282a42/members/0620517b07414ec8fd56ce1ed4ae3b72"
},
{
"method": "DELETE",
"path": "lists/dfce17dd1b/members/0620517b07414ec8fd56ce1ed4ae3b72"
}
@castroalves
castroalves / array-to-csv-using-for-vs-implode.php
Last active September 24, 2018 13:15
Performance Test: Array to CSV using For vs Implode
<?php
$arr_numbers = range(1,10000);
$total = count($arr_numbers);
$time_for = microtime(true);
$csv_for = '';
for($i = 0; $i < $total; $i++) {
if( $i == ($total - 1) ) {
/**
* Define Post Type labels.
*
* @return array Post Type labels.
*/
protected function labels() {
$default = array(
'name' => sprintf( __( '%ss', 'odin' ), $this->name ),
'singular_name' => sprintf( __( '%s', 'odin' ), $this->name ),
'view_item' => sprintf( __( 'View %s', 'odin' ), $this->name ),
@castroalves
castroalves / wp_post_publish_email_notify
Created August 6, 2013 18:38
WordPress Hook to Notify Users When New Post Was Published
/**
* Send E-mails When a New Post is Published
*/
function email_notify( $new_status, $old_status, $post ) {
// Avoids re-sending e-mails on update
if( $new_status == 'publish' && $new_status != $old_status ) {
$message = 'The post ' . $post->post_title . ' was published at ' . get_bloginfo('name');