Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env php
<?php
$file = $argv[1];
$contents = file_get_contents($file);
/** @var $patterns */
$patterns = [
/** @lang PhpRegExp */
'~<\?=[ ]?([^?]+);?[ ]?\?>~m' => '{{ $1 }}',
@lcherone
lcherone / input.scss
Last active July 8, 2021 18:29
Generated by SassMeister.com.
.nav {
nav-prop: 1;
.parent-class {
parent-prop: 1;
&.sibling-class {
grand-child-prop: 1;
.grand-child-class {
@lcherone
lcherone / php.js
Created March 3, 2021 19:38
phpjs
function abs(mixed_number) {
return Math.abs(mixed_number) || 0;
}
function acos(arg) {
return Math.acos(arg);
}
function acosh(arg) {
return Math.log(arg + Math.sqrt(arg * arg - 1));
@lcherone
lcherone / file.php
Last active January 2, 2021 20:20
manual wordpress serialize fixer
<?php
$str = 'a:1:{s:3:"foo";s:23:"https://beta.domain.com";}';
echo serialize(json_decode(str_replace('beta.domain.com', 'domain.com', json_encode(unserialize($str))), true));
// a:1:{s:3:"foo";s:18:"https://domain.com";}
@lcherone
lcherone / script.js
Last active December 12, 2020 00:41
Minio Migrate All - Script to migrate all buckets and files from one S3 server to another.
/**
* S3 migration script
*
* Use this script to migrate all buckets and files from one S3 server to another.
*
* Author: Lawrence Cherone
*/
const HOSTS = {
from: {
@lcherone
lcherone / index.js
Created October 29, 2020 23:23
range js
const range = (start, end, step) => {
const range = []
typeof step === 'undefined' && (step = 1)
if (end < start) step = -step
while (step > 0 ? end >= start : end <= start) {
range.push(start)
start += step
}
return range
}
@lcherone
lcherone / script.js
Created July 11, 2020 19:06
js async queue
const queue = []
Object.defineProperty(queue, 'push', {
configurable: true,
enumerable: false,
writable: true,
value: function (...args) {
console.log('queue changed')
if (typeof args[0] === 'function') args[0]()
return Array.prototype.push.apply(this, args)
}
@lcherone
lcherone / script.js
Created June 27, 2020 01:31
asynchronous IIAFE in a for loop, with step timing
console.log('asynchronous IIAFE in a for loop, with step timing')
for (let i = 0; i <= 10; i++)
setTimeout(
async () =>
(async function (index) {
console.log(index)
})(i),
i * 250
)
@lcherone
lcherone / script.js
Last active June 26, 2020 23:58
Javascript merge multiple arrays, de-duped by property name, O(N1) using reduce
const array1 = [
{ name: 'a', creationDate: new Date() },
{ name: 'b', creationDate: new Date() },
]
const array2 = [
{ name: 'a', creationDate: new Date() },
{ name: 'c', creationDate: new Date() },
]
const mergeBy = (...arrays) => {
@lcherone
lcherone / script.js
Last active June 27, 2020 00:15
JavaScript, merge 2 arrays of objects, remove dupes, irrelevant of length, keys or reference
/*
You saw it here first, out of the 8k dupes on stackoverflow, none address diff length b array, diff keys or reference.
Leave a comment if you know a better way
*/
const a = [{ a: 'a' }, { b: 'b' }];
const b = [{ a: 'a' }, { c: 'c' }, { x: 'x' }, {}];
const merge = (a, b) => [
...new Set([