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: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
@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 / ff_fix_button.css
Created May 25, 2011 13:45
Fix firefox two pixel button
@-moz-document url-prefix() {
#frm_contact_submit {
padding: 0 0 2px 8px !important;
}
}
@chardcastle
chardcastle / read-xml.cs
Created March 28, 2011 14:12
File an xml file locally off disk
/*
* Read the Homepage XML file and get the snippets
* from file
*/
public List<string> get_homepage_snippets()
{
List<string> snippets = new List<string>();
XmlTextReader reader = new XmlTextReader(Server.MapPath("~/Data/homepage.xml"));
while (reader.Read())
@chardcastle
chardcastle / gist:884987
Created March 24, 2011 12:40
Recover deleted files
// from http://thefinerstuff.posterous.com/git-saved-my-day-restore-accid
git ls-files -d | xargs git checkout --
@chardcastle
chardcastle / blank.html
Created March 16, 2011 22:43
HTML file template
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Site name</title>
</head>
<body></body>
</html>