<?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>FOSS &#8211; Web 0.2</title>
	<atom:link href="http://www.held.org.il/blog/tag/foss/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.held.org.il/blog</link>
	<description>Linux, FOSS, Web and more: a buzzword-free blog</description>
	<lastBuildDate>Thu, 28 Mar 2013 11:05:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.7.15</generator>
	<item>
		<title>Navigating through the git history like a boss</title>
		<link>http://www.held.org.il/blog/2013/03/navigating-through-the-git-history-like-a-boss/</link>
					<comments>http://www.held.org.il/blog/2013/03/navigating-through-the-git-history-like-a-boss/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Thu, 28 Mar 2013 11:05:32 +0000</pubDate>
				<category><![CDATA[development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[git]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=390</guid>

					<description><![CDATA[[ If you're not into reading why I find git history useful, you may jump right into the command-line coolness! ] I love reading git logs! First, because it reveals the people and processes behind software. Software is not just a bunch of code that works (or more commonly, doesn't work...) - it's also a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[ If you're not into reading why I find git history useful, you may <a href="#tahles">jump right into the command-line coolness!</a> ]</p>
<p>I love reading git logs! First, because it reveals the people and processes behind software. Software is not just a bunch of code that works (or more commonly, doesn't work...) - it's also a bunch of people crafting something together for a long time. Not only adding features and fixing bugs, but they also refactor, do dirty tasks and ugly workarounds, explaining their motives in the commit messages.</p>
<p>A second, more concrete reason - quick access to git history helps me make better software. It helps me find out when and how exactly a bug was introduced, learn whom to talk to about a certain change or code, or simply find a desired code snippet in a huge repository - even if it was already deleted. Am I stating the obvious here? I guess so! but I do believe that sometimes this tool is underestimated and underused.<br />
<span id="more-390"></span></p>
<p>Of course, the better we know git's secrets, the more effective use of git history we could make. I'll try to share here some useful tricks I've collected in the recent years... I bet you know some; I believe you may still find some of them useful.</p>
<p><a name="tahles"></a>Alright, enough human communication - let the command-line part begin:</p>
<h2>1. Find commits by their commit message - --grep</h2>
<p>Impress your boss at how quickly you find this commit!</p><pre class="crayon-plain-tag">git log -p --grep &quot;nasty bug&quot;

# Feeling lucky? 
git show :/'nasty bug'</pre><p></p>
<h2>2. Search by commit content - -S</h2>
<p>This one will show you only commits that contain the provided string in the commit content itself. Super useful!</p><pre class="crayon-plain-tag">git log -p -S 'Date.new'</pre><p></p>
<h2>3. Search by author</h2>
<p>You know who's responsible for this change you're looking for, so why not use this to ease the search?</p><pre class="crayon-plain-tag">git log -p --author='Linus Torvalds'

# Can even use parts of the name or email:
git log -p --author=orvalds
git log -p --author=gmail.com</pre><p></p>
<h2>4. Find by date</h2>
<p></p><pre class="crayon-plain-tag">git log -p --since=2013-01-01 --until=2012-02-01</pre><p></p>
<h2>5. By path!</h2>
<p></p><pre class="crayon-plain-tag">git log -p -- path/to/file1 path/to/directory ...

# Add --follow to follow changes through file renames:
git log -p --follow -- path/to/file1</pre><p></p>
<h2>6. Search ALL branches</h2>
<p>Lost something?</p><pre class="crayon-plain-tag">git log -S 'populate_database' --all</pre><p></p>
<h2>7. Putting (some of) it all together</h2>
<p>I actually find such commands useful in practice.</p><pre class="crayon-plain-tag">git log -p --author=linus --since=2012-06-01 --until=2013-01-01 --grep fix -S 'Date.new' -- that_directory/</pre><p></p>
<h2>8. A few useful revision-range tricks</h2>
<h3>a. What's new in my branch compared to remote?</h3>
<p></p><pre class="crayon-plain-tag">git log -p origin/master..master

# But I like the following syntax better; it's exactly the same but self-explanatory:
# all commits of master branch that are not contained in origin/master branch. 
git log -p master ^origin/master

# Also possible to put multiple arguments
git log -p master ^origin/master ^my_github/master</pre><p>(Note: I've noticed that zsh needs the '^' character to be escaped!)</p>
<h3>b. 3-dots operator: symmetric difference</h3>
<p>The less-widely-known-but-very-useful 3-dots operator, shows any commit that is in any of the branches but not in both:</p><pre class="crayon-plain-tag">git log -p mybranch...master

# --cherry-pick is often useful to avoid seeing &quot;duplicate commits&quot;. 
# common when cherry-picking, where commits identical content get 
# different hashes.
git log -p --cherry-pick mybranch...master</pre><p></p>
<h2>Read more!</h2>
<p></p><pre class="crayon-plain-tag">git help log
git help revisions
git help blame</pre><p></p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2013/03/navigating-through-the-git-history-like-a-boss/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Restarting the Linux sound subsystem</title>
		<link>http://www.held.org.il/blog/2012/06/restarting-the-linux-sound-subsystem/</link>
					<comments>http://www.held.org.il/blog/2012/06/restarting-the-linux-sound-subsystem/#respond</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Mon, 25 Jun 2012 08:32:57 +0000</pubDate>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[alsa]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[no headphones]]></category>
		<category><![CDATA[pulseaudio]]></category>
		<category><![CDATA[snd_hda_intel]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=364</guid>

					<description><![CDATA[Sometimes my laptop gets to a state in which sound works through the built-in speakers, but not through the headphone jack. Possibly my solution is too brutal, but it works -Â  restarting the whole sound subsystem. I guess that it may come handy in other situation: the ability to restart a subsystem instead of rebooting [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Sometimes my laptop gets to a state in which sound works through the built-in speakers, but not through the headphone jack. Possibly my solution is too brutal, but it works -Â  restarting the whole sound subsystem. I guess that it may come handy in other situation: the ability to restart a subsystem instead of rebooting the machine, is always an advantage.</p>
<p>The rationale is simply reloading the kernel module that acts as a driver to our sound hardware. Reloading isn't easy, as:</p>
<ol>
<li>Kernel modules use this module.</li>
<li>User processes use this module.</li>
</ol>
<p><span id="more-364"></span><br />
So the solution is to first kill all processes which use the sound (on a healthy system nowadays it's only pulseaudio), recursively <em></em> unload sound driver and the modules that depend on it, then reload the main kernel module. On my system, with Intel sound card, the sound driver's module name is <em>snd_hda_intel</em>.</p>
<p>Therefore here is the full, 3-step process:</p>
<p style="padding-left: 30px;">[cc lang="bash"]$ killall pulseaudio; sleep 3; killall -9 pulseaudio[/cc]</p>
<p style="padding-left: 30px;">Note: you'll need sudo if there are pulseaudio processes running as other users.</p>
<p style="padding-left: 30px;">[cc lang="bash"]$ sudo modprobe -r snd_hda_intel[/cc]</p>
<p style="padding-left: 30px;">Note: make sure modprobe didn't throw an error. If it did, there's probably still a process using the kernel module. Sometimes that's because a new pulseaudio process got created.</p>
<p style="padding-left: 30px;">[cc lang="bash"]$ sudo modprobe snd_hda_intel[/cc]</p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2012/06/restarting-the-linux-sound-subsystem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Improve your shell experience with tmux &#038; ConqueTerm</title>
		<link>http://www.held.org.il/blog/2012/06/improve-your-shell-experience-with-tmux-conqueterm/</link>
					<comments>http://www.held.org.il/blog/2012/06/improve-your-shell-experience-with-tmux-conqueterm/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Tue, 19 Jun 2012 04:09:35 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[conqueterm]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[textmode]]></category>
		<category><![CDATA[tmux]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=344</guid>

					<description><![CDATA[As a power text-mode user, I was both surprised and glad to hear (10x @erikzaadi!) about two interesting tools: tmux &#38; ConqueTerm, which significantly changed the way I use the shell/terminal. I'll try to keep it short and to the point, and briefly explain the most notable behavior-changing features the way I see them. Or [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As a power text-mode user, I was both surprised and glad to hear (10x <a href="http://www.twitter.com/erikzaadi">@erikzaadi</a>!) about two interesting tools: <a href="http://tmux.sourceforge.net/">tmux</a> &amp; <a href="http://code.google.com/p/conque/">ConqueTerm</a>, which significantly changed the way I use the shell/terminal. I'll try to keep it short and to the point, and briefly explain the most notable behavior-changing features the way I see them. Or in other words: why should you give them a try.</p>
<h3>tmux</h3>
<p><a href="http://tmux.sourceforge.net/">tmux</a> is <em>screen</em>-like. I didn't get to learn much of <em>screen</em> (absolutely my bad), so it's really not a "why tmux is better than screen" post, but simply what goodies does tmux provide.</p>
<h4>tmux goodies:<span id="more-344"></span></h4>
<ul>
<li><strong>Detach and reattach to the whole session.</strong> Even when X/ssh dies: this is basic, and that's what <em>screen</em> is most widely known for, but it's so important.<br />
<strong>&gt; list all sessions: tmux ls<br />
&gt; attach a certain session: tmux attach [-t &lt;num&gt;]</strong><br />
<strong></strong></li>
<li><strong>Keep</strong> <strong>multiple copy-paste buffers</strong>. It'll stay there for as long as the session is alive. It'll not live through reboots, but will live multiple days through ssh logins, X crashes. When using multiple tmux sessions (e.g. I have one on each screen), all share the same copy-paste buffer. Bonus: no mouse involved <img src="https://s.w.org/images/core/emoji/13.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /><br />
<strong>&gt; Copy: </strong>Ctrl+B+[ . I find it much easier keyboard-wise withÂ  'set -g mode-keys vi' in ~/.tmux.conf. So that I move with vim keys (0, $, b, B, w, W), Space starts selection, Enter finishes.<br />
<strong>&gt; Paste:</strong> Ctrl+B+]<br />
<strong>&gt; View clipboard buffers and choose what to paste: </strong>Ctrl+B+=Â  (so cool!)</li>
<li><strong>Keyboard controlled tabs</strong> ("windows") and window splits ("panes"). It's hard to explain its strength, but think of running some long running command - you want to see the output but in the meantime to run something else. Ctrl+B+^ will split the screen and provide bring a new shell above it. Much nicer than shell job control.<br />
&gt; <strong>Create panes:</strong> Ctrl+B+", Ctrl+B+% . <strong>Navigate:</strong> Ctrl+B+Arrow keys<br />
<strong>&gt; Create window:</strong> Ctrl+B+c . <strong>Navigate:</strong>Ctrl+B+(p/n/#)</p>
<ul>
<li><strong>Run command in a split: </strong>this one is very handy. Split dies when command dies.<br />
<strong>&gt; tmux split [-h] top</strong><br />
<strong>&gt; tmux new-window tar -xvf /tmp/my.tar.gz</strong></li>
</ul>
</li>
<li><strong>Scrollable, searchable, copyable, super-long buffer:</strong> basic, but well-made.</li>
<li><strong>Remote pair programming: </strong>it's a killer one. I know, <em>screen</em> has it too, but it's worth mentioning. The other peer, being logged in to the same host as the same user as you, simply needs to use 'tmux attach' to attach to the specific session.</li>
<li><strong><a href="https://github.com/aziz/tmuxinator">tmuxinator</a></strong>: I didn't yet make good use of it, but it certainly redefines the meaning of "cool".</li>
</ul>
<p>You can check out my <a href="https://github.com/orenhe/dotfiles/blob/master/.tmux.conf">tmux.conf</a>, and this <a href="https://github.com/scharan/Goodies/blob/master/ssh-agent-restore">ssh-agent-restore helper</a>.</p>
<h3>ConqueTerm - a console buffer inside vim</h3>
<p>I never got to play well with Emacs. But I must admit it's strong. One of the features I got excited about was that anything is a buffer, either a text file or a console. And since seeing it, I was looking for a vim equivalent. And just when I gave up, ConqueTerm appeared.</p>
<h4>ConqueTerm goodies:</h4>
<ul>
<li><strong>Output is a vim buffer</strong>: it's fun using the familiar vim tools on your output: search, navigate, select and copy, % for brace matching, etc.</li>
<li><strong>Copy-and-paste</strong> between a regular edited file and the terminal buffer in both directions.</li>
<li><strong>Brace matching</strong> on command line: running a complex command line with all sorts of braces? a well-configured VIM would highlight the matching brace when cursor is over it.</li>
<li><strong>Keyboard-controlled</strong> <strong>window sizing and position</strong>: create the terminal buffer as a vertical split, resize, etc.<br />
<strong>&gt; Also possible to modify after creation: </strong>I found Ctrl+W+J (capital J) pretty useful, as well as the other H,K,L vim navigation keyskeys). It changes the window layout by saying "current window stays on bottom and uses all of it.<strong></strong></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2012/06/improve-your-shell-experience-with-tmux-conqueterm/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Introducing myip (no more ifconfig eye-grep!)</title>
		<link>http://www.held.org.il/blog/2012/06/introducing-myip/</link>
					<comments>http://www.held.org.il/blog/2012/06/introducing-myip/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Fri, 01 Jun 2012 22:51:34 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[ifconfig]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=358</guid>

					<description><![CDATA[Complex tools for a simple task It's common for us, users and admins, to check what is the ip of the host we are logged in to. Currently on Linux, this task is commonly done by the ip and ifconfig tools. However, I find them way too complex for the simple task of checking what's [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Complex tools for a simple task</h2>
<p>It's common for us, users and admins, to check what is the ip of the host we are logged in to. Currently on Linux, this task is commonly done by the <em>ip</em> and <em>ifconfig</em> tools. However, I find them way too complex for the simple task of checking what's the IP. their output is full of confusing, irrelevant details, and they have tons of command-line arguments.</p>
<h2>But you can pipe it all through grep, sed and awk!</h2>
<p>Well... I'm not even going to explain why it isn't friendly.</p>
<h2>myip for the rescue</h2>
<p>So after I failed to find a simple tool for displaying IPs, I started writing it myself. Some command line samples:<span id="more-358"></span></p>
<p>1. Show primary IP:<br />
<code lang="bash"># myip<br />
192.168.1.100</code><br />
2. Show all IPs:<br />
<code lang="bash"># myip --all<br />
1.2.3.4<br />
192.168.1.100<br />
192.168.122.1</code><br />
3. Show IP of a specific interface:<br />
<code lang="bash"># myip eth0<br />
1.2.3.4</code><br />
More info &amp; download on the github page, <a href="https://github.com/orenhe/myip">Check it out</a> and submit pull requests <img src="https://s.w.org/images/core/emoji/13.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2012/06/introducing-myip/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>How I converted a VMware VM to KVM</title>
		<link>http://www.held.org.il/blog/2012/04/how-i-converted-vmware-vm-to-kvm/</link>
					<comments>http://www.held.org.il/blog/2012/04/how-i-converted-vmware-vm-to-kvm/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Mon, 30 Apr 2012 11:29:50 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[qcow2]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[vmdk]]></category>
		<category><![CDATA[vmware]]></category>
		<category><![CDATA[vmx]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=347</guid>

					<description><![CDATA[There's lots of info on the net on achieving that, but I found it a bit too scattered, and had to combine instructions from multiple sources. I'm not certain it's the right way, but it workedâ„¢. So I'll share, and get your feedback in case I've done anything stupid: Convert VMDKs (VM's disk), even when [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>There's lots of info on the net on achieving that, but I found it a bit too scattered, and had to combine instructions from multiple sources.</p>
<p>I'm not certain it's the right way, but it workedâ„¢. So I'll share, and get your feedback in case I've done anything stupid:</p>
<ol>
<li><strong>Convert VMDKs<strong> (VM's disk)</strong>, even when having multiple files,Â  to qcow2 format</strong> (note: QVM/QEMU should be able to deal with vmdk files (multiple as well?), so possibly this step is redundant):<br />
<pre class="crayon-plain-tag"># qemu-img convert &lt;vmdk wildcard&gt; &lt;qcow2 file&gt;</pre>
</li>
<li><strong>Convert the vmx (VM's settings) to xml (requires vmware2libvirt tool found in <em>virt-goodies</em> package)</strong><br />
<pre class="crayon-plain-tag"># vmware2libvirt -f &lt;source.vmx&gt;&Acirc;&nbsp;&gt; target.xml</pre>
</li>
<p><span id="more-347"></span></p>
<li><strong>import the xml</strong>:<br />
<pre class="crayon-plain-tag"># virsh -c qemu:///system define file.xml</pre>
</li>
<li><strong>re-add the disk as a qcow2 disk</strong>:<br />
Shame on me, I did it through the GUI:</p>
<ol>
<li>Run virt-manager</li>
<li>You should see the new VM now, cool! Open it.</li>
<li>From the view menu, switch to 'details' mod</li>
<li>Remove the existing (VMDK) disk, and re-add the qcow2 disk instead:
<ol>
<li>Find the disk and remove it from the VM. Your probably want to make sure the checkbox for deleting the data is unchecked.</li>
<li>Add Hardware -&gt; Storage -&gt; Select "managed or other existing storage" -&gt; Browse -&gt; choose your qcow2 file</li>
<li>At "device type" select box, choose the proper type (IDE worked for me)</li>
<li>At "storage format" select box, choose 'qcow2'.</li>
<li>Click "Finish"</li>
</ol>
<p>&nbsp;</li>
</ol>
</li>
<li>Uninstall vmware</li>
</ol>
<p>A few notes:</p>
<ul>
<li>I used a very simple VM configuration (e.g. Linux, single harddisk, NAT networking, no sound)</li>
<li>I guess I lost the original snapshots</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2012/04/how-i-converted-vmware-vm-to-kvm/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>Raise or Return? (using exceptions, part 1)</title>
		<link>http://www.held.org.il/blog/2012/01/raise-or-return-using-exceptions-part-1/</link>
					<comments>http://www.held.org.il/blog/2012/01/raise-or-return-using-exceptions-part-1/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Sat, 28 Jan 2012 23:18:41 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[craftsmanship]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=333</guid>

					<description><![CDATA[Ever since I've been using exceptions, uncertainty has always been there: when are we better off with return codes? when is it smart to catch the exceptions? when should they better be left untouched and propagate higher? Create a separate exception class, or just pass an argument to the constructor? During the recent few years, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Ever since I've been using exceptions, uncertainty has always been there: when are we better off with return codes? when is it smart to catch the exceptions? when should they better be left untouched and propagate higher? Create a separate exception class, or just pass an argument to the constructor?</p>
<div style="width: 190px" class="wp-caption alignright"><a href="http://www.flickr.com/photos/jmchuff/2403104412/"><img loading="lazy" class=" " src="http://farm3.staticflickr.com/2405/2403104412_27594979f1_m_d.jpg" alt="" width="180" height="240" /></a><p class="wp-caption-text">cc-by-sa Jason McHuff</p></div>
<p>During the recent few years, I've been gathering some best practices I learned from my peers and by experience, which I'll dump here to a short series of posts. I hope it'll help to provoke some discussion on this rather important design matter. As it's a highly debatable matter, discussions are more effective than trying to declare the ultimate truth of proper usage of exceptions.</p>
<p>Most of my experience in this area is related to Python, but I believe the same discussion usually applies to all dynamic languages, and possibly to languages that use <em>throw</em> rather than <em>raise</em>.</p>
<p>Enough disclaimers, let's get started. An easy one for starters:<br />
<span id="more-333"></span></p>
<h2><strong>Part 1: Should a function raise an exception or return a failure value?</strong></h2>
<p>Exceptions, as their name suggests, should be raised in <strong>exceptional cases</strong>. To differentiate between exceptional and normal, I usually ask myself <strong>what's the purpose of the function. </strong>If a function is well-named (it should be!), it gets easy to deduce that. [I also find <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> very helpful in deciding what's the purpose of a function, and thus how to properly name it]</p>
<p>To sum up my take on this, in a single sentence: <strong><span style="color: #008000;"><br />
</span>Exceptions should be raised only when the function encounters a case that is out of the scope of its purpose.</strong></p>
<h2>Distinctive examples</h2>
<h4><span style="color: #00ff00;"><strong>Do raise an exception - something out-of-scope has occurred:</strong></span></h4>
<ul>
<li><strong><em>read_file_contents(file_handle)</em></strong>, may raise an exception if file handle is closed or if read has unexpectedly failed.<br />
e.g. FileReadError()<br />
<strong>Update: </strong>My assumption here is that the file open operation occurred earlier and succeeded; this makes read errors exceptional and not expected.<strong></strong></li>
<li><em><strong>parse_configuration(data)</strong></em> may raise an exception if given data is bad.<br />
e.g. BadConfigurationDataError()<br />
<strong>Update:</strong> I refer here to an internal not-user-modifiable configuration file, which renders a parsing failure exceptional and not expected.</li>
</ul>
<h4><span style="color: #ff0000;"><strong>Don't raise (return a value) - something normal, in-scope, has occurred:</strong></span></h4>
<ul>
<li><strong><em>file.is_open()</em></strong> should NOT throw an exception if file is not open: its name suggests its a boolean function, therefore it should return False. A closed file is a normal case for this function.</li>
<li>
<div style="width: 250px" class="wp-caption alignright"><a href="http://www.flickr.com/photos/msr/448820990/"><img loading="lazy" class=" " src="http://farm1.staticflickr.com/249/448820990_099a4aa69f_m_d.jpg" alt="" width="240" height="163" /></a><p class="wp-caption-text">cc-by-nc msr</p></div>
<p><em><strong>apples.count()</strong></em> - if apple count is 0, I would expect the function to return 0, rather thanÂ  raising <em>ZeroApplesError() exception</em>. Zero apples is a normal case for a the scope of the <em>count</em>() function.<br />
But it's not always that obvious! In the larger context (e.g. an apple juice factory control program), zero apples may seem like an exceptional case - but we should look at the <strong>scope of the function</strong> and not beyond. In this hypothetical juice factory case, it WILL make sense to raise an exception at a higher-level function such as <em>squeeze_apples()</em>, if <em>apples.count()</em> == 0.</li>
</ul>
<p>Of course in reality we encounter cases which are harder to differentiate, but I find it useful to compare the real cases to these fictional edge cases. Furthermore, even these edge cases DO happen sometimes...</p>
<p>Do you agree? disagree? Do you find cases where even the most unexpected error should return -1 rather than raise an exception? Add your comments.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2012/01/raise-or-return-using-exceptions-part-1/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Network-Manager 0.9.2 WiFi password issues</title>
		<link>http://www.held.org.il/blog/2011/12/network-manager-0-9-2-wpa-password-issues/</link>
					<comments>http://www.held.org.il/blog/2011/12/network-manager-0-9-2-wpa-password-issues/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Tue, 27 Dec 2011 21:38:56 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[network-manager]]></category>
		<category><![CDATA[NetworkManager]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=330</guid>

					<description><![CDATA[I've noticed a few significant issues with Network Manager on GNOME 3.2, when connecting to WiFi networks that require password (e.g. WPA, EAP). Trying to find existing bug reports, I've found quite a mess: multiple bug reports, both downstream (Debian, Ubuntu, Fedora) and upstream (GNOME bugzilla). I suspect many of these bugs are related to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I've noticed a few significant issues with Network Manager on GNOME 3.2, when connecting to WiFi networks that require password (e.g. WPA, EAP). Trying to find existing bug reports, I've found quite a mess: multiple bug reports, both downstream (Debian, Ubuntu, Fedora) and upstream (GNOME bugzilla).</p>
<p>I suspect many of these bugs are related to the same root cause (or max. 2-3 root causes). In order to try and make sense of this, I tried to categorize the bugs I've found. I hope it'll help to gather more info to resolve the bugs, and reject dups.</p>
<ol>
<li><strong>NM (gnome applet?) forgets passwords</strong>:</li>
<ol>
<li>GNOME Bugzilla: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=666465">[666465], </a><a href="https://bugzilla.gnome.org/show_bug.cgi?id=665431">[665431]</a>, <a href="https://bugzilla.gnome.org/show_bug.cgi?id=665503#c1">[665503]</a></li>
<li>Debian BTS: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=646018">[651445]</a>, <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=651445">[646018]</a></li>
<li>Ubuntu BTS: <a href="https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/904666">[904666]</a></li>
<li>Mint <a href="http://forums.linuxmint.com/viewtopic.php?f=194&amp;t=86924&amp;p=514038">forum post</a> with a workaround</li>
</ol>
<li><strong>NM takes too long to re-connect</strong> after resume (possibly problem in popping up the enter-password dialog box):</li>
<ol>
<li>GNOME: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=664289">[664289]</a>,</li>
<li>Debian: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=651358">[651358]</a>, <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653076">[653076]</a></li>
</ol>
<li><strong>NM-gnome double password dialog box case</strong>:</li>
<ol>
<li>GNOME: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=661208">[661208]</a>, <a href="https://bugzilla.gnome.org/show_bug.cgi?id=665503#c1">[665503]</a> - mentioned in 1st comment,</li>
<li>Debian: <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=651097">[651097]</a></li>
</ol>
</ol>
<p>I'll try to update this post when new info arrives, please add your comments.</p>
<p>Generally speaking, I think that FOSS community lacks some "dirty-work" QA workforce for bug scrubbing, such as what I'm trying to do here. I don't even know how to name this non-coding activity. Thoughts? <img src="https://s.w.org/images/core/emoji/13.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><strong>Update1: </strong>This Linux Mint <a href="http://forums.linuxmint.com/viewtopic.php?f=194&amp;t=86924&amp;p=514038">forum post</a> suggests that only the applet "forgets" passwords.</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2011/12/network-manager-0-9-2-wpa-password-issues/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Reviving the hibernate feature on Debuntu</title>
		<link>http://www.held.org.il/blog/2011/09/reviving-the-hibernate-feature-on-debuntu/</link>
					<comments>http://www.held.org.il/blog/2011/09/reviving-the-hibernate-feature-on-debuntu/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Sun, 25 Sep 2011 14:29:36 +0000</pubDate>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[power]]></category>
		<category><![CDATA[suspend]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=318</guid>

					<description><![CDATA[My laptop's battery had just died. It made me realize how much I depend on it, for changing my working location, either when computer is awake or asleep for many hours. Without a battery, the sleep (aka suspend-to-ram) feature is less useful, for the tiniest power interruption would kill it. So I had to go [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>My laptop's battery had just died. It made me realize how much I depend on it, for changing my working location, either when computer is awake or asleep for many hours. Without a battery, the <em>sleep</em> (aka suspend-to-ram) feature is less useful, for the tiniest power interruption would kill it.<span id="more-318"></span></p>
<p>So I had to go back and use the old <em>hibernate </em>feature<em></em> (aka suspend-to-disk), as powering off-and-on the computer on daily basis is not a reasonable option. But, <em>hibernate</em> never worked for me for quite a while - clicking in my GNOME "System -&gt; Shut Down -&gt; Hibernate" did nothing more than a hard-to-notice flicker. So I had to research this:</p>
<ul>
<li><strong>Insight #1:</strong> suspending/hibernating from GNOME 2 indirectly triggers the tools: <strong><em>pm-suspend</em>, <em>pm-hibernate </em></strong>(from pm-utils package). Running <em>pm-hibernate</em> manually from a terminalÂ  revealed the problem I had by printing the error to screen (and also later I found it in <em>/var/log/pm-suspend.log)</em>:</li>
</ul>
<blockquote><p>
</p><pre class="crayon-plain-tag">s2disk: Could not stat the resume device file. Reason: No such file or directory</pre><p>
</p></blockquote>
<ul>
<li><strong>Insight #2:</strong> pm-utils make use of uswsusp (userspace software suspend utils): <em>s2disk</em>, <em>s2ram</em>, <em>s2both</em></li>
<li><strong>Insight #3:</strong> <em>/etc/initramfs-tools/conf.d/resume </em>defines the resume device file (swap device) for the initrd.</li>
<li><strong>Insight #4:</strong> If swap device is a device-mapper device (such as a Logical Volume on LVM) - one should be using <strong>RESUME=/dev/mapper/&lt;name&gt;.</strong> Notations such as UUID=&lt;ID&gt; or /dev/dm-nn <strong>don't</strong> seem to work, triggerring the following error on boot:</li>
</ul>
<blockquote><p>
</p><pre class="crayon-plain-tag">resume: could not stat the resume device file '# RESUME=/dev/sda6
UUID=UUID=038df595-f105-4653-a2a4-7c051f90dd10'
             Please type in the full path name to try again or press
ENTER to boot the system:</pre><p>
</p></blockquote>
<ul>
<li><strong>Insight #5:</strong> <em>dpkg-reconfigure uswsusp</em> reconfigures the whole thing, and regenerates the initrd (thus applying the newly defined RESUME device).</li>
</ul>
<p>To summarize, that's how I solved it:</p>
<ul>
<li>updated <em>/etc/initramfs-tools/conf.d/resume</em> to:</li>
</ul>
<blockquote><p>RESUME=/dev/mapper/myvg-swapvol</p></blockquote>
<ul>
<li>Ran <em>dpkg-reconfigure uswsuspÂ </em></li>
<li>Tested it by running <em>pm-hibernate</em></li>
</ul>
<p><strong>Additional tip:</strong> <em>suspend-hybrid</em> is very cool - both writes to disk and RAM: if RAM power survived, wake-up process would be instantaneous. Otherwise, it'll behave as regular hibernate. To use it, simply use <em>pm-suspend-hybrid</em>. GNOME2 doesn't seem to have it in its GUI, I haven't checked GNOME3 out yet.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2011/09/reviving-the-hibernate-feature-on-debuntu/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>pylint Vim plugin update (0.24.0 support)</title>
		<link>http://www.held.org.il/blog/2011/08/pylint-vim-plugin-update-0-24-0-support/</link>
					<comments>http://www.held.org.il/blog/2011/08/pylint-vim-plugin-update-0-24-0-support/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Wed, 24 Aug 2011 21:53:41 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[pylint]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vim]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=315</guid>

					<description><![CDATA[[Executives' summary (in case any executive uses Vim) - get this updated pylint.vim for compatibility with pylint 0.24.0 changes]Â  Integrating Python code checker into Vim is really cool. It lets Vim provide (relatively) quick feedback on your code, be it a conventions warning or syntax error. That, in my opinion, increases coding productivity slightly. The [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>[Executives' summary </strong>(in case any executive uses Vim)<strong> - get <a href="https://github.com/orenhe/pylint.vim">this updated pylint.vim</a> for compatibility with pylint 0.24.0 changes]Â </strong></p>
<p>Integrating <a href="http://pypi.python.org/pypi/pylint">Python code checker</a> into <a href="http://www.vim.org">Vim</a> is really cool. It lets Vim provide (relatively) quick feedback on your code, be it a conventions warning or syntax error. That, in my opinion, increases coding productivity slightly.</p>
<p>The problem is, that configuring the vim-pylint integration is hell. for two reasons mainly:</p>
<ol>
<li>Doing it manually requires understanding of the unpleasant errorformat syntax and some other vim tricks.</li>
<li>No good zero-setup plugin is available: <a href="http://www.vim.org/scripts/script.php?script_id=891">official pylint.vim</a> is unmaintained. I used to use <a href="code.google.com/p/vim-python-ide/">this fork</a>, but its not really active anymore.</li>
</ol>
<p>Specifically, since I upgraded to latest pylint (0.24.0),Â  Vim stopped showing pylint's hints. That's because pylint's output was modified to contain the column number as well.</p>
<p>I've <a href="https://github.com/orenhe/pylint.vim">re-forked it</a>, and updated it to support pylint 0.24.0. Note that it will probably fail with older versions. Please try it and <a href="https://github.com/orenhe/pylint.vim/issues">send feedback</a> (you can comment this post if easier).</p>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2011/08/pylint-vim-plugin-update-0-24-0-support/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>The mysterious case of broken SSH client (&#8220;connection reset by peer&#8221;)</title>
		<link>http://www.held.org.il/blog/2011/05/the-myterious-case-of-broken-ssh-client-connection-reset-by-peer/</link>
					<comments>http://www.held.org.il/blog/2011/05/the-myterious-case-of-broken-ssh-client-connection-reset-by-peer/#comments</comments>
		
		<dc:creator><![CDATA[Oren Held]]></dc:creator>
		<pubDate>Wed, 04 May 2011 19:12:52 +0000</pubDate>
				<category><![CDATA[FOSS]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[11.04]]></category>
		<category><![CDATA[5.7p1]]></category>
		<category><![CDATA[5.8p1]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[natty]]></category>
		<category><![CDATA[openssh]]></category>
		<category><![CDATA[sid]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unstable]]></category>
		<category><![CDATA[wheezy]]></category>
		<guid isPermaLink="false">http://www.held.org.il/blog/?p=301</guid>

					<description><![CDATA[Update: from the info I've gathered, this is most probably a problem with some Cisco IDS/DPI is running on the ethernet equipment. Workaround is available in the content below, I still don't know what's the real solution here (Cisco equipment config? update Cisco firmware?) --- Starting with 5.7p1, ssh client on specific environments fails connecting [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Update: </strong>from the info I've gathered, this is most probably a problem with some Cisco IDS/DPI is running on the ethernet equipment. Workaround is available in the content below, I still don't know what's the real solution here (Cisco equipment config? update Cisco firmware?)</p>
<p>---</p>
<p>Starting with 5.7p1, ssh client <strong>on specific environments</strong> fails connecting to <strong>specific </strong>(usually old versioned) servers. I reproduced it on a particular network, while trying to connect using new ssh client (5.8p1, Ubuntu 11.04) to an old server (default SSH server on RedHat 5.4).</p>
<p><strong>Motivation</strong></p>
<p>This issue is around for quite a while, but is very tricky to reproduce or understand. What bothered me most is that many people reported it to different forums, each posting only a few (different) pieces of the puzzle. So my motivation here is to try and summarize the relevant info from multiple places. I'll do my best to update this post when I hear something new.</p>
<p><strong>Complete Fact list<span id="more-301"></span><br />
</strong></p>
<ol>
<li>Problem is present on 5.7p1, 5.8p1.</li>
<li>Exact same version (e.g. 5.7p1) works on some environments, and fails on others. (My definition to "environment": particular client machine, particular server machine, on a particular network)</li>
<li>On the "bad" environments, the problem is 100% reproducible. SSH dies immediately right after connection with the "connection reset by peer" message. Running ssh -vvv don't shed too much light on this problem (see <a href="https://www.nowhere.dk/articles/natty-narwhal-problems-connecting-to-servers-behind-cisco-firewalls-using-ssh">here</a>).</li>
<li><strong>Workarounds: </strong>On the "bad" environments, the two following workarounds are known to always work around the problem:
<ol>
<li>Shortening the cipher list ('ssh -c aes256-ctr').</li>
<li>Shortening the HostKeyAlgorithms list</li>
</ol>
</li>
<li>On the "bad" environments, enlarging the cipher list manually using '-c aes256-ctr,,,,,,' with enough commas, triggers the problem. It's easy to find a deterministic (per-environment) threshold for the length of the cipher list. More than this threshold - breaks ssh client, less - works perfectly.</li>
<li>On "bad" environments, downgrading to an older release (5.5p1) resolves the problem.</li>
<li>I (among many others) reported the problem to openssh-unix-dev mailing list, but the openssh developers couldn't reproduce the problem on their place, and therefore couldn't yet investigate it properly.</li>
</ol>
<p><strong>Guesses</strong></p>
<ol>
<li>It occurs on networks with Cisco equipment, possibly some "smart" Deep Packet Inspection filter ruins specific packets.</li>
<li>It has to do with the packet size of one of the "handshaking" packets. Setting a short cipher list/HostKeyAlgorithms list simply shortens the packet size below some threshold.</li>
<li>The buggy behavior HAS something to do with some change in OpenSSH, probably starting in 5.7p1. It's probably a fair change which just triggers the problem innocently.</li>
<li>I didn't rule out the possibility that another 3rd party lib is involved (e.g. openssl).</li>
</ol>
<p><strong>Resources</strong></p>
<ol>
<li><a href="https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/708493">Ubuntu bug</a></li>
<li><a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612607">Debian Bug</a></li>
<li>Serverfault <a href="http://serverfault.com/questions/265244/ssh-client-problem-connection-reset-by-peer">[1]</a></li>
<li>Threads on openssh-unix-dev: <a href="http://lists.mindrot.org/pipermail/openssh-unix-dev/2011-February/029361.html">[1]</a> <a href="http://lists.mindrot.org/pipermail/openssh-unix-dev/2011-March/029432.html">[2]</a></li>
<li><a href="https://www.nowhere.dk/articles/natty-narwhal-problems-connecting-to-servers-behind-cisco-firewalls-using-ssh">A report that correlates the problem to Cisco</a>, a surprising progress!</li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>http://www.held.org.il/blog/2011/05/the-myterious-case-of-broken-ssh-client-connection-reset-by-peer/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
			</item>
	</channel>
</rss>
