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 / 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: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: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: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 / 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,