Skip to content

Instantly share code, notes, and snippets.

View chardcastle's full-sized avatar

Chris Hardcastle chardcastle

  • London (England)
View GitHub Profile
sed -e 's/searchString/replacementString/g' target.txt > destination.txt
@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(){
@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 / 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 / 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 / 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: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 / 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 / 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 / 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');