Skip to content

Instantly share code, notes, and snippets.

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

Luis Felipe Zaguini zaguiini

🏠
Working from home
View GitHub Profile
@zaguiini
zaguiini / giftwrap-extensible-abilities.php
Created October 19, 2026 19:52
WooCommerce 11.3 extensible abilities: gift wrap example plugin (experimental API)
<?php
/**
* Plugin Name: Gift Wrap (extensible abilities example)
* Description: Adds a gift wrap price to WooCommerce's product abilities with the experimental extensible abilities API in WooCommerce 11.3.
* Version: 1.0.0
* Requires Plugins: woocommerce
*
* Turn on WooCommerce > Settings > Advanced > Features > Extensible abilities to try it.
*/
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function performanceURL(url, sampleSize, sleepMs = 1000) {
const performanceList = [];
for (let i = 0; i < sampleSize; i++) {
const t0 = performance.now();
await window.wpcom.request({ method: 'GET', path: url });
const t1 = performance.now();
performanceList.push(t1 - t0);
{"lastUpload":"2021-09-13T13:13:59.269Z","extensionVersion":"v3.4.3"}
@zaguiini
zaguiini / flatten-list.js
Last active January 14, 2020 14:34
How to flatten a list using reduce and recursion
const flattenList = (array) => {
return array.reduce((flat, next) => {
return flat.concat(Array.isArray(next) ? flattenList(next) : next)
}, [])
}
import { createStore } from 'easy-peasy'
const store = createStore({
todos: {
items: ['Create store', 'Wrap application', 'Use store'],
add: action((state, payload) => {
state.items.push(payload)
})
}
})
import React from 'react'
const Store = React.createContext()
const useStore = () => React.useContext(Store)
const reducer = (state, action) => {
switch(action.type) {
case 'ADD_TODO':
return { ...state, todos: [...state.todos, action.payload] }
@zaguiini
zaguiini / brick-wall.js
Last active December 2, 2019 03:22
Brick wall Leetcode solution
const wall = [
[1, 2, 2, 1],
[3, 1, 2],
[1, 2, 2],
[2, 4],
[3, 1, 2],
[1, 3, 1, 1]
]
const leastBricks = (wall) => {
@zaguiini
zaguiini / README.md
Last active November 2, 2019 22:45
Travis CI NPM workflow

Travis CI - NPM workflow

This workflow does, in the following order:

  • install your packages
  • run the lint command
  • run the test command
  • publishes the package with the version defined in the release tag
  • publishes the new version code on github (updates the package.json to match the latest tag)

It will only trigger the deploy phase on the master branch when there's the release tag present. Otherwise it will just build and test your files.

@zaguiini
zaguiini / selection-sort.js
Last active October 29, 2019 04:05
Selection sort in plain English
/*
Time complexity: O(nˆ2) since it has two nested loops
Space complexity: O(1) since it uses a reference to something that already exists and does not create new arrays
*/
const selectionSort = array => {
for (let arrayIndex = 0; arrayIndex < array.length - 1; arrayIndex++) {
let minIndex = arrayIndex
for (let subArrayIndex = arrayIndex + 1; subArrayIndex < array.length; subArrayIndex++) {
@zaguiini
zaguiini / getAge.js
Last active May 27, 2019 13:07
Return the age given the parameters
function getAge(month, day, year) {
const birthDate = new Date(year, month - 1, day)
const fromNow = new Date() - birthDate
const absoluteAge = new Date(fromNow).getFullYear()
// that's because timestamps starts from 1970, so
// we're getting relatively to that year
return Math.abs(absoluteAge - 1970)
}