Skip to content

Instantly share code, notes, and snippets.

@pwFoo
pwFoo / AuthService.php
Created March 31, 2020 19:09 — forked from apiraino/AuthService.php
Simple static token authentication with Directus API
<?php
declare(strict_types=1);
use Directus\Services\AuthService as DirectusAuthService;
use Directus\Authentication\Exception\UserNotFoundException;
class AuthService
{
private function getToken($req)
@pwFoo
pwFoo / Encryption.js
Created May 9, 2020 13:04 — forked from ve3/Encryption.js
Encrypt and decrypt between programming languages (PHP & JavaScript).
/**
* Encryption class for encrypt/decrypt that works between programming languages.
*
* @author Vee Winch.
* @link https://stackoverflow.com/questions/41222162/encrypt-in-php-openssl-and-decrypt-in-javascript-cryptojs Reference.
* @link https://github.com/brix/crypto-js/releases crypto-js.js can be download from here.
*/
class Encryption {
@pwFoo
pwFoo / README.md
Created May 9, 2020 19:57 — forked from saulshanabrook/README.md
Saving Web Crypto Keys using indexedDB

This is a working example on how to store CryptoKeys locally in your browser. We are able to save the objects, without serializing them. This means we can keep them not exportable (which might be more secure?? not sure what attack vectors this prevents).

To try out this example, first make sure you are in a browser that has support for async...await and indexedDB (latest chrome canary with chrome://flags "Enable Experimental Javascript" works). Load some page and copy and paste this code into the console. Then call encryptDataSaveKey(). This will create a private/public key pair and encrypted some random data with the private key. Then save both of them. Now reload the page, copy in the code, and run loadKeyDecryptData(). It will load the keys and encrypted data and decrypt it. You should see the same data logged both times.

Minio on GlusterFS Volume Guide

This document provides instructions on how to serve a GlusterFS volume across multiple Minio instances. There are no special configuration changes required to enable this feature. Access to files stored on GlusterFS volume are locked and synchronized by default.

Download Minio

Visit here to download binary for your operating system.

Mount GlusterFS

@pwFoo
pwFoo / 00README.md
Created September 18, 2020 21:07 — forked from mwpastore/00README.md
Lightning Fast WordPress: Caddy+Varnish+PHP-FPM

README

This gist assumes you are migrating an existing site for www.example.com — ideally WordPress — to a new server — ideally Ubuntu Server 16.04 LTS — and wish to enable HTTP/2 (backwards compatibile with HTTP/1.1) with always-on HTTPS, caching, compression, and more. Although these instructions are geared towards WordPress, they should be trivially extensible to other PHP frameworks, other FastCGI backends, and even non-FastCGI backends (using proxy in lieu of fastcgi in the terminal Caddyfile stanza).

Quickstart: Use your own naked and canonical domain names instead of example.com and www.example.com and customize the Caddyfile and VCL provided in this gist to your preferences!

These instructions target Varnish Cache 4.1, PHP-FPM 7.0, and Caddy 0.10. (I'm using MariaDB 10.1 as well, but that's not relevant to this guide.)

@pwFoo
pwFoo / event-source.html
Created October 18, 2020 19:44 — forked from lukemorton/event-source.html
EventSource: The Glorified Long Polling Machine
Open your console.
<script src="event-source.js"></script>
<?php
/**
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Data;
use Psr\Cache\CacheInterface;
@pwFoo
pwFoo / Static python executable.txt
Created January 10, 2021 19:24 — forked from 0xhexmex/Static python executable.txt
How to turn a python script into a statically linked executable with pyinstaller and staticx
// Example below is with mitm6 (https://github.com/fox-it/mitm6/)
// Note: Adding the '--add-binary' option here is specific to mitm6, not required in all cases.
# pip install pyinstaller
# pyinstaller --clean -F --add-binary="/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0:." ./mitm6.py
// The step above will create a single binary in the ./dist/ directory called mitm6
// Install staticx and dependencies
/**
* Produces a function which uses template strings to do simple interpolation from objects.
*
* Usage:
* var makeMeKing = generateTemplateString('${name} is now the king of ${country}!');
*
* console.log(makeMeKing({ name: 'Bryan', country: 'Scotland'}));
* // Logs 'Bryan is now the king of Scotland!'
*/
var generateTemplateString = (function(){
@pwFoo
pwFoo / graph.js
Created April 11, 2021 21:04 — forked from alterx/graph.js
GunDB useful resources
// Dletta has implemented a depth-first (and sort of breadth-first) search algorithm for gun graphs.
var stack;
var nodes;
var edges;
var start;
var u;
var label;
var opt = true;