Skip to content

Instantly share code, notes, and snippets.

View woganmay's full-sized avatar

Wogan May woganmay

View GitHub Profile
@woganmay
woganmay / auth.php
Created February 12, 2017 13:38
PHP CURL code to authenticate with Flarum API
<?php
// Details to access Flarum
$api_url = "https://my.forum.url/api/token";
$username = "my_flarum_user";
$password = "my_flarum_pass";
// CURL call
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@woganmay
woganmay / new-flarum-user.php
Last active March 9, 2024 20:34
Use the Flarum API to create a new user
<?php
$api_url = "https://my.flarum.url/api/users";
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
// This must be a token for a user with Administrator access
$new_username = "johnsmith";
$new_password = "password1234";
$new_email = "john.smith@example.org";
@woganmay
woganmay / iam-policy.json
Created January 3, 2017 23:48
IAM policy to grant a user narrow access to one S3 bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
@woganmay
woganmay / squash.php
Created January 5, 2016 12:13
Use PHP to flatten a multidimensional stdClass object (like a json_decode result)
<?php
function squash($array, $prefix = '')
{
$flat = array();
$sep = ".";
if (!is_array($array)) $array = (array)$array;
foreach($array as $key => $value)
@woganmay
woganmay / TWR.js
Created December 13, 2016 11:02
Modified Dietz TWR calculation
function twr(transactions, roundingFactor, emv)
{
// beginning market value
var bmv = 0;
// Sort by date
transactions.sort(function(a, b){
var da = new Date(a.date);
var db = new Date(b.date);
@woganmay
woganmay / set-flarum-cookie.php
Created February 12, 2017 13:54
Set the flarum_remember cookie from a GET parameter
@woganmay
woganmay / gist:de9bf6da8d23117e3f932c546f0581ae
Last active March 6, 2021 18:20
Setting up nginx + rtmp

This was all done on a Debian Linux server.

Speedtest

Install speedtest-cli by:

sudo easy_install speedtest-cli

That gives you a one-line command to run up/down tests via speedtest.net. To hit a specific server, check the main list at https://www.speedtest.net/speedtest-servers.php and provide the ID to test against:

@woganmay
woganmay / hook.sh
Created June 25, 2020 08:48
Cache node_modules between envoyer.io deploys
#
# Use cached node_modules for faster frontend compile times
# on envoyer.io
#
# Rationale: If you don't want to set up node_modules caching on
# every server you deploy to, this drop-in deployment hook serves
# a similar purpose. It will symlink every new release to a shared
# node_modules folder, cutting out the installation time.
#
@woganmay
woganmay / bitbucket-pipelines.yml
Created September 11, 2019 20:41
Bitbucket CI Pipeline - Deploy Laravel Vapor
# Prerequisites:
# 1. Have the laravel/vapor-cli dependency in your project, so that composer install catches it
# 2. Set the VAPOR_API_TOKEN environment variable to your Vapor API key
# Details in the documentation: https://docs.vapor.build/1.0/projects/deployments.html#deploying-from-ci
# This pipeline will build a PHP 7.2 environment with dependencies, run the standard
# phpunit tests, then deploy to the staging environment on Vapor.
image: php:7.2.22-alpine
@woganmay
woganmay / Harvest.gs
Created August 24, 2019 17:22
Read Harvest timesheet data into a Google Sheet
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Integrations')
.addItem('Fetch Harvest', 'fetchHarvestData')
.addToUi();
}
function fetchHarvestData() {
// Update monthly, or read from another sheet