Smashed Blog Development

“mount error 13″ – Mounting a WD TV SMB share

I set up a Raspberry Pi to use as a torrent downloader and NAS at my brother’s place. A WD TV is being used as the media player which has a 1TB hard drive attached via the provided USB port. The WD TV automatically shares the contents via SMB.

I wanted to mount the share to the Pi on boot, but kept running into “mount error 13 = Permission denied”. After a lot of Googling I eventually found this post that offered a solution.

The missing parameter is:

-o sec=ntlmv2

To mount, run the following from the terminal:

mount -t cifs -o guest,sec=ntlmv2 //wdtvlive/sans_titre /mnt/smb

Replacing //wdtvlive/sans_titre with your device and /mnt/smb with the directory you'd like to mount to.

If you'd like to do this on boot, add the following to /etc/fstab:

//wdtvlive/sans_titre    /mnt/smb    cifs    guest,sec=ntlmv2    0    0

Gravity Forms 1.4.5 – no such method ‘select’ for tabs widget instance

I recently bumped into the problem mentioned here in the latest WordPress update when using Gravity Forms.

The fix outlined is for Gravity Forms 1.6.4.5.4, I’m using version 1.4.5 so the described changes don’t exist.
Below is a fix for the latter.

Locate the file js.php in wp-content/plugins/gravityforms/

Find this line around 1251:

jQuery("#field_settings").appendTo(".field_selected").tabs("select", 0);

and change to:

jQuery("#field_settings").appendTo(".field_selected").tabs("option", "active", 0);

Hope that helps!

Essential Windows Applications

  • Volume2 – Pretty volume replacement
  • Desktop Media – Removeable disk icons on desktop
  • Clover - Tabbed Chrome-like explorer replacement
  • f.lux – Protects your eyes at night
  • Teracopy - File transfer replacement
  • Launchy - Application launcher
  • WizMouse – Scroll unfocused window under mouse cursor
  • Unlocker – Unlock files currently in use
  • NetSpeedMonitor – Speed monitor in Windows taskbar
  • BatteryBar – Battery info in Windows taskbar
  • Switcher – Alt+Tab replacement

jQuery CSS theme switcher

HTML:

<ul class="themeSwitch">
	<li><a href="#light" id="light" class="selected">Light</a></li>
	<li><a href="#dark" id="dark">Dark</a></li>
</ul>

jQuery:

//Theme switcher
$('.themeSwitch a').click(function(e) {
	//Get the ID from link
	id = $(this).attr('id');

	//Load alternate styles
	if (id == 'dark') {
		//Method 1: Swap out existing CSS included in head
		url = '/blog/wp-content/themes/smashedcrab/css/monokai.css';
		$('#syntax-css').attr('href', url);

		//Method 2: Change body class
		$('body').removeClass('light').addClass('dark');
	} else {
		//Must be light
		url = '/blog/wp-content/themes/smashedcrab/css/github.css';
		$('#syntax-css').attr('href', url);
		$('body').removeClass('dark').addClass('light');
	}

	//Remove any selected link
	$('.themeSwitch .selected').removeClass('selected');
	//Add 'selected' class to clicked link
	$(this).addClass('selected');

	//Prevent default link action
	e.preventDefault();
});

Recreating the Gmail dynamic favicon with canvas

I’m currently using this for a web application I’m working on. Pass an integer to it and you’re set.

View Demo

function updateFavicon(i) {
	var canvas = document.createElement('canvas'),
	ctx,
	img = document.createElement('img'),
	link = document.getElementById('favicon').cloneNode(true)//,
		
	if (canvas.getContext) {
		canvas.height = canvas.width = 16; // set the size
		ctx = canvas.getContext('2d');
		img.onload = function () { // once the image has loaded
			ctx.drawImage(this, 0, 0);
			y = "15";
			if (i <= 9) { //moves x coordinates depending on value
				x = "9";
			} else if (i > 9 && i < 99) {
				x = "5";
			} else if (i > 99 && i < 999) {
				x = "1";
			} else if (i > 999) { //doesn't display >999
				x = "0";
				i = "";
			}

			ctx.font = '9px sans-serif';
			ctx.lineWidth = 3;
			ctx.strokeStyle = "#fff";
			ctx.strokeText(i, x, y);
			ctx.fillStyle = '#111';
			ctx.fillText(i, x, y);

			link.href = canvas.toDataURL('image/png');
			document.body.appendChild(link);
		};
		img.src = 'favicon.png'; //path to favicon
	}
};

Shopp WordPress Plugin images not working solution

If you are having problems with your Shopp product images not displaying, try removing the following line (or similar) from your .htaccess file in your root directory.

RewriteRule ^.*shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]

Easy Hover menu with jQuery

I’ve seen this or some variant around a few times. Easy one to use these days when you don’t have to cater for IE6. Make sure you grab the latest version of hoverIntent.js as well.

var config = {    
	 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	 interval: 100,  // number = milliseconds for onMouseOver polling interval    
	 over: doOpen,   // function = onMouseOver callback (REQUIRED)    
	 timeout: 300,   // number = milliseconds delay before onMouseOut    
	 out: doClose    // function = onMouseOut callback (REQUIRED)    
};

function doOpen() {
	$(this).addClass("hover");
	$('ul:first',this).css('visibility', 'visible');
}

function doClose() {
	$(this).removeClass("hover");
	$('ul:first',this).css('visibility', 'hidden');
}
$("#topNav li").hoverIntent(config);

Shouldn’t be hard to figure out the HTML needed!

Mark active page with jQuery and CSS

This one is really handy. Sometimes you may need to change window.location.pathname, depending on how your URL structure works.

Assuming you have a menu set up in a list:

<ul id="nav">
	<li><a href="#">Link_1</a></li>
	<li><a href="#">Link_2</a></li>
	<li><a href="#">Link_3</a></li>
</ul>

Use the jQuery:

var url = window.location.pathname, 
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
$('#nava').each(function(){
	if(urlRegExp.test(this.href.replace(/\/$/,''))){
		$(this).parents('li').addClass('active');
	}
});

And then some good old CSS:

#nav li.active a:hover {
	font-weight:700;
}