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 / gist:9450312764a0fb3055165e3825631976
Created May 30, 2020 13:30
Browser crypto.subtle (SubtleCrypto) simple encrypt/decrypt
// derive string key
async function deriveKey(password) {
const algo = {
name: 'PBKDF2',
hash: 'SHA-256',
salt: new TextEncoder().encode('a-unique-salt'),
iterations: 1000
}
return crypto.subtle.deriveKey(
algo,
@lcherone
lcherone / index.md
Created May 19, 2019 05:53
Template variable replacement, js and php

In PHP

<?php
$vars = [
  'name' => 'Loz'
];

$template = 'Hello {{ name }}!';
@lcherone
lcherone / gist:5e2283e5659a2ebba1de09013ce223ba
Last active December 13, 2022 17:24
Express SPA history API express.static fallback

Mostly taken from: https://gitlab.com/sebdeckers/express-history-api-fallback, without all the repo/package fluff.

let staticPath = '/path/to/dist'

app.use(express.static(staticPath))

app.use('/', ((...args) => (req, res, next) => {
  if ((req.method === 'GET' || req.method === 'HEAD') && req.accepts('html')) {
(res.sendFile || res.sendfile).call(res, ...args, err =&gt; err &amp;&amp; next())
@lcherone
lcherone / lxc-start.sh
Created September 20, 2017 04:16
LXD Start all stopped containers
#!/bin/bash
#
# Start all stopped containers
#
# stop running containers
for container in $(lxc list volatile.last_state.power=STOPPED -c n --format csv); do
lxc start "$container"
done
@lcherone
lcherone / reelgood.md
Created January 8, 2018 18:09
Curl requests to access reelgood.com API

Curl requests to access reelgood.com API

<?php
$options = [
    'nocache' => 'true',
    'kind' => 0,
    'minimumScore' => 0,
    'sources' => [
        'amazon_prime',

'fx_tveverywhere',

@lcherone
lcherone / disposable-email-provider-domains
Last active December 26, 2021 19:02
List of disposable email provider domains
0815.ru
0815.ru0clickemail.com
0815.ry
0815.su
0845.ru
0clickemail.com
0-mail.com
0wnd.net
0wnd.org
10mail.com
@lcherone
lcherone / lxc-exec-all.sh
Created September 20, 2017 04:30
LXD run command in all running containers
#!/bin/bash
#
# Run command in all running containers
# Usage: $ ./lxc-exec-all.sh apt update && apt upgrade
#
for container in $(lxc list volatile.last_state.power=RUNNING -c n --format csv); do
lxc exec "$container" "$@"
done
@lcherone
lcherone / cron.php
Last active November 27, 2021 11:23
CRON PHP Daemon
#!/usr/bin/php
<?php
/**
* Need to test code works on ©Win"virus"dow$
*
* Aim:
* To run code within a cron task at a settable frequency above 1 per minute,
* but not overrun the minute or run again if already running, tasks should
* also complete at their own pace within the minute.
*
@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 {