Skip to content

Instantly share code, notes, and snippets.

Ben Hutton Relequestual

Block or report user

Report or block Relequestual

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Relequestual
Relequestual / gist:5583353
Last active Dec 17, 2015
Get total count for use with pagination for MySQL
View gist:5583353
//if your query is raw sql you created, each mysql key word must be on a new line for this to work
$last_query = $this->db->last_query();
$pattern = '/(.*)Limit (.*)/i';
$new_query = preg_replace ($pattern, '', $last_query);
$pattern = '/(.*)Select *(.*)/i';
$new_query = preg_replace ($pattern, 'SELECT \'\'', $new_query);
$new_query = 'Select Count(*) AS res From (' . $new_query . ') v__dynamic;';
@Relequestual
Relequestual / Onepage.php
Created Mar 28, 2013
Magento files for question posted on stackoverflow
View Onepage.php
<?php
class CheckTest_Model_Checkout_Type_Onepage extends Mage_Checkout_Model_Type_Onepage{
public function saveTestCheck($data){
//echo 'lalala';exit;
if (empty($data)) {
return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
}
$this->getQuote()->setTestCheckLike($data['like']);
$this->getQuote()->collectTotals();
View robot.js
var Robot = function(robot){
robot.turnLeft(robot.angle % 90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
robot.ahead(1);
robot.turnGunRight(1);
}
else {
View robot.js
var Robot = function(robot){
robot.turnLeft(robot.angle % 90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
robot.ahead(1);
robot.turnGunRight(1);
}
else {
@Relequestual
Relequestual / migrations.php
Created Nov 16, 2012
Run multiple sql queries with CodeIgniter migrations
View migrations.php
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.
*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
@Relequestual
Relequestual / remove.sql
Created Sep 20, 2012
Remove hidden character copied from Adobe (Ps, Ai) from mysql database
View remove.sql
# Replace TABLE and COLUMN as appropriate
Update TABLE Set COLUMN = Replace(COLUMN, CHAR(3), '');
@Relequestual
Relequestual / helper.js
Created Sep 5, 2012
Remove helper text when given focus and re-display helper text when loose focus and empty
View helper.js
$("input, textarea").focus(function(){
if ($(this).val() == $(this).attr("title")) {
$(this).val("");
}
}).blur(function () {
if ($(this).val() == "") {
$(this).val($(this).attr("title"));
}
});
@Relequestual
Relequestual / gist:2230990
Created Mar 28, 2012
Split a string which starts with lowercase then uses camel case from first capital letter.
View gist:2230990
<?php
/*
/ Created while using the Last.FM API.
/ The Last.FM API is split into sections. Artists, Album, Track etc.
/ The method names are for example "artists.getTopTracks". If I'm using magic method __call
/ and calling artistsGetTopTracks, I can then split the call down into the section and method with the following regex
/ which can then be used to construct API call URL
*/
preg_match_all('/^[a-z]*|[A-Z]\w*/', $candidate, $results);
@Relequestual
Relequestual / localive.js
Created Mar 18, 2012 — forked from RonnyO/localive.js
Conditional loading of live.js for dev environments
View localive.js
// Load live.js on local envs only
// Make sure the path is right and your dev env passes the test.
/* Delete these characters to disable it temporarily -> */
(function() {
if(/^https?:\/\/(localhost|127.0.0.1|(dev|test).*?)\/|^file:\/\/\//.test(document.location.href)) {
var live = document.createElement('script');
live.src = 'js/live.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(live, s);
@Relequestual
Relequestual / blog_model.php
Created Feb 19, 2012
CodeIgniter blog_model pisyek tut
View blog_model.php
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog_model extends CI_Model {
function __construct() {
parent::__construct();
//var_dump(get_instance()); exit;
// $CI = get_instance();
// $CI->load->database();
You can’t perform that action at this time.