Skip to content

Instantly share code, notes, and snippets.

View chardcastle's full-sized avatar

Chris Hardcastle chardcastle

  • London (England)
View GitHub Profile
@chardcastle
chardcastle / jwt-sign-verify.js
Created November 10, 2023 19:24
JWT Sign and Verify - good for API and APP respectfully. Where jsonwebtoken was buggy on client side
/**
* Example output
*
* # node user/jwt.js
* Generated JWT: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNjk5NjQ0MTczLCJleHAiOjE2OTk2NDc3NzMsImlzcyI6InVybjpleGFtcGxlOmlzc3VlciIsImF1ZCI6InVybjpleGFtcGxlOmF1ZGllbmNlIn0.qkYazhX0__WeBAjiW1MvXndqdBc4qsP-mX8vWIzCPwE
* Verified Payload: {
* sub: '1234567890',
* name: 'John Doe',
* iat: 1699644173,
* exp: 1699647773,
@chardcastle
chardcastle / gist:6fb037559e3cc90e0028
Last active August 29, 2015 14:09
Simple PHP checksum (legacy fix)
<?php
// Interesting legacy fix
//
// This works by replacing a collection of 10 blank spaces with a random character.
// However the \e modifier is deprecaited now, it needed replacing as it's hard to
// underststand without some notes.
//
// This line appears to come from http://php.net/manual/en/function.rand.php#86465
//
// $f->checksum = preg_replace('/([ ])/e', 'chr(rand(97,122))', ' ');
@chardcastle
chardcastle / gist:f3b5eedef975de8f28a3
Created October 20, 2014 09:55
Traverse array in batch YII Framework
<?php
/**
* Prototype method for traversing large records in batches
* using the YII framework.
*
* Completed stepper method for restoration rollback solution.
*
* @todo Include this in main restoartion rollback solution
* @return [type] [description]
*/
@chardcastle
chardcastle / gist:2d610f6208f893d9b52d
Created October 19, 2014 21:51
clear all blank lines from vim
:g/^$/d
# @see http://stackoverflow.com/questions/706076/vim-delete-blank-lines
@chardcastle
chardcastle / gist:9eff528a8752a05abfac
Created October 15, 2014 09:33
DateTime calculator
<?php
var_dump(DateTime::createFromFormat('d-m-Y','01-01-2013')->add(date_interval_create_from_date_string('2 years'))->format('d-m-Y'));
?>
@chardcastle
chardcastle / gist:9229799
Created February 26, 2014 13:54
Date subtraction PHP
<?php
$date = new DateTime('Europe/London');
$date->sub(DateInterval::createFromDateString('12 days'));
echo $date->format('d-m-y');
@chardcastle
chardcastle / build-couchdb-documents
Created February 20, 2014 10:25
Stash data away into couchdb (build script)
<?php
// Get a unique ID for document
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:5984/_uuids');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Accept: */*'
));
@chardcastle
chardcastle / get-all-images
Created September 2, 2013 09:04
Get all image src attributes in page
var imgs = document.getElementsByTagName("img");
for (x in imgs){
console.log('curl -O ' + imgs[x].src);
}
@chardcastle
chardcastle / gist:5965420
Created July 10, 2013 11:06
Search in files on mac terminal
// Find foo in javascript files within a folder called www
grep 'foo' -rl --include=\*.{js,h} www/
// Find bar in php files within a folder called www
grep 'bar' -rl --include=\*.{php,h} www/
@chardcastle
chardcastle / gist:5121364
Created March 8, 2013 23:44
Reset admin password on Wordpress 3.5.1
-- SQL to reset user password on wordpress 3.5.1 to 'tacoseven'
update wp_users set user_pass = '$P$BsrjScKnteWABdcJxOPgd7EepP7QME1' where user_login = 'admin';