<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>conjurecode</title>
	<atom:link href="http://conjurecode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://conjurecode.com</link>
	<description>python, php, *nix</description>
	<lastBuildDate>Fri, 27 Apr 2012 16:32:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Send text to clipboard in linux terminal</title>
		<link>http://conjurecode.com/send-text-to-clipboard-in-linux-terminal/</link>
		<comments>http://conjurecode.com/send-text-to-clipboard-in-linux-terminal/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 16:30:31 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Environment]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=191</guid>
		<description><![CDATA[What we'd like to do is have a quick way of sending text to the clipboard from terminal in linux. We can accomplish this with pipes and xclip. We'll install and configure xclip and then review the proper usage. First we install xclip: sudo apt-get install xclip Next we want to configure an alias for [...]]]></description>
			<content:encoded><![CDATA[<p>What we'd like to do is have a quick way of sending text to the clipboard from terminal in linux. We can accomplish this with pipes and xclip. We'll install and configure xclip and then review the proper usage.</p>
<p>First we install xclip:</p>
<div class="codesnip-container" >sudo apt-get install xclip</div>
<p>Next we want to configure an alias for xclip so that the arguments "-selection c" are used every time we call xclip. This ensures that the text is piped (copied) into the correct clipboard. This command will place the alias specification into the .bashrc file in our home directory.</p>
<div class="codesnip-container" >echo "alias xclip=\"xclip -selection c\"" >> ~/.bashrc</div>
<p>Now we need to load our new .bashrc settings into the current window or open a new window.</p>
<div class="codesnip-container" >source ~/.bashrc</div>
<p>Now we can use xclip as follows:</p>
<div class="codesnip-container" >uptime | xclip</div>
<p>In my case I like being able to copy my public keys directly from file into github, so I use it like so:</p>
<div class="codesnip-container" >cat ~/.ssh/id_rsa.pub | xclip</div>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=191&amp;md5=1593729c3cf12e75cf757ad2f8ddee68" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/send-text-to-clipboard-in-linux-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fsend-text-to-clipboard-in-linux-terminal%2F&amp;language=en_GB&amp;category=text&amp;title=Send+text+to+clipboard+in+linux+terminal&amp;description=What+we%27d+like+to+do+is+have+a+quick+way+of+sending+text+to+the+clipboard+from+terminal+in+linux.+We+can+accomplish+this+with+pipes+and+xclip.+We%27ll+install...&amp;tags=Environment%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Linux and sharing, so awesome it just might be illegal</title>
		<link>http://conjurecode.com/linux-and-sharing-so-awesome-it-just-might-be-illegal/</link>
		<comments>http://conjurecode.com/linux-and-sharing-so-awesome-it-just-might-be-illegal/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 00:05:04 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=165</guid>
		<description><![CDATA[I'm a huge GNU/Linux fan and I like to think of myself as a FOSS advocate. So I chose an image of Tux to emblazon on my new credit card. There is some opaque process for determining which images can be used and which cannot, due to licensing issues. Unfortunately my image was flagged and [...]]]></description>
			<content:encoded><![CDATA[<p>I'm a huge GNU/Linux fan and I like to think of myself as a FOSS advocate. So I chose an <a href="http://www.isc.tamu.edu/~lewing/linux/">image of Tux</a> to emblazon on my new credit card. There is some opaque process for determining which images can be used and which cannot, due to licensing issues. Unfortunately my image was flagged and denied, falling under "Celebrities such as actors, musicians, athletes, or cartoons." Now certainly Tux may be a celebrity, but that doesn't mean I can't use his glorious image! I mean, look at that mug!</p>
<p><img src="http://www.conjurecode.com/tuxcard.jpg" alt="Tux Credit Card" /></p>
<p>So not wanting to give up, I call in to appeal the decision. That's when things got funny:</p>
<blockquote><p>
<b>Me:</b> The image on the card is a cartoon penguin named Tux. Not like a cartoon you'd see on television though. He is the Linux mascot. Are you familiar with Linux?</p>
<p><b>Capital One CS:</b> No response.</p>
<p><b>Me:</b> Linux is a free, open source operating system for your computer. It is free to use, modify, share or sell. The image is free to use. I know it can be a funny concept for some people.</p>
<p><b>Capital One CS:</b> Ok, and the organization is?</p>
<p><b>Me:</b> ... There is no organization, Linux can be freely downloaded, used and modified by anyone, no one necessarily owns or controls it.</p>
<p><b>Capital One CS:</b> And this is legal?</p>
<p><b>Me:</b> *chuckles* Yes, it certainly is.
</p></blockquote>
<p>How about that? I've heard of people receiving this exact response before, but it is absolutely stunning to hear it myself. What does that say about our culture? Especially the culture in technology and software. It is certainly disappointing, but I will admit, there is a part of me that feels a glowing pride, knowing that Linux is so awesome, so mind bending to the common person, that hell, it might not even be legal. These days, let's ensure that it remains that way.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=165&amp;md5=1617ca83505924965be1c18d51be702c" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/linux-and-sharing-so-awesome-it-just-might-be-illegal/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Flinux-and-sharing-so-awesome-it-just-might-be-illegal%2F&amp;language=en_GB&amp;category=text&amp;title=Linux+and+sharing%2C+so+awesome+it+just+might+be+illegal&amp;description=I%27m+a+huge+GNU%2FLinux+fan+and+I+like+to+think+of+myself+as+a+FOSS+advocate.+So+I+chose+an+image+of+Tux+to+emblazon+on+my+new+credit+card....&amp;tags=Culture%2Cblog" type="text/html" />
	</item>
		<item>
		<title>UDev rules for Android Development on Motorola Triumph</title>
		<link>http://conjurecode.com/udev-rules-for-android-development-on-motorola-triumph/</link>
		<comments>http://conjurecode.com/udev-rules-for-android-development-on-motorola-triumph/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 20:28:37 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=160</guid>
		<description><![CDATA[In short, the published Vendor ID for Motorola is not correct for the Motorola Triumph. Instead of 22b8, use 0489. When we connect our android device to the computer via USB for development purposes, we have to set a UDev rule which specifies how the system should be allowed to access that device. For this [...]]]></description>
			<content:encoded><![CDATA[<p>In short, the published Vendor ID for Motorola is not correct for the Motorola Triumph. Instead of 22b8, use 0489. When we connect our android device to the computer via USB for development purposes, we have to set a UDev rule which specifies how the system should be allowed to access that device. For this purpose we can refer to the <a href="http://developer.android.com/guide/developing/device.html#setting-up">Android Developer Docs</a>. These docs give instructions for Ubuntu users. You need to make sure you're using the correct location for the rules file for your distribution. You can can see at the <a href="https://wiki.archlinux.org/index.php/Udev#About_udev_rules">arch wiki</a>, the location for udev rules is /etc/udev/rules.d/.</p>
<p>So to enable our Motorola Triumph android phone for development we must add the following to /etc/udev/rules.d/51-android.rules (again, check for your distribution's docs for the correct udev rules location)</p>
<div class="codesnip-container" >SUBSYSTEM=="usb", ATTR{idVendor}=="0489", MODE="0666", GROUP="plugdev"</div>
<p>Once you save this file UDev should automatically load in your new rule, but you will have to unplug and reconnect your phone in order for the new rule to take effect.</p>
<p>Now browse to the platform tools folder of your sdk (In my case /opt/android-sdk/platform-tools/) and run adb to ensure your device is properly recognized, like so:</p>
<div class="codesnip-container" >$ ./adb devices<br />
List of devices attached<br />
FD1M1019202100	device</div>
<p>Without the proper UDev rule, your Triumph will not be mounted with the correct permissions and neither your nor your Eclipse SDK will be able to access your phone properly. Running adb without the proper UDev rule will yield something like this:</p>
<div class="codesnip-container" >$ ./adb devices<br />
List of devices attached<br />
????????????	no permissions</div>
<p>In order to determine the vendor id and product id of a phone, connect it to your computer (the previously mentioned UDev rules do not have to be in place), and run lsusb and find your phone amongst the devices listed.</p>
<div class="codesnip-container" >$ lsusb<br />
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br />
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br />
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 002 Device 002: ID 0bda:0158 Realtek Semiconductor Corp. USB 2.0 multicard reader<br />
Bus 002 Device 003: ID 5986:01a6 Acer, Inc Lenovo Integrated Webcam<br />
Bus 001 Device 016: ID 0489:c001 Foxconn / Hon Hai</div>
<p>In this case we're interested in the last one, named "Foxconn / Hon Hai". The Vendor ID and Product ID directly precede the name and are separated by a colon. For example, in the case of this particular Motorola Triumph, the Vendor ID is 0489, and the Product ID is c001. To save yourself time and frustration, take a moment to run this command when you're creating your UDev rules to ensure you have the proper ID's for your particular device.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=160&amp;md5=456211250e78f884bcff9593f8257fce" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/udev-rules-for-android-development-on-motorola-triumph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fudev-rules-for-android-development-on-motorola-triumph%2F&amp;language=en_GB&amp;category=text&amp;title=UDev+rules+for+Android+Development+on+Motorola+Triumph&amp;description=In+short%2C+the+published+Vendor+ID+for+Motorola+is+not+correct+for+the+Motorola+Triumph.+Instead+of+22b8%2C+use+0489.+When+we+connect+our+android+device+to+the+computer+via...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Fix Spotify playlist URL&#8217;s in Ubuntu / Linux / Gnome 3</title>
		<link>http://conjurecode.com/fix-spotify-playlist-urls-in-linux/</link>
		<comments>http://conjurecode.com/fix-spotify-playlist-urls-in-linux/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 14:14:21 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Spotify]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=143</guid>
		<description><![CDATA[Spotify has a great linux client but I had trouble getting Spotify playlist URLs to load properly. When you a click a spotify URL in your browser it utilizes xdg-open to determine which application should be launched. I'm running Ubuntu 11.04 with Gnome 3, and the following solution worked well for me and is quite [...]]]></description>
			<content:encoded><![CDATA[<p>Spotify has a great linux client but I had trouble getting Spotify playlist URLs to load properly. When you a click a spotify URL in your browser it utilizes xdg-open to determine which application should be launched. I'm running Ubuntu 11.04 with Gnome 3, and the following solution worked well for me and is quite elegant.</p>
<p>Enter the following into the file /usr/share/applications/spotify-url.desktop</p>
<div class="codesnip-container" >
<div class="ini codesnip" style="font-family:monospace;"><span class="re0"><span class="br0">&#91;</span>Desktop Entry<span class="br0">&#93;</span></span><br />
<span class="re1">Name</span><span class="sy0">=</span><span class="re2">Spotify</span><br />
<span class="re1">GenericName</span><span class="sy0">=</span><span class="re2">Spotify</span><br />
<span class="re1">Comment</span><span class="sy0">=</span><span class="re2">Listen to music using Spotify</span><br />
<span class="re1">Icon</span><span class="sy0">=</span><span class="re2">spotify-linux-512x512</span><br />
<span class="re1">TryExec</span><span class="sy0">=</span><span class="re2">spotify</span><br />
<span class="re1">Exec</span><span class="sy0">=</span><span class="re2">spotify -uri %u</span><br />
<span class="re1">Terminal</span><span class="sy0">=</span><span class="re2">false</span><br />
<span class="re1">Type</span><span class="sy0">=</span><span class="re2">Application</span><br />
<span class="re1">Categories</span><span class="sy0">=</span><span class="re2">Qt</span><span class="co0">;AudioVideo</span><br />
<span class="re1">MimeType</span><span class="sy0">=</span><span class="re2">x-scheme-handler/spotify</span><br />
<span class="re1">NoDisplay</span><span class="sy0">=</span><span class="re2">true</span></div>
</div>
<p>Then run the following command to update your desktop database to enable the new command. If successful this command will return silently, without any error or success message.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">sudo</span> update-desktop-database</div>
</div>
<p>Spotify links should now work! Have a better solution? Having trouble finding a solution for your particular setup, let me know.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=143&amp;md5=3a1734200259d65227ced825fe63be34" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/fix-spotify-playlist-urls-in-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Ffix-spotify-playlist-urls-in-linux%2F&amp;language=en_GB&amp;category=text&amp;title=Fix+Spotify+playlist+URL%26%238217%3Bs+in+Ubuntu+%2F+Linux+%2F+Gnome+3&amp;description=Spotify+has+a+great+linux+client+but+I+had+trouble+getting+Spotify+playlist+URLs+to+load+properly.+When+you+a+click+a+spotify+URL+in+your+browser+it+utilizes+xdg-open...&amp;tags=Hacks%2CSpotify%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Disable the Universal Access accessibility menu in Gnome 3</title>
		<link>http://conjurecode.com/disable-the-universal-access-accessibility-menu-in-gnome-3/</link>
		<comments>http://conjurecode.com/disable-the-universal-access-accessibility-menu-in-gnome-3/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 15:17:54 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=135</guid>
		<description><![CDATA[In the new gnome-shell, otherwise known as Gnome 3, there is an accessibility menu called "Universal Access" that cannot be removed by any apparent means. Fortunately it can easily be removed, hidden, or disabled by editing a file and restarting the shell. This method works for gnome-shell version 3.0 (this reportedly works in Gnome 3.2 [...]]]></description>
			<content:encoded><![CDATA[<p><!--<strong>Update:</strong> Thanks to <a href="http://ubuntuforums.org/showthread.php?p=11424502#post11408575">mtron</a> for suggesting an improved method for removing the Universal Access menu which does not rely on editing system files. I've left the original article intact below in case this new method does not work.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">sudo</span> add-apt-repository ppa:webupd8team<span class="sy0">/</span>gnome3<br />
<span class="kw2">sudo</span> <span class="kw2">apt-get</span> update<br />
<span class="kw2">sudo</span> <span class="kw2">apt-get</span> <span class="kw2">install</span> gnome-shell-extensions-noa11y</div>
</div>
<p><strong>Possibly Outdated:</strong> --> In the new gnome-shell, otherwise known as Gnome 3, there is an accessibility menu called "Universal Access" that cannot be removed by any apparent means. Fortunately it can easily be removed, hidden, or disabled by editing a file and restarting the shell. This method works for gnome-shell version 3.0 (this reportedly works in Gnome 3.2 as well), it may or may not work in future versions.</p>
<p>Edit the file /usr/share/gnome-shell/js/ui/panel.js</p>
<p>Look for the following line, (line 38 in my case):</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="st0">'a11y'</span><span class="sy0">:</span> imports.<span class="me1">ui</span>.<span class="kw3">status</span>.<span class="me1">accessibility</span>.<span class="me1">ATIndicator</span><span class="sy0">,</span></div>
</div>
<p>Comment out this line like so:</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="co1">//'a11y': imports.ui.status.accessibility.ATIndicator,</span></div>
</div>
<p>Then restart gnome-shell by typing Alt-F2 to run command, enter "r" without the quotes, and hit enter. This will quickly restart the shell and you should find that the Universal Access menu no longer appears. If you should find a use for it in the future, simply un-comment the lines found in /usr/share/gnome-shell/js/ui/panel.js</p>
<p>Thanks to the endlessly helpful folks who maintain <a href="https://wiki.archlinux.org/index.php/GNOME#Hide_accessibility_icon">ArchWiki</a> for this tip.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=135&amp;md5=852065b5802a8f9c826440618e7d532c" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/disable-the-universal-access-accessibility-menu-in-gnome-3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fdisable-the-universal-access-accessibility-menu-in-gnome-3%2F&amp;language=en_GB&amp;category=text&amp;title=Disable+the+Universal+Access+accessibility+menu+in+Gnome+3&amp;description=In+the+new+gnome-shell%2C+otherwise+known+as+Gnome+3%2C+there+is+an+accessibility+menu+called+%22Universal+Access%22+that+cannot+be+removed+by+any+apparent+means.+Fortunately+it+can+easily+be...&amp;tags=Hacks%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Disable the Ctrl-Q quit shortcut in firefox with keyconfig!</title>
		<link>http://conjurecode.com/disable-the-ctrl-q-quit-shortcut-in-firefox-with-keyconfig/</link>
		<comments>http://conjurecode.com/disable-the-ctrl-q-quit-shortcut-in-firefox-with-keyconfig/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 17:28:56 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=129</guid>
		<description><![CDATA[This is a firefox extension which allows you to add, modify, remove and disable keyboard shortcuts for Firefox. We're going to use this to disable the pesky shortcut for quitting firefox which is Ctrl-Q. Ctrl-Q is right next to Ctrl-W which is the handy shortcut for closing tabs, and if you hit it by mistake [...]]]></description>
			<content:encoded><![CDATA[<p>This is a firefox extension which allows you to add, modify, remove and <strong>disable</strong> keyboard shortcuts for Firefox. We're going to use this to disable the pesky shortcut for quitting firefox which is Ctrl-Q. Ctrl-Q is right next to Ctrl-W which is the handy shortcut for closing tabs, and if you hit it by mistake your entire session will be lost; sometimes it vanishes so quickly you don't even know what hit you.</p>
<p>Simply install the extension, restart Firefox, and then open Preferences for keyconfig in the Add-ons section. Then scroll down and highlight the shortcut for Quit and click disable. Voila, no more Ctrl-Q rage.</p>
<p>This extension was created by dorando, and can be found here: <a href="http://forums.mozillazine.org/viewtopic.php?t=72994">http://forums.mozillazine.org/viewtopic.php?t=72994</a> and here: <a href="http://mozilla.dorando.at">http://mozilla.dorando.at</a></p>
<p>According to the forum post linked above, you can support the creator of this extension by donating something towards his hosting bill here: <a href="http://www.dreamhost.com/donate.cgi?id=3048">http://www.dreamhost.com/donate.cgi?id=3048</a></p>
<p>Since this extensions works so well for many people and the only trace of it seems to be a forum post, I've decided to host a mirror of it on my server, just in case. You can find that here: <a href="http://conjurecode.com/keyconfig.xpi">http://conjurecode.com/keyconfig.xpi</a></p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=129&amp;md5=784e5fd411ad32c5c540e5b9fcfb36e8" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/disable-the-ctrl-q-quit-shortcut-in-firefox-with-keyconfig/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fdisable-the-ctrl-q-quit-shortcut-in-firefox-with-keyconfig%2F&amp;language=en_GB&amp;category=text&amp;title=Disable+the+Ctrl-Q+quit+shortcut+in+firefox+with+keyconfig%21&amp;description=This+is+a+firefox+extension+which+allows+you+to+add%2C+modify%2C+remove+and+disable+keyboard+shortcuts+for+Firefox.+We%27re+going+to+use+this+to+disable+the+pesky+shortcut+for+quitting...&amp;tags=Hacks%2Cblog" type="text/html" />
	</item>
		<item>
		<title>SSH Tunnel for MySQL (or anything else) via Port Forwarding</title>
		<link>http://conjurecode.com/ssh-tunnel-for-mysql-or-anything-else-via-port-forwarding/</link>
		<comments>http://conjurecode.com/ssh-tunnel-for-mysql-or-anything-else-via-port-forwarding/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 16:36:29 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[One Liners]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=122</guid>
		<description><![CDATA[Let's using SSH port forwarding to tunnel a service from a remote server to our local machine. For example, many servers restrict mysql connections to localhost only. Using this technique we can tunnel our mysql connection through the remote machine transparently and securely. Let's set up our example. We have an instance of MySQL running [...]]]></description>
			<content:encoded><![CDATA[<p>Let's using SSH port forwarding to tunnel a service from a remote server to our local machine. For example, many servers restrict mysql connections to localhost only. Using this technique we can tunnel our mysql connection through the remote machine transparently and securely. Let's set up our example. We have an instance of MySQL running at mysql.remoteserver.com on the default port of 3306. To make things interesting (and perhaps easier to follow), we're going to assume that you're also running an instance of MySQL on your local machine on the same port. So, let's tunnel the mysql connection from the remote server to our local machine on port 3307 so there are no conflicts.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">ssh</span> <span class="re5">-L</span> 3307:127.0.0.1:3306 user<span class="sy0">@</span>mysql.remoteserver.com <span class="re5">-N</span></div>
</div>
<p>If you're not using public key authentication, you will be prompted for a password. By specifying the -N option, we suppress opening a shell session and your command prompt will merely hang after you've entered your password. This can be safely omitted if you like, and a shell session will be opened for you. You can read more about the ssh command at it's <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?ssh+1">man page</a>.</p>
<p>To connect to our MySQL server, we need to specify our local address and port (Note: Using "localhost" will NOT work in this case, make sure to 127.0.0.1), and the login information for the instance of MySQL on our remote server. In Python you might use the following:</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;">db = MySQLdb.<span class="me1">connect</span><span class="br0">&#40;</span>host=<span class="st0">'127.0.0.1'</span>, port=3307, <span class="kw3">user</span>=<span class="st0">'myusername'</span>, passwd=<span class="st0">'mypassword'</span>, db=<span class="st0">'databasename'</span><span class="br0">&#41;</span></div>
</div>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=122&amp;md5=022a647d07318f6031f6e207b796c9a2" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/ssh-tunnel-for-mysql-or-anything-else-via-port-forwarding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fssh-tunnel-for-mysql-or-anything-else-via-port-forwarding%2F&amp;language=en_GB&amp;category=text&amp;title=SSH+Tunnel+for+MySQL+%28or+anything+else%29+via+Port+Forwarding&amp;description=Let%27s+using+SSH+port+forwarding+to+tunnel+a+service+from+a+remote+server+to+our+local+machine.+For+example%2C+many+servers+restrict+mysql+connections+to+localhost+only.+Using+this+technique...&amp;tags=One+Liners%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Create Indicator Applet for Ubuntu Unity (with Python!)</title>
		<link>http://conjurecode.com/create-indicator-applet-for-ubuntu-unity-with-python/</link>
		<comments>http://conjurecode.com/create-indicator-applet-for-ubuntu-unity-with-python/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 18:12:43 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=110</guid>
		<description><![CDATA[We're going to walk through the process of creating a status indicator applet for the latest version of Ubuntu running Unity. In this example we're going to create a basic new mail indicator which works with GMail. This will give you a solid grounding in the basic structure of an applet while providing a real-world [...]]]></description>
			<content:encoded><![CDATA[<p>We're going to walk through the process of creating a status indicator applet for the latest version of Ubuntu running Unity. In this example we're going to create a basic new mail indicator which works with GMail. This will give you a solid grounding in the basic structure of an applet while providing a real-world (albeit simplistic) example that you can easily extend.</p>
<p>Let's go through the final script piece by piece, first our header:</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="co1">#!/usr/bin/env python</span></p>
<p><span class="kw1">import</span> <span class="kw3">sys</span><br />
<span class="kw1">import</span> gtk<br />
<span class="kw1">import</span> appindicator</p>
<p><span class="kw1">import</span> <span class="kw3">imaplib</span><br />
<span class="kw1">import</span> <span class="kw3">re</span></p>
<p>PING_FREQUENCY = <span class="nu0">60</span></div>
</div>
<p>The first line instructs the system to find the current environment's version of python and use it to run this file. The first three imports are probably going to be used in every indicator you use. sys is used so we can offer a "Quit" option, GTK drives the interface, and appindicator provides Unity-specific code for creating indicator applets. The last two includes are required for this indicator's specific functionality, checking GMail. Finally we have one application wide constant which dictates how often we should ping (or check) GMail's servers for new mail, in seconds.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">class</span> CheckGMail:<br />
&nbsp; &nbsp; <span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span> = appindicator.<span class="me1">Indicator</span><span class="br0">&#40;</span><span class="st0">&quot;debian-doc-menu&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;indicator-messages&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;appindicator.<span class="me1">CATEGORY_APPLICATION_STATUS</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ACTIVE</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_attention_icon</span><span class="br0">&#40;</span><span class="st0">&quot;new-messages-red&quot;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu_setup</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_menu</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">menu</span><span class="br0">&#41;</span></div>
</div>
<p>Next we create a class called CheckGMail which will hold all of our indicator's functionality. To initialize our class first we create the variable "ind" which holds an Indicator object. According to the <a href="http://developer.ubuntu.com/api/ubuntu-11.04/libappindicator/libappindicator-app-indicator.html#app-indicator-new">API</a> this constructor takes 3 (or 4) arguments, a unique id for our indicator, an icon name, and an <a href="http://developer.ubuntu.com/api/ubuntu-11.04/libappindicator/libappindicator-app-indicator.html#AppIndicatorCategory">indicator category</a>.</p>
<p>We set an initial status for our indicator with ind.set_status and then define the icon to use when our indicator requires attention (in this case when we have new mail waiting). Then we call our custom menu_setup() function (which we haven't defined yet), and then the set_menu() function on the Indicator object which takes a GTK menu as an argument and attaches it to our indicator.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">def</span> menu_setup<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu</span> = gtk.<span class="me1">Menu</span><span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span> = gtk.<span class="me1">MenuItem</span><span class="br0">&#40;</span><span class="st0">&quot;Quit&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span>.<span class="me1">connect</span><span class="br0">&#40;</span><span class="st0">&quot;activate&quot;</span>, <span class="kw2">self</span>.<span class="me1">quit</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu</span>.<span class="me1">append</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">quit_item</span><span class="br0">&#41;</span></div>
</div>
<p>Here is the aforementioned menu_setup() function. Here we create a new <a href="http://developer.gnome.org/pygtk/stable/class-gtkmenu.html#constructor-gtkmenu">GTK Menu</a> and then define a single menu item called "quit_item". We define the text label for the menu, and then connect it with an action. We instruct the menu item to launch the quit() function when the item is "activated" (clicked) and then add the item to our menu variable.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">def</span> main<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">check_mail</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gtk.<span class="me1">timeout_add</span><span class="br0">&#40;</span>PING_FREQUENCY <span class="sy0">*</span> 1000, <span class="kw2">self</span>.<span class="me1">check_mail</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gtk.<span class="me1">main</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p>The main() function constitutes our primary program loop. When our indicator is first loaded we run this function. First it runs the check_mail() function (which has yet to be defined), and then creates a timeout. This causes our program to wait the specified amount of time and then run the given callback function, which is in this case, check_mail(). Then finally we run our main() function again, putting our program into an infinite loop, since we'd like our applet to continually check mail as long as it's running.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">def</span> quit<span class="br0">&#40;</span><span class="kw2">self</span>, widget<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span></div>
</div>
<p>Here we define the quit() function which we referenced in menu_setup(). This function makes a call to sys.exit which will cause our application to stop running. At this point the process will stop and our indicator applet will disappear.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">def</span> check_mail<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; messages, unread = <span class="kw2">self</span>.<span class="me1">gmail_checker</span><span class="br0">&#40;</span><span class="st0">'myaddress@gmail.com'</span>,<span class="st0">'mypassword'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> unread <span class="sy0">&gt;</span> 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ATTENTION</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ACTIVE</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">True</span></div>
</div>
<p>This is the core functionality of this specific indicator applet. We're calling the function gmail_checker() which we've borrowed from <a href="http://martinbrook.posterous.com/python-snippet-check-status-of-your-gmail-inbox">Martin Brook</a> for the purposes of this example. We load in the number of total messages and the number of unread messages from the provided GMail account. (I should note, this will work with Google Apps account, you are not required to have a @gmail.com address). If there is more than one unread messages found, we change the status of our indicator to STATUS_ATTENTION, which is this case turns our icon red, notifying you of new messages.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">def</span> gmail_checker<span class="br0">&#40;</span><span class="kw2">self</span>, username, password<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; i = <span class="kw3">imaplib</span>.<span class="me1">IMAP4_SSL</span><span class="br0">&#40;</span><span class="st0">'imap.gmail.com'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i.<span class="me1">login</span><span class="br0">&#40;</span>username, password<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, y = i.<span class="me1">status</span><span class="br0">&#40;</span><span class="st0">'INBOX'</span>, <span class="st0">'(MESSAGES UNSEEN)'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messages = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">'MESSAGES<span class="es0">\s</span>+(<span class="es0">\d</span>+)'</span>, y<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">group</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unseen = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">'UNSEEN<span class="es0">\s</span>+(<span class="es0">\d</span>+)'</span>, y<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">group</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>messages, unseen<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">except</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">False</span>, <span class="nu0">0</span></div>
</div>
<p>This is the final function of our indicator applet class, and it is the code that we borrowed from Martin. It creates an SSL encrypted connection to an IMAP server, in this case GMail, and will attempt to determine how many total and unread messages are available.</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp; indicator = CheckGMail<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; indicator.<span class="me1">main</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p>We come a the close of our file with some basic python initialization. This special block will be run when our file is called directly. It instantiated an object of the CheckGMail class and then runs the main() function, which set's everything off for us.</p>
<p>Here is our entire file:</p>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="co1">#!/usr/bin/env python</span></p>
<p><span class="kw1">import</span> <span class="kw3">sys</span><br />
<span class="kw1">import</span> gtk<br />
<span class="kw1">import</span> appindicator</p>
<p><span class="kw1">import</span> <span class="kw3">imaplib</span><br />
<span class="kw1">import</span> <span class="kw3">re</span></p>
<p>PING_FREQUENCY = <span class="nu0">10</span> <span class="co1"># seconds</span></p>
<p><span class="kw1">class</span> CheckGMail:<br />
&nbsp; &nbsp; <span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span> = appindicator.<span class="me1">Indicator</span><span class="br0">&#40;</span><span class="st0">&quot;new-gmail-indicator&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;indicator-messages&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;appindicator.<span class="me1">CATEGORY_APPLICATION_STATUS</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ACTIVE</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_attention_icon</span><span class="br0">&#40;</span><span class="st0">&quot;new-messages-red&quot;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu_setup</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_menu</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">menu</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">def</span> menu_setup<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu</span> = gtk.<span class="me1">Menu</span><span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span> = gtk.<span class="me1">MenuItem</span><span class="br0">&#40;</span><span class="st0">&quot;Quit&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span>.<span class="me1">connect</span><span class="br0">&#40;</span><span class="st0">&quot;activate&quot;</span>, <span class="kw2">self</span>.<span class="me1">quit</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">quit_item</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">menu</span>.<span class="me1">append</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">quit_item</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">def</span> main<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">check_mail</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gtk.<span class="me1">timeout_add</span><span class="br0">&#40;</span>PING_FREQUENCY <span class="sy0">*</span> 1000, <span class="kw2">self</span>.<span class="me1">check_mail</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gtk.<span class="me1">main</span><span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">def</span> quit<span class="br0">&#40;</span><span class="kw2">self</span>, widget<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">def</span> check_mail<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; messages, unread = <span class="kw2">self</span>.<span class="me1">gmail_checker</span><span class="br0">&#40;</span><span class="st0">'myaddress@gmail.com'</span>,<span class="st0">'mypassword'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> unread <span class="sy0">&gt;</span> 0:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ATTENTION</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ind</span>.<span class="me1">set_status</span><span class="br0">&#40;</span>appindicator.<span class="me1">STATUS_ACTIVE</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">True</span></p>
<p>&nbsp; &nbsp; <span class="kw1">def</span> gmail_checker<span class="br0">&#40;</span><span class="kw2">self</span>, username, password<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; i = <span class="kw3">imaplib</span>.<span class="me1">IMAP4_SSL</span><span class="br0">&#40;</span><span class="st0">'imap.gmail.com'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i.<span class="me1">login</span><span class="br0">&#40;</span>username, password<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, y = i.<span class="me1">status</span><span class="br0">&#40;</span><span class="st0">'INBOX'</span>, <span class="st0">'(MESSAGES UNSEEN)'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messages = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">'MESSAGES<span class="es0">\s</span>+(<span class="es0">\d</span>+)'</span>, y<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">group</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unseen = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">'UNSEEN<span class="es0">\s</span>+(<span class="es0">\d</span>+)'</span>, y<span class="br0">&#91;</span>0<span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">group</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>messages, unseen<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">except</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">False</span>, 0</p>
<p>
<span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp; indicator = CheckGMail<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; indicator.<span class="me1">main</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
<p>Now we just need to mark the file as executable and run it to see the results.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">chmod</span> +x check_gmail.py</div>
</div>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">.<span class="sy0">/</span>check_gmail.py</div>
</div>
<p>Now if you have a bunch of unread messages in your gmail account it will always be red, so you'll have to extend this example if you want to make the new message checking more intelligent. We've learned how to setup a basic indicator applet with it's own menu and icon, and give it a useful piece of functionality. You could easily replace the check_email() function with almost anything else you could program in python normally. Hope this helps to get you started with creating indicators, if you have any questions or comments, please let me know!</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=110&amp;md5=9e5f6fd7a47bdffd6083b08d4abf415f" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/create-indicator-applet-for-ubuntu-unity-with-python/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fcreate-indicator-applet-for-ubuntu-unity-with-python%2F&amp;language=en_GB&amp;category=text&amp;title=Create+Indicator+Applet+for+Ubuntu+Unity+%28with+Python%21%29&amp;description=We%27re+going+to+walk+through+the+process+of+creating+a+status+indicator+applet+for+the+latest+version+of+Ubuntu+running+Unity.+In+this+example+we%27re+going+to+create+a+basic...&amp;tags=Utilities%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Resize HFS+ Partition in Linux</title>
		<link>http://conjurecode.com/resize-hfs-partition-in-linux/</link>
		<comments>http://conjurecode.com/resize-hfs-partition-in-linux/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 19:56:55 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=107</guid>
		<description><![CDATA[Let's say we've got a left over Time Machine backup disk from our old, sacrilegious OSX install, and we'd like to keep those backups but also shrink the partition down and recover some usable space. Here is an easy way to shrink an HFS+ partition in linux. Please use common sense and make sure that [...]]]></description>
			<content:encoded><![CDATA[<p>Let's say we've got a left over Time Machine backup disk from our old, sacrilegious OSX install, and we'd like to keep those backups but also shrink the partition down and recover some usable space. Here is an easy way to shrink an HFS+ partition in linux. Please use common sense and make sure that you have another backup of this data before attempting this.</p>
<p><strong>Note to OSX/Time Machine users:</strong> I've had some people end up here looking for a way to resize their Time Machine partition. You can easily follow this article with an <a href="http://www.ubuntu.com/download/ubuntu/download">Ubuntu Live CD</a>.</p>
<p>First plug in the drive and determine which device it is on. In my case it is /dev/sdb. The first thing we need to do is unmount the partition we're looking to resize. You can figure out which partition that is by running parted, like so:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">sudo</span> parted <span class="sy0">/</span>dev<span class="sy0">/</span>sdb</div>
</div>
<p>You will be greeted with a "(parted)" prompt. Enter "print" to view details of the partitions on the drive. In my case, I want to resize partition 2, so we'll "quit" out of parted and unmount partition 2.</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">sudo</span> <span class="kw2">umount</span> <span class="sy0">/</span>dev<span class="sy0">/</span>sdb2</div>
</div>
<p>Now let's go back into parted and resize our partition. We're going to enter into parted, select the partition we'd like to resize, and then we'll be prompted for a start and end to the partition. In my case, I had about 512Gb of data on my 1TB drive. I also had a small partition before this one, which is why it prompted me to start my partition at 210MB. You should probably select whatever it suggests as the start (by simply not entering anything, the item in brackets is the proposed default), and then selecting an end which is a little larger than your usage. I chose 550GB for my end, just to be safe. Below is an output of the whole process:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;">Welcome to GNU Parted<span class="sy0">!</span> Type <span class="st_h">'help'</span> to view a list of commands.<br />
<span class="br0">&#40;</span>parted<span class="br0">&#41;</span> print &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Model: WD My Passport 071A <span class="br0">&#40;</span>scsi<span class="br0">&#41;</span><br />
Disk <span class="sy0">/</span>dev<span class="sy0">/</span>sdb: 1000GB<br />
Sector <span class="kw2">size</span> <span class="br0">&#40;</span>logical<span class="sy0">/</span>physical<span class="br0">&#41;</span>: 512B<span class="sy0">/</span>512B<br />
Partition Table: gpt</p>
<p>Number &nbsp;Start &nbsp; End &nbsp; &nbsp; Size &nbsp; &nbsp;File system &nbsp;Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Flags<br />
&nbsp;1 &nbsp; &nbsp; &nbsp;20.5kB &nbsp;210MB &nbsp; 210MB &nbsp; fat32 &nbsp; &nbsp; &nbsp; &nbsp;EFI System Partition &nbsp;boot<br />
&nbsp;2 &nbsp; &nbsp; &nbsp;210MB &nbsp; 1000GB &nbsp;1000GB &nbsp;hfsx &nbsp; &nbsp; &nbsp; &nbsp; Time Machine Backups</p>
<p><span class="br0">&#40;</span>parted<span class="br0">&#41;</span> resize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
WARNING: you are attempting to use parted to operate on <span class="br0">&#40;</span>resize<span class="br0">&#41;</span> a <span class="kw2">file</span> system.<br />
parted<span class="st_h">'s file system manipulation code is not as robust as what you'</span>ll <span class="kw2">find</span> <span class="kw1">in</span><br />
dedicated, file-system-specific packages like e2fsprogs. &nbsp;We recommend<br />
you use parted only to manipulate partition tables, whenever possible.<br />
Support <span class="kw1">for</span> performing most operations on most types of <span class="kw2">file</span> systems<br />
will be removed <span class="kw1">in</span> an upcoming release.<br />
Partition number? <span class="nu0">2</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Start? &nbsp;<span class="br0">&#91;</span>210MB<span class="br0">&#93;</span>? &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
End? &nbsp;<span class="br0">&#91;</span>1000GB<span class="br0">&#93;</span>? 550GB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#40;</span>parted<span class="br0">&#41;</span> quit</div>
</div>
<p>After you specify an end point and hit enter, the program will go to work and may take some time to finish. I have a relatively fast machine and I believe the drive is 7200rpm. It took only a few minutes to complete. A successful resize should bring you back to the (parted) prompt. Then just enter "quit" to exit parted. At this point I opened gparted and used it's visual editor to create a file system on the newly created partition. When you plug in the drive you should now see the old and new partitions and have access to all the files on both. Again, please, be smart, back up your data.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=107&amp;md5=a1beb9cf646ce6996e5ab194e343fcdd" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/resize-hfs-partition-in-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fresize-hfs-partition-in-linux%2F&amp;language=en_GB&amp;category=text&amp;title=Resize+HFS%2B+Partition+in+Linux&amp;description=Let%27s+say+we%27ve+got+a+left+over+Time+Machine+backup+disk+from+our+old%2C+sacrilegious+OSX+install%2C+and+we%27d+like+to+keep+those+backups+but+also+shrink+the+partition+down...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Secure browsing with an SSH port-forwarding socks proxy</title>
		<link>http://conjurecode.com/secure-browsing-with-easy-ssh-port-forwarding-socks-proxy/</link>
		<comments>http://conjurecode.com/secure-browsing-with-easy-ssh-port-forwarding-socks-proxy/#comments</comments>
		<pubDate>Sat, 21 May 2011 20:22:34 +0000</pubDate>
		<dc:creator>atrus</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[One Liners]]></category>

		<guid isPermaLink="false">http://conjurecode.com/?p=94</guid>
		<description><![CDATA[When we're browsing the web from a public place we'd like to ensure all our traffic travels over an encrypted channel. W can accomplish this easily with an SSH based proxy. You're going to need a shell (SSH) account on a remote server. The following process will work on *nix and OSX and probably other [...]]]></description>
			<content:encoded><![CDATA[<p>When we're browsing the web from a public place we'd like to ensure all our traffic travels over an encrypted channel. W can accomplish this easily with an SSH based proxy. You're going to need a shell (SSH) account on a remote server. The following process will work on *nix and OSX and probably other systems as well. For windows you'll want to use something like <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">PuTTY/Plink</a>, but beyond that you're on your own.</p>
<p>Create a file in your home directory and name it whatever you like, I'm using tunnel.sh. In that file enter the following:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">ssh</span> user<span class="sy0">@</span>server.com <span class="re5">-p</span> 22 <span class="re5">-ND</span> <span class="nu0">8080</span></div>
</div>
<p>First of all, pay attention to case here, we're using a lower case -p to specify the remote port we're connecting on, and a capital -D to specify the local port to serve the proxy from. If you're connecting to your server via port 22 like the example you can actually leave it off, but I've included it in the example since many sysadmins use non-standard ports for ssh (and so should you, if possible). The -N is optional and signals SSH not to open a shell session, so after you've connected and provided a password, the command will simply sit there as if it were hanging, instead of providing you with a command prompt.</p>
<p>Let's flag our file as executable:</p>
<div class="codesnip-container" >
<div class="bash codesnip" style="font-family:monospace;"><span class="kw2">chmod</span> +x tunnel.sh</div>
</div>
<p>Now we can run our file which will connect to your server and prompt you for your password. Once you enter your password it will simply sit there. You must keep this window open, so either minimize it or move it to a different desktop if you can. Now we have a SOCKS5 compatible port-forwarding proxy at our disposal. Normally when you make a request over the internet, it travels from your computer's network card to your local router and then to the internet in effectively plaintext. Anyone with the slightest inclination is able to view what sites you're visiting, and obtain your login information if it is not being transmitted in a secure fashion (including email, ftp, and many websites). You may have been following the whole <a href="http://codebutler.com/firesheep">firesheep fiasco</a>.</p>
<p>Now that we have our SSH proxy running, we can tunnel all of our traffic through an SSH encrypted channel which effectively hides all of your internet traffic from curious/malicious users on your local network. In order to do this we have to tell our software to use the local proxy running on port 8080. For firefox I recommend <a href="http://getfoxyproxy.org/">foxyproxy</a></a>. Most instant messengers allow you to use a proxy for a given account. In either case, you need to make sure that you use "localhost", port 8080, and check the options for SOCKS5 proxy. You can check that it works by checking your IP at <a href="http://checkip.dyndns.org/">http://checkip.dyndns.org</a> before and after enabling the proxy.</p>
 <p><a href="http://conjurecode.com/?flattrss_redirect&amp;id=94&amp;md5=582fee8cf6bbe17ac3b46f8b021ce845" title="Flattr" target="_blank"><img src="http://conjurecode.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conjurecode.com/secure-browsing-with-easy-ssh-port-forwarding-socks-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=sophistihip&amp;popout=1&amp;url=http%3A%2F%2Fconjurecode.com%2Fsecure-browsing-with-easy-ssh-port-forwarding-socks-proxy%2F&amp;language=en_GB&amp;category=text&amp;title=Secure+browsing+with+an+SSH+port-forwarding+socks+proxy&amp;description=When+we%27re+browsing+the+web+from+a+public+place+we%27d+like+to+ensure+all+our+traffic+travels+over+an+encrypted+channel.+W+can+accomplish+this+easily+with+an+SSH+based...&amp;tags=One+Liners%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>

