Skip to content

Instantly share code, notes, and snippets.

View woganmay's full-sized avatar

Wogan May woganmay

View GitHub Profile
@woganmay
woganmay / activate-flarum-user.php
Created February 12, 2017 13:47
Activate an existing Flarum user
<?php
$api_url = "https://my.flarum.url/api/users/" . $userid; // See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
// This must be a token for a user with Administrator access
$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 / 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 / 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 / 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);
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
class Inspire extends Command
{
/**
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
@woganmay
woganmay / sample.php
Last active February 24, 2016 09:43
Everything in linfo v3.0.0
<?php
// http://wogan.me/2016/02/21/get-system-information-in-laravel-5-1/
$linfo = new \Linfo\Linfo;
$parser = $linfo->getParser();
$everything = [
'os' => $parser->getOS(),
'cpu' => $parser->getCPU(),
@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 / query.sql
Last active September 17, 2015 16:19
/** MS SQL */
SELECT
t.NAME AS TableName,
p.[Rows] AS NumRows
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id