Skip to content

Instantly share code, notes, and snippets.

@levymetal
levymetal / twitter_cache.php
Last active November 1, 2022 02:40
A simple php twitter cache, which can be used with the v1.1 api
<?php
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = 'username';
$number_tweets = 4;
$feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache';
$modified = filemtime( $cache_file );
$now = time();
@levymetal
levymetal / style.css
Created October 4, 2013 02:53
Show a wordpress submenu using only CSS
#sub-menu ul li {
display: none;
}
#sub-menu .menu > li > a {
display: none;
}
#sub-menu ul .current-menu-item,
#sub-menu ul .current-menu-item li,
@levymetal
levymetal / finder-resize.scpt
Last active November 1, 2022 02:41
Small applescript that makes the finder window really large then back to its original size to force the name column to resize fluidly. Used to fix a bug in OSX Mavericks whereby the name column is randomly wider than the window. Best to use a tool such as BTT to bind it to a keyboard shortcut, I used CMD + E.
tell application "Finder"
tell the front Finder window
-- get the current bounds of the finder window
set b to the bounds
-- create a really wide window
set the bounds to {item 1 of b, item 2 of b, 3000, item 4 of b}
-- set window back to its original size
set the bounds to b
end tell
end tell
@levymetal
levymetal / application.js
Last active November 1, 2022 02:42
How to add quantity to product archives in WooCommerce (and keep ajax). From blog post: http://christianvarga.com/how-to-add-quantity-to-product-archives-in-woocommerce-and-keep-ajax
$('.input-text.qty', 'ul.products').on('input', function() {
$(this).closest('li').find('.add_to_cart_button').data('quantity', $(this).val());
});
@levymetal
levymetal / gist:03085a8656d8eb104deb
Last active November 1, 2022 02:42
Allow hyphenated usernames in Wordpress Multisite
<?php
/**
* Allow hypenated usernames
*
* @wp-hook wpmu_validate_user_signup
* @param array $result
* @return array
*/
function wpse_59760_allow_hyphenated_usernames( $result ) {
<?php
function my_wp_nav_menu( $theme_location = 'primary', $container = false, $items_wrap = "<div class='widget'><nav><ul>%3\$s</ul></nav></div>" ) {
$menu = wp_nav_menu(array(
'container' => $container,
'items_wrap' => $items_wrap,
'sub_menu' => true,
'theme_location' => $theme_location,
'echo' => false
));

Keybase proof

I hereby claim:

  • I am levymetal on github.
  • I am levymetal (https://keybase.io/levymetal) on keybase.
  • I have a public key whose fingerprint is 9B4B CA67 E4CB 4791 1894 BA66 A223 AEAA B714 64F3

To claim this, I am signing this object:

@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that treats first-level items as root-level items. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/** wp_nav_menu( array(
'theme_location' => 'primary',
'sub_menu' => true
) );
or
wp_nav_menu( array(
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that allows you to force a specific sub-menu to be displayed. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/* usage
*
* wp_nav_menu( array(
* 'theme_location' => 'primary',
* 'sub_menu' => true,
* 'root_id' => id_of_menu_item
* ) );
*/
@levymetal
levymetal / twitter-cache.php
Last active November 1, 2022 02:44
Custom version of my twitter cache that works with multiple usernames. Original here: http://christianvarga.com/how-to-get-public-feeds-using-twitters-v1-1-api/#comment-2121870201
<?php
// call this script using a GET parameter, eg: http://your-domain.com/twitter-cache.php?screen_name=your_twitter_username
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = $_GET['screen_name'];
$number_tweets = 4;
$feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache-'.$username;