Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@rbk
rbk / common.js
Last active August 29, 2015 14:07
Pre load images
// Page this function a javascript array of image urls to preload them!
function pre_load_images(images){
for( var i=0; i < images.length; i++ ){
var img_new = document.createElement('img');
img_new.setAttribute( 'src', images[i] );
img_new.setAttribute( 'style', 'display:none;' );
document.body.appendChild(img_new)
}
}
@rbk
rbk / gist:9878aaeaab45e7f29a99
Created October 7, 2014 07:24
Awesome git logging! Paste this in terminal and check logs with: git lg
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@rbk
rbk / Gruntfile.js
Last active August 29, 2015 14:08
Sample grunt configuration files for processing sass and compressing javascripts
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'css/app.css' : 'scss/app.scss'
@rbk
rbk / siderbar-metabox.php
Created November 6, 2014 19:02
Adds dropdown menu of navigation menus from the Wordpress menu system to page edit screens.
<?php
/**
* Adds a box to the main column on the Post and Page edit screens.
*/
function myplugin_add_meta_box() {
$screens = array( 'page' );
foreach ( $screens as $screen ) {
@rbk
rbk / nav.js
Last active September 14, 2015 16:43
$(window).scroll(function(){
if( $(window).scrollTop() >= $('#site-navigation').height() ){
$('#site-navigation').css({position : 'fixed', top: '0', 'z-index' : 9, width: '100%'});
} else {
$('#site-navigation').css({position : 'relative'});
}
});
@rbk
rbk / functions.php
Created January 22, 2015 22:58
Overrides NGG shortcode. Example for query.
function gurustu_slideshow_override( $atts, $content = null ) {
global $wpdb;
$atts = shortcode_atts( array(
'id' => '0',
), $atts );
if( $atts['id'] ){
$gallery = 'SELECT title, path FROM wp_ngg_gallery WHERE gid = '. $atts['id'] .';';
$pictures = 'SELECT description, filename FROM wp_ngg_pictures WHERE galleryid = '. $atts['id'].';';
$gallery = $wpdb->get_results($gallery);
@rbk
rbk / slider.js
Created February 6, 2015 15:25
My first slider made with jquery
function init_slider(id, num){
// Cache the ID
var id = '#' + id;
// Define slide height
var slider_height = '143px';
if( $(window).width() < 767 ){
slider_height = 'auto';
}
@rbk
rbk / common.js
Created February 6, 2015 15:26
Make links to other domains open in a new tab( requires jQuery)
function offSiteLinks() {
var all_links = $('a');
all_links.each(function(){
var link = $(this).attr('href');
var tld = 'com';
if( link != null ){
if( link.match( /\.pdf{1}$/ ) || ! link.match( '/' + location.hostname + '/' ) && ! link.match( /#/ ) && ! link.match(/mailto/) ){
$(this).attr('target', '_blank');
}
@rbk
rbk / anyfile.php
Last active August 29, 2015 14:20
Get category list magento
<?php
// Credit: http://excellencemagentoblog.com/blog/2011/09/14/magento-generate-category-tree-recursively/
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function get_categories($categories) {
$array= '<ul>';
foreach($categories as $category) {
$cat = Mage::getModel('catalog/category')->load($category->getId());
$count = $cat->getProductCount();
$array .= '<li>'.
@rbk
rbk / reset_permissions.sh
Last active February 28, 2017 01:50
Reset Permissions
function reset_permissions() {
echo 'who should own the directory tree?';
read owner;
sudo chown -R $owner:$owner $1;
sudo find $1 -type d -exec chmod 755 {} \;
sudo find $1 -type f -exec chmod 644 {} \;
}