Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Relequestual
Relequestual / gist:5583353
Last active December 17, 2015 08:49
Get total count for use with pagination for MySQL
//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 March 28, 2013 14:22
Magento files for question posted on stackoverflow
<?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();
@Relequestual
Relequestual / robot.js
Created December 6, 2012 09:13
Zolmeister
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 / robot.js
Created December 6, 2012 09:13
Zolmeister
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 November 16, 2012 16:09
Run multiple sql queries with CodeIgniter migrations
/*
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 September 20, 2012 13:52
Remove hidden character copied from Adobe (Ps, Ai) from mysql database
# Replace TABLE and COLUMN as appropriate
Update TABLE Set COLUMN = Replace(COLUMN, CHAR(3), '');
@Relequestual
Relequestual / helper.js
Created September 5, 2012 10:46
Remove helper text when given focus and re-display helper text when loose focus and empty
$("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 March 28, 2012 22:11
Split a string which starts with lowercase then uses camel case from first capital letter.
<?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 March 18, 2012 19:00 — forked from RonnyO/localive.js
Conditional loading of live.js for dev environments
// 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 February 19, 2012 22:33
CodeIgniter blog_model pisyek tut
<?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();