Skip to content

Instantly share code, notes, and snippets.

View samthomson's full-sized avatar

Sam Thomson samthomson

View GitHub Profile
@samthomson
samthomson / filter.php
Created November 5, 2014 09:48
laravel - filter to minify output
App::after(function($request, $response)
{
// HTML Minification
if(!Config::get('app.debug'))
{
if($response instanceof Illuminate\Http\Response)
{
$output = $response->getOriginalContent();
// Clean comments
$output = preg_replace('/<!--([^\[|(<!)].*)/', '', $output);
@samthomson
samthomson / filters.php
Created August 16, 2015 09:16
Case insensitive routing in laravel
App::before(function($request)
{
// if any characters in the route path are uppercase
if(ctype_upper(preg_replace('/[^\da-z]/i', '', $request->path()))){
// extract the path section of the url (the route) from the url and convert it to lowercase
$sNewRelativePath = str_replace($request->path(), strtolower($request->path()), $request->fullUrl());
// now redirect the user with a 301 to the lower case route
return \Illuminate\Support\Facades\Redirect::to($sNewRelativePath, 301);
}
});
@samthomson
samthomson / gist:f0e521bb2bc5bdeb720230a0cfcfa269
Created April 17, 2017 14:11
rebase a feature branch to it's initial state
# git rebase i expects a commit hash as an argument, but will rebase from after that commit. This will effectively rebase from before the commit.
git rebase -i `git merge-base feature master`
@samthomson
samthomson / convert.js
Created April 22, 2017 08:32
ffmpeg video conversion
var start = new Date();
var ffmpeg = require('fluent-ffmpeg');
var path = require('path');
const outputFolder = './out';
let outputName = 'gopro';
let outputPath = path.join(outputFolder, outputName);
let inputPath = './seed-videos/MAH04656.MP4'
@samthomson
samthomson / phpunit_testing
Created April 22, 2017 20:55
run a single phpunit test
phpunit --filter {FUNCTION_NAME} {test_folder}/{test_file_no_extension}
### Keybase proof
I hereby claim:
* I am samthomson on github.
* I am samt (https://keybase.io/samt) on keybase.
* I have a public key ASBlJWdtvAUFjO3u0HEra363rFRTZH5cvK70C6AiBgvpMgo
To claim this, I am signing this object:
`sudo mount /dev/mapper/data-root /mnt`
from https://support.system76.com/articles/pop-recovery/
@samthomson
samthomson / gist:6484431d0e8b097c3f52b345f8fe70cf
Created September 25, 2020 08:45
add hmac signed url to header
add hmac signed url to header. requires a variable to be set on collection. replace key with whatever.
```
pm.request.headers.add({
key: 'sign',
value: CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA512(request['url'], pm.collectionVariables.get("SECRET")))
});
```
@samthomson
samthomson / Bittrex_API_V3_Postman_Pre-request_script.md
Last active September 27, 2020 14:10
Bittrex API V3 Postman Pre request script

Assumes a BITTREX_API_KEY and BITTREX_API_SECRET is set on the collections variables.

// set up vars
let timestamp = new Date().getTime()
let url = request['url']
let method = request['method']
let contentHash = CryptoJS.SHA512(request['data']).toString(CryptoJS.enc.Hex);

var preSign = [timestamp, url, method, contentHash, ''].join('');
var signature = CryptoJS.HmacSHA512(preSign, pm.collectionVariables.get("BITTREX_API_SECRET")).toString(CryptoJS.enc.Hex);
@samthomson
samthomson / gist:bbafca1a5caaececf043d751a6b610c1
Created November 18, 2020 13:17
node: write object to local json file
import * as fs from 'fs'
fs.writeFileSync('response.json', JSON.stringify(result))