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 / deploy-static.ps1
Created June 1, 2011 22:48
Upload files (recursive) via powershell
## Automate FTP uploads
## Go to destination
cd C:\Test
$location = Get-Location
"We are here: $location"
## Get files
$files = Get-ChildItem -recurse
## Get ftp object
$ftp_client = New-Object System.Net.WebClient
$ftp_address = "ftp://user:pass@adress:/home/chardcastle/test"
@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';
@chardcastle
chardcastle / gist:4220130
Created December 5, 2012 22:36
eCommerce order complete process
<?php
// Decode the Crypt field and extract the results
$sagePay = new SagePay_Util();
$strDecoded = $sagePay->decodeAndDecrypt($strCrypt);
$values = $sagePay->getToken($strDecoded);
// Fire a range of actions
$listeners = array(
"Application_Model_Order", // Add order to database
"SagePay_Order", // Update order with payment information
@chardcastle
chardcastle / kohana-1.3.1-snippets
Created September 12, 2011 12:17
Kohana 1.3.1 useful snippets
// Get current controller
Request::current()->controller();
// Throw errors
throw new Http_Exception_404('File not found!');
throw new Http_Exception_500('Server tantrum');
// Last query
ORM::factory([MODEL_NAME])->last_query();
@chardcastle
chardcastle / non-console-browser-support
Created September 7, 2011 08:29
Console safety for IE
// code yanked from the Yahoo media player. Thanks, Yahoo.
// via http://ajaxian.com/archives/graceful-degradation-of-firebug-console-object
if (! ("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group"
, "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i <names.length; ++i) window.console[names[i]] = function() {};
}
@chardcastle
chardcastle / deferred jquery
Created August 15, 2011 23:19
Deferred objects with jQuery
$.post(ENV.app_url+"/tab/answer", data, function(json){
// create a deferred object
var dfd = $.Deferred();
var action = {
add_response: function(json){
console.log('added message');
$("#question_response")
.html(json.message)
},
refresh_cufon: function(){
sed -e 's/searchString/replacementString/g' target.txt > destination.txt