Skip to content

Instantly share code, notes, and snippets.

View nicksheffield's full-sized avatar

Nick Sheffield nicksheffield

View GitHub Profile
@nicksheffield
nicksheffield / edit_item.php
Created March 8, 2011 04:35
Edit in place using ajax and contenteditable
<?php
// quit script if you aren't accessing it with ajax
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) == false){
die();
}
// include database class
include('database.class.php');
<?php
class Base_controller extends CI_Controller {
function __construct(){
parent::__construct();
}
function _page($view,$data = false){
@nicksheffield
nicksheffield / gist:1218259
Created September 15, 2011 00:56 — forked from astorm/gist:992233
Fix console.log in Magento
jQuery(document).ready(function(){
fixConsole();
console.log('yo waddup');
});
function fixConsole(){
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
window.console = iframe.contentWindow.console;
@nicksheffield
nicksheffield / example.php
Created September 22, 2011 04:11
Testing changes on a live php site without disrupting users
<?php
# dogs is the text every other user will see.
# "cats" is what the developer sees...
# This way, only the developer can see changes, and if they want to show the client, they can.
?>
<h1>Heading!</h1>
<p>This is some text about <?php if(!isset($_GET['dev'])): ?>dogs<?php else: ?>cats<?php endif; ?>
@nicksheffield
nicksheffield / gist:1236690
Created September 23, 2011 03:32
Most evil javascript ever
(function(){
var elems = document.getElementsByTagName('*');
for(var i=-1;++i<elems.length;){
elems[i].style.fontFamily='"Comic Sans MS", "Comic Sans", cursive';
}
})();
// as a bookmarklet
javascript:(function(){var elems=document.getElementsByTagName('*');for(var i=-1;++i<elems.length;){elems[i].style.fontFamily='"Comic Sans MS", "Comic Sans", cursive';}})();
@nicksheffield
nicksheffield / gist:1371613
Created November 16, 2011 22:05
Magento: Get category image
<?php
function getCategoryImage($category) {
$categoryCollection = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->getCollection()->addAttributeToSelect('image')->addIdFilter($category->getId());
foreach($categoryCollection as $category) {
return $category->getImageUrl();
}
}
?>
@nicksheffield
nicksheffield / thumb_helper.php
Created March 16, 2012 00:04
Smart thumbnail generation
<?php
/*
Really useful for echoing with CI
*/
function generate_thumbnail($filename, $thumb_width, $thumb_height){
$path = 'uploads/'.$filename;
@nicksheffield
nicksheffield / expect.js
Created April 24, 2012 01:31
Short easy test function - inspired by Angular JS
function expect(value){
return {
val: value,
toBe: function(that){
if(this.val == that) return true;
else return false;
}
};
}
@nicksheffield
nicksheffield / fb.css
Last active June 21, 2018 16:04
Facebook custom styles (stylebot)
#blueBar {
background: -webkit-linear-gradient(#444, #111);
border-bottom: 1px solid #000;
border-top: 1px solid black;
box-shadow: 0 0 30px rgba(0,0,0,0.8) ;
height: auto;
position: fixed;
}
#blueBar a:hover {
@nicksheffield
nicksheffield / script.js
Created November 13, 2012 00:39
Ajax page slide+fade transition
$(document).ready(function(){
var currentOrderID = $('.nav .current a').parent().index()
$('[data-ajax]').on('click', 'a', function(e){
var target = $(e.target),
animSpeed = 200,
url = target.attr('href'),
newOrderID = target.parent().index()