Skip to content

Instantly share code, notes, and snippets.

View Cauen's full-sized avatar
🎯
Focusing

Cauê Nolasco Cauen

🎯
Focusing
View GitHub Profile
@Cauen
Cauen / ajax_and_no_ajax_wp_plugin_options_page.php
Last active August 31, 2019 23:37
Ajax and no Ajax WP Options Page - Multiple DB Options
<?php
add_action('wp_ajax_save_i9_analytics_options', 'save_i9_analytics_options');
add_action('wp_ajax_nopriv_save_i9_analytics_options', 'save_i9_analytics_options');
function save_i9_analytics_options()
{
if (!empty($_POST)) {
$i9_heap_id = $_POST["i9_heap_id"];
$i9_mixpanel_id = $_POST['i9_mixpanel_id'];
$i9_amplitude_id = $_POST['i9_amplitude_id'];
@Cauen
Cauen / ajax_wp_plugin_options_page_unique_option.php
Last active September 1, 2019 00:10
Ajax Options Page - Unique DB Option
<?php
add_action('wp_ajax_save_i9_analytics_options', 'save_i9_analytics_options');
function save_i9_analytics_options()
{
if (!empty($_POST)) {
$i9_analytics_data = $_POST["data"];
update_option('i9_analytics_integration_data', json_encode($i9_analytics_data));
echo "OK";
wp_die();
@Cauen
Cauen / ajax_wp_plugin_options_page_unique_option_dynamic_fields_css.php
Created September 1, 2019 15:16
Ajax Options Page - Unique DB Option - CSS - Dynamic Fields
<?php
add_action('wp_ajax_save_i9_analytics_options', 'save_i9_analytics_options');
function save_i9_analytics_options()
{
var_dump($_POST);
if (!empty($_POST)) {
$i9_analytics_data = $_POST;
update_option('i9_analytics_integration_data', json_encode($i9_analytics_data));
@Cauen
Cauen / docker-swarm-traefik-subdomain-forcehttps.yml
Last active May 16, 2020 16:12
Docker Swarm + Traefik (Global Redirection & Subdomain & Auth to view Dashboard) + 2 backends
# Is needed to add A records to the address of the network
# Cname with * wildcard would be good
version: '3'
services:
traefik:
image: traefik:v2.0.0
command:
- --api.insecure=false # set to 'false' on production
@Cauen
Cauen / gist:eab04bf191d0980f18f87cf865c71741
Created May 29, 2020 20:42
Docker Swarm + Portainer + Traefik (Global Redirection & Subdomain & Auth to view Dashboard) + 2 backends
version: '3'
services:
traefik:
image: traefik:v2.0.0
command:
- --api.insecure=false # set to 'false' on production
- --api.dashboard=true # see https://docs.traefik.io/v2.0/operations/dashboard/#secure-mode for how to secure the dashboard
- --api.debug=true # enable additional endpoints for debugging and profiling
- --log.level=DEBUG # debug while we get it working, for more levels/info see https://docs.traefik.io/observability/logs/
@Cauen
Cauen / adminbro-translation-ptbr.js
Last active June 29, 2021 18:46
Adminbro portuguese configuration file (translated all strings to brazilian portuguese)
// Unfortunately the singular and plural are having problems in my version of admin bro, and therefore should be updated if yours is already working
export const translations = {
actions: {
new: 'Criar novo',
edit: 'Editar',
show: 'Mostrar',
delete: 'Deletar',
bulkDelete: 'Deletar tudo',
list: 'Listagem',
@Cauen
Cauen / parse-google-sheet-or-spreadsheet-data-copied-to-clipboard-to-json-object-array-of-objects.ts
Last active March 29, 2023 10:21
Parse Google Sheet or Spreadsheet Data Copied to Clipboard to JSON Object (Array of Objects)
const fake = 'Name\tAge\t\t\nEmanuel\t18\t\t\nCauê\t13\t\t\n\t\t\t\n\t\t\t'
const data = prompt("Digite o conteúdo") || fake
const splitInRows = (data: string): string[] => data.split("\n")
const isEmptyRow = (data: string): boolean => data.replaceAll('\t', '').length === 0
const splitRowInColumns = (row: string): string[] => row.split("\t")
const splitRowsInColumns = (rows: string[]) => rows.map(row => splitRowInColumns(row))
const getFilledColumnsIndexes = (headerRow: string[]): number[] => headerRow.reduce((prev, curr, currentIndex) => (curr.trim()) ? [...prev, currentIndex] : prev, [] as number[])
const keepOnlySpecificIndexesInArray = (row: string[], indexes: number[]): string[] => indexes.map(index => row[index])
const cleanifyRows = (rows: string[][], indexesToKeep: number[]) => rows.map(row => keepOnlySpecificIndexesInArray(row, indexesToKeep))
@Cauen
Cauen / how-to-expose-zustand-immer-to-update-any-field-inside-components.md
Created July 14, 2022 02:25
Expose Zustand Immer to Update Any Part of Store inside Components

Why?

In examples, we dont know how to use immer outside of the store implementation. Here's how to.

// store.ts
import { immer } from 'zustand/middleware/immer'
import { CreateOneShopOrderFromCheckoutInput } from '@/graphql/generated'
import { WritableDraft } from 'immer/dist/internal'
/*
## Open [https://scriptkit.com](https://scriptkit.com) in your browser
*/
// Name: ScriptKit.com
// Description: Launch scriptkit.com in your browser
// Author: John Lindquist
// Twitter: @johnlindquist
// Note: Feel free to delete this script!
// Name: Port kill
// Description: Enter port number to kill process listening on port.
// Author: kyo young
// GitHub:
import '@johnlindquist/kit';
const killPort = await npm('kill-port');
const port = await arg('Enter port to kill')
const containerClassName = 'flex justify-center items-center text-4xl h-full'