Skip to content

Instantly share code, notes, and snippets.

@arioch1984
arioch1984 / console_log_wrap_coffee_script
Last active August 29, 2015 14:01
console log wrapper coffee script
window.debugMode = document.location.hash.match(/debug/) and console?   console.log 'This is the first of many debug-mode outputs' if debugMode
@arioch1984
arioch1984 / parse_string_for_numbers
Created May 16, 2014 15:47
Parse string for float numbers
<?php
preg_match_all('!\d+\,*\d*!', $price, $matches);
?>
@arioch1984
arioch1984 / wp_percentage_discount
Created May 16, 2014 16:04
WP filter price for add discount as percentage
<?php
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
preg_match_all('!\d+\,*\d*!', $price, $prices);
$discount = '';
if(isset($prices[0]) && !empty($prices[0])){
if(count($prices[0])==2){ //There's total and discount prices
$total_price = floatval(str_replace(',', '.', $prices[0][0]));
$discount_price = floatval(str_replace(',', '.', $prices[0][1]));
$discount_amount = $total_price - $discount_price;
@arioch1984
arioch1984 / log_wp_user_programmatically
Last active August 29, 2015 14:01
Log in a WordPress user programmatically
/*
* Taken from http://www.wprecipes.com/log-in-a-wordpress-user-programmatically
*/
<?php
function auto_login( $user ) {
$username = $user;
if ( !is_user_logged_in() ) {
$user = get_userdatabylogin( $username );
$user_id = $user->ID;
wp_set_current_user( $user_id, $user_login );
@arioch1984
arioch1984 / jquery_floating_share_box
Created May 20, 2014 10:07
jQuery floating share box
//Taken from http://www.webanddesigners.com/floating-share-box/
$(function() {
var offset = $("#box").offset();
var topPadding = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
$("#box").stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
@arioch1984
arioch1984 / wp_remove_filter_after_first_usage
Created May 22, 2014 12:45
WP remove filter after first usage
//Taken from http://stackoverflow.com/questions/18206115/how-to-avoid-affecting-other-queries-when-using-posts-orderby
// My list of post IDs in my custom order
$my_post_ids = array(1,3,2);
// Apply filter to the ORDERBY SQL statement
add_filter('posts_orderby', 'my_custom_orderby');
function my_custom_orderby($orderby_statement) {
// Disable this filter for future queries!
@arioch1984
arioch1984 / 0_reuse_code.js
Created May 22, 2014 12:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@arioch1984
arioch1984 / new_gist_file.php
Created June 20, 2014 12:47
List all hooked WordPress functions
<?php
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
}
@arioch1984
arioch1984 / new_gist_file.php
Created July 15, 2014 09:33
Relative to absolute path
function make_absolute($url, $base)
{
// Return base if no url
if( ! $url) return $base;
// Return if already absolute URL
if(parse_url($url, PHP_URL_SCHEME) != '') return $url;
// Urls only containing query or anchor
if($url[0] == '#' || $url[0] == '?') return $base.$url;
@arioch1984
arioch1984 / new_gist_file_0
Created August 18, 2014 13:56
Change all spaces wallpaper at once - OSX mac
-- Adapted from http://movingparts.net/2012/09/25/changing-backgroundwallpaper-on-os-x-with-multiple-spaces-and-multiple-monitors/
-- Copied from http://apple.stackexchange.com/questions/61677/changing-desktop-background-in-os-x-10-8-only-changes-it-for-the-current-desktop
-- pick a new background image
set theFile to choose file
-- *Note*: Set the number of spaces/desktops manually
set numSpaces to 12
-- Loop through the spaces/desktops, setting each of their backgrounds in turn: