Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / backup_all_dbs.sh
Created November 18, 2012 20:35
Backup All DB's and transfer to S3 with s3cmd + Rolling on the days of the weeks and on the weeks of the months + a montly backup (for paranoiac guys)
#!/bin/bash
BACKUP_DIR="~/db_backups"
DBUSER=""
DBPASSWORD=""
BUCKET="your-unique-bucket-name"
FROM='"Backups" <backups@localhost>'
TO='"Admin" <admin@localhost>'
SUBJECT='Backup Log'
@sardbaba
sardbaba / drupal-template.php
Last active October 13, 2015 10:27
Drupal | Omega | Transform the main menu into a select to be used into small screen sizes.
// see also https://gist.github.com/3201854
function mytheme_menu_tree__main_menu($variables) {
return '<select class="mobile-main-menu" onchange="location = this.options[this.selectedIndex].value;">'
. $variables['tree'] . '</select>';
}
function mytheme_menu_link__main_menu($variables) {
global $base_url;
$e = $variables['element'];
@sardbaba
sardbaba / wordpress-function.php
Last active April 23, 2018 07:04 — forked from GaryJones/gist:1258784
An improved version of the original Jared/Gary version which checks for, in order, the presence of: 1) subcategory template ID 2) subcategory template slug 3) parent category ID 4) parent category slug 5) general category (category.php) You can use it in the function.php file of your theme.
/**
* Apply a template to all subcategories of a certain parent category.
*
* Initial work by Jared Atchison.
* http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* Revisited by GaryJones https://gist.github.com/GaryJones/1258784
* https://gist.github.com/GaryJones/1258784
*
* An improved version of the original Jared/Gary version which checks for, in order, the presence of the templates:
@sardbaba
sardbaba / wordpress-function.php
Last active December 14, 2015 18:29
qtrans_generate_language_list() is a better version of the qtrans_generateLanguageSelectCode() function from qTranslate's Wordpress plugin, originally used to print the languages as an HTML select. This function receive an optional string for the separator that will be echoed and it is able to show your languages as spans followed by separators:…
/**
* Language list Code for non-Widget users
*
* @global array $q_config
* @param string $sep
*/
function qtrans_generate_language_list($sep = " | ") {
global $q_config;
$languages = qtrans_getSortedLanguages();
$num_langs = count($languages);
@sardbaba
sardbaba / wordpress-function.php
Last active December 17, 2015 08:09
Hide Standard Shipping option when free shipping is available
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function sardbaba_hide_standard_shipping_when_free_is_available($available_methods) {
if (isset($available_methods['free_shipping']) AND isset($available_methods['flat_rate'])) {
// remove standard shipping option
unset($available_methods['flat_rate']);
}
@sardbaba
sardbaba / wordpress-functions.php
Created May 14, 2013 17:55
Add a checkbox for the terms agreement and hooks into wp_authenticate to allow authentication or to display an error message.
/**
* Add the terms agreement field
*/
function sardbaba_add_login_field() {
?>
<p class="forgetmenot">
<label for="terms-agreement">
<input name="terms-agreement" type="checkbox" id="terms-agreement" value="agree"> <?php _e( 'I Agree to the terms and conditions' ) ?>
</label>
</p>
@sardbaba
sardbaba / functions.js
Created June 13, 2013 20:16
Fallback to PNG if SVG is not supported. Note: of course, you must create the PNG version of the SVG image. Reference: http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/
( function( $ ) {
$( window ).load( function() {
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (!supportsSVG()) {
var imgs = document.getElementsByTagName('img');
var dotSVG = /.*\.svg$/;
Drupal.settings.isTouchDevice = function() {
return "ontouchstart" in window;
}
if ( Drupal.settings.isTouchDevice() ) {
Drupal.behaviors.jQueryMobileSlideShowTouchAdvance = {
attach: function(context, settings) {
self = Drupal.behaviors.jQueryMobileSlideShowTouchAdvance;
jQuery.each(jQuery(".views_slideshow_cycle_main.viewsSlideshowCycle-processed"), function(idx, value) {
value.addEventListener("touchstart", self.handleTouchStart);
@sardbaba
sardbaba / WP-Widget_Language_Chooser
Created May 2, 2014 12:57
Wordpress - A textual language chooser widget compatible with qTranslate and qTranslate-slug
/**
* A textual language chooser widget compatible with qTranslate and qTranslate-slug
* Author: Mauro Mascia
* License: WTFPL (www.wtfpl.net)
*/
class Widget_Language_Chooser extends WP_Widget {
function __construct() {
parent::__construct(
'widget_language_chooser',
@sardbaba
sardbaba / jquery-outer.js
Last active August 29, 2015 14:01 — forked from tlync/jquery-outer.js
Setter for jQuery outerWidth/outerHeight, in a compact version
/** Get or set the current outer width/height for the first element in the set of matched elements. */
var origOuterWidth = $.fn.outerWidth;
$.fn.outerWidth = function(){
var value = arguments[0];
if (arguments.length === 0 || typeof value === 'boolean') { return origOuterWidth.apply(this, arguments); }
else if (typeof value !== 'number') { throw new Error('Invalid argument. The new outerWidth value must be an integer.'); }
var css = ['borderLeftWidth','borderRightWidth','paddingLeft','paddingRight'];
if (arguments[1] === true) { css.push('marginLeft'); css.push('marginRight'); }
var $el = $(this), exclude = 0, parse = parseFloat;
for (var i=0; i<css.length; i++) { exclude += parse($el.css(css[i])); }