<?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>Things n&#039; Stuff Articles</title>
	<atom:link href="http://geek.co.il/wp/category/articles/feed" rel="self" type="application/rss+xml" />
	<link>http://geek.co.il/wp</link>
	<description>Thoughts about the universe in general</description>
	<lastBuildDate>Tue, 22 May 2012 23:23:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19978</generator>
		<item>
		<title>Nvidia Optimus on Ubuntu 12.04</title>
		<link>http://geek.co.il/wp/2012/02/19/nvidia-optimus-on-ubuntu-12-04</link>
		<comments>http://geek.co.il/wp/2012/02/19/nvidia-optimus-on-ubuntu-12-04#comments</comments>
		<pubDate>Sun, 19 Feb 2012 00:04:27 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[Graphics processing unit]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2012/02/19/nvidia-optimus-on-ubuntu-12-04</guid>
		<description><![CDATA[Nvidia Optimus is a neat solution to the problem of power consumption vs. 3D performance in notebook computers &#8211; the computer comes with two graphics chips, an &#8220;integrated graphics package&#8221; &#8211; the Intel GMA embedded graphics and a &#8220;discrete graphics package&#8221; &#8211; the Nvidia chip. The setup works by running your normal windowing UI on [...]]]></description>
			<content:encoded><![CDATA[<p>Nvidia Optimus is a neat solution to the problem of power consumption vs. 3D performance in notebook computers &#8211; the computer comes with two graphics chips, an &#8220;integrated graphics package&#8221; &#8211; the Intel GMA embedded graphics and a &#8220;discrete graphics package&#8221; &#8211; the Nvidia chip. The setup works by running your normal windowing UI on the integrated graphics, only powering on the discrete graphics when you want to play a 3D game or something like that.</p>
<p>Recently I had the fortune to work on a Lenovo T420 laptop that has this setup, and it works very well on MS-Windows with the Nvidia Optimus driver &#8211; you get battry life around 10 hours with the 9 cell battery.</p>
<p>Unfortunately I spend most of my day in Linux and because Nvidia does not support Optimus on Linux, you have the poor choice of either running everything on the Nvidia chip &#8211; decreasing battery life to around 4 hours if you&#8217;re careful, or disabling the Nvidia chip completely.</p>
<p>The solution comes from the <a href="http://bumblebee-project.org/">Bumblebee project</a> &#8211; a software suite to handle the switching between the Nvidia discrete graphics and the embedded Intel chip.</p>
<p>The setup is pretty simple to understand (though I suspect under the hood there are many problems to be solved): A service runs and waits for users to ask for 3D accelerated graphics. When a user starts a program using the special command <code>optirun</code>, the service loads the Nvidia driver, starts an X server using the discrete graphics (with the display disconnected from the actual screen) and runs the specified program on that &#8220;background&#8221; X server. Then it copies the visuals from the program that is rendered using the discrete graphics to a window on the main X server. When the program terminates, the service closes the secondary X server, removes the driver and powers down the graphics card &#8211; putting us back into the ~10 hours battery life.</p>
<p>The Bumblebee software had some problems in the past, but the current version &#8211; 3.0 &#8211; looks very good. There are a few seconds of delay when you launch the application (setting up the driver and X takes some time), but performance is about what you&#8217;d expect when running directly on the hardware. All this without any configuration &#8211; that is if you are running on the stable Ubuntu version.</p>
<p>As I can&#8217;t leave well enough alone, and whenever someone says &#8220;alpha&#8221;, I say &#8211; &#8220;I wants&#8221;, I&#8217;m running the current Ubuntu 12.04 alpha (which is not so bad &#8211; due to be released in a couple of months, it works very well). And of course Bumblebee doesn&#8217;t work properly here.</p>
<p>So this is what I had to do to get it running:</p>
<p><span id="more-1935"></span><br />
These instructions assume you are doing everything in a command line. If you are not comfortable with the command line, this guide is not for you &#8211; go away.</p>
<ol>
<li>We will start by installing Bumblbee itself and its dependencies. We will need to add their PPA to the <a class="zem_slink" title="The Ubuntu Experience (Nelson Mandela Interview)" href="http://www.youtube.com/watch?v=ODQ4WiDsEBQ" rel="youtube">Ubuntu software</a> sources list: <code><br />
sudo add-apt-repository ppa:bumblebee/stable<br />
</code> Unfortunately the project has a repository for Ubuntu 12.04, but at this point in time it does not include all the needed packages. I had to edit the source list file and add the 11.10 repositories as well before installation could complete &#8211; open the file <code>/etc/apt/sources.list.d/bumblebee-stable-precise.list</code> for editing as root, for example: <code><br />
sudo gedit /etc/apt/sources.list.d/bumblebee-stable-precise.list<br />
</code> and duplicate the two lines found there, changing the word <code>precise</code> to <code>oneiric</code> in the duplicates. Save and exit the editor, then run these:<code><br />
sudo apt-get update<br />
sudo apt-get install bbswitch-dkms bumblebee bumblebee-nvidia virtualgl-libs:i386 libgl1-mesa-glx:i386 libc6:i386<br />
sudo usermod -a -G bumblebee $USER<br />
</code><br />
The last line adds the current user (the one you are logged in as) to the &#8220;bumblbee&#8221; user group &#8211; only users who are part of this group may use the Bumblebee service. If you have more users that you want to be able to play 3D games, then you need to add them as well.</li>
<li><a href="http://bumblebee-project.org/install.html#Ubuntu">The Bumblebee Project recommends</a> Ubuntu users to install the &#8220;X-Swat&#8221; x-updates PPA, but this isn&#8217;t available for 12.04 users, and we are already running the latest X anyway, right? After bumblebee didn&#8217;t work for me, I went to the next best thing &#8211; the xorg-edgers repository. A word of warning &#8211; this is a set of highly experimental software &#8211; if it works for you, count yourself lucky and if it doesn&#8217;t &#8211; don&#8217;t complain. To install it, type:<code><br />
sudo apt-add-repository ppa:xorg-edgers/ppa<br />
sudo apt-get update<br />
sudo apt-get dist-upgrade -y<br />
</code> At this point most likely your kernel and other important software packages have been upgraded, so its a good idea to reboot.</li>
<li>After you come back from the reboot, the standard Nvidia driver will not work, because of an incompatible ABI version. Not to worry, its time to recompile a new Nvidia driver. Start by removing your old one with:<code><br />
sudo apt-get purge nvidia-current<br />
</code>Now to get the most up to date Nvidia driver package to rebuild a driver that works with your latest Xorg and kernel, create a new directory to hold the Nvidia package sources and change into it, and type: <code><br />
sudo apt-get install build-essential checkinstall -y<br />
sudo apt-get build-dep nvidia-current-updates -y<br />
apt-get source nvidia-current-updates<br />
</code> Now with the source downloaded and all dependencies installed, we can build a new driver and install it:<code><br />
cd nvidia-graphics-drivers*<br />
dpkg-buildpackage -us -uc -nc<br />
cd ..<br />
sudo dpkg -i nvidia-current-updates_*.deb<br />
</code>If all went well, you have your new Nvidia driver instaled. Lets see if it loads Ok:<code><br />
sudo modprobe nvidia_current_updates<br />
</code>If you get no error, then we can go to the next step.</li>
<li>The Bumblebee configuration must be modified to work with all this cutting edge stuff, so lets start by turning off the Bumblbee service:<code><br />
sudo stop bumblebeed<br />
</code><br />
Now you need to edit the Bumblebee configuration file. Use your favorite text editor to open <code>/etc/bumblebee/bumblebee.conf</code> as root, for example:<code><br />
sudo gedit /etc/bumblebee/bumblebee.conf<br />
</code>. This is a standard <a class="zem_slink" title="INI file" href="http://en.wikipedia.org/wiki/INI_file" rel="wikipedia">INI file</a>with a lot of comments to help you figure out what is going on in here, and we will need to do some changes to (a) disable auto-detection and force Nvidia mode and (b) help Bumblebee locate the drivers for the Nvidia graphics. Make these changes:</p>
<ul>
<li>In the <code>[bumblebeed]</code> section, set <code>Driver=nvidia</code></li>
<li>In the <code>[driver-nvidia]</code> section, set <code>KernelDriver=nvidia_current_updates</code> and in both <code>LibraryPath</code> and <code>XorgModulePath</code> change <code>nvidia-current</code> to <code>nvidia-current-updates</code>.</li>
</ul>
<p>Save the file after all the changes have been complete, and start the service again:<code><br />
sudo start bumblbeed<br />
</code></li>
<li>At this point, Bumblebee should be ready to do some damage. The recommended way to test it is to run <code><br />
optirun glxspheres<br />
</code>Give it a few seconds to launch the window (the screen may black out for a bit, don&#8217;t worry about it). When the window appears, it should show a graphical demo and a frame per seconds counter at the bottom left corner. On my system it shows a respectable 86 frames per seconds (vs 2 frames per seconds on the embedded Intel chip). If the glxspehere window doesn&#8217;t come up, and you get errors from the optirun command, look in the system log file <code>/var/log/syslog</code> for lines from <code>bumblebeed</code>. Also if you haven&#8217;t rebooted your computer since you built the Nvidia drivers, it might be a good idea to try that as well.</li>
</ol>
<p>Running games with optirun is pretty straight forward &#8211; either invoke them manually or edit their .desktop files to add the optirun command. I&#8217;ve also used this in MS-Windows games running under wine (I recommend using <a href="http://www.playonlinux.com/">PlayOnLinux</a> &#8211; its a beautiful piece of work), and they work perfectly well.</p>
<p>Best of luck, and let me know if it works or if it doesn&#8217;t.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://geek.co.il/wp/2011/11/15/installing-nvidia-drivers-on-fedora-16-the-wrong-way">Installing Nvidia drivers on Fedora 16 &#8211; the wrong way</a> (geek.co.il)</li>
<li class="zemanta-article-ul-li"><a href="http://techie-buzz.com/foss/ubuntu-12-04-lts-precise-pangolin-alpha.html">Ubuntu 12.04 LTS, Codename Precise Pangolin Releases Its First Alpha</a> (techie-buzz.com)</li>
<li class="zemanta-article-ul-li"><a href="http://neelmohile.wordpress.com/2011/11/02/how-to-manually-install-latest-nvidia-drivers-on-ubuntu-oneiric-11-10/">How to manually install latest nvidia drivers on Ubuntu Oneiric 11.10</a> (neelmohile.wordpress.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=d4402761-b953-4034-aaa8-420ae8bd248d" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2012/02/19/nvidia-optimus-on-ubuntu-12-04/feed</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>LDAP authentication on Fedora 16 (and why it sucks)</title>
		<link>http://geek.co.il/wp/2012/02/16/ldap-authentication-on-fedora-16-and-why-it-sucks</link>
		<comments>http://geek.co.il/wp/2012/02/16/ldap-authentication-on-fedora-16-and-why-it-sucks#comments</comments>
		<pubDate>Thu, 16 Feb 2012 11:52:20 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[PAM]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2012/02/16/ldap-authentication-on-fedora-16-and-why-it-sucks</guid>
		<description><![CDATA[In my company we (still) use an Active Directory domain controller to manage central authentication, which is not set up very well &#8211; no SSL and the Kreberos setup is not done properly. This makes gives much trouble to modern Linuxes (e.g. not Ubuntu. yes &#8211; I&#8217;m looking at you Shuttleworth.)  such as Fedora, as [...]]]></description>
			<content:encoded><![CDATA[<p>In my company we (still) use an Active Directory domain controller to manage central authentication, which is not set up very well &#8211; no SSL and the Kreberos setup is not done properly. This makes gives much trouble to modern Linuxes (e.g. <a title="Ubuntu network authentication, pending since 2005" href="https://blueprints.launchpad.net/ubuntu/+spec/network-authentication">not Ubuntu. yes &#8211; I&#8217;m looking at you Shuttleworth</a>.)  such as Fedora, as Fedora have done away with NSS/PAM based LDAP authentication and instead relies on SSS &#8211; which I have yet managed to get working or even find a tutorial on how to set it up properly.</p>
<p>So if you still want to authentication your Fedora installation against the company&#8217;s Active Directory &#8211; and can&#8217;t/won&#8217;t rely on Winbind&#8217;s notably flaky behaviour, you can always install NSS/PAM ldap authentication manually. Unfortunately its not as easy as it sounds, and as I learned the hard way &#8211; one must pay careful attention to SELinux. So here&#8217;s the recipe:</p>
<p><span id="more-1936"></span></p>
<ol>
<li>Install pam_ldap and nss_ldap: <code>yum install -y nss_ldap</code> (this will also install the PAM support).</li>
<li>Configure LDAP access. In Fedora the NSS and PAM configuration were broken into 2 different files. Fortunately the syntax and required configuration is identical so you can just create both files as a copy of each other or even use a link. My configuration looks like this:
<p><code><br />
# the Active Directory domain - this the LDAPized FQDN of your Active Directory tree<br />
base dc=some,dc=domain,dc=com<br />
# the CN of an unpriviliged user that is allowed to log in and search in the domain.<br />
# we created this dummy user that is not part of the normal domain user and it is needed<br />
# for many integration scenarios<br />
binddn CN=authuser,CN=Users,dc=some,dc=domain,dc=com<br />
bindpw 123456<br />
scope sub<br />
timelimit 120<br />
bind_timelimit 120<br />
bind_polict soft<br />
idle_timelimit 3600<br />
# this is the default set up for SBS directory installation<br />
nss_base_passwd		ou=SBSUsers,ou=Users,ou=MyBusiness,dc=some,dc=domain,dc=com<br />
nss_base_shadow		ou=SBSUsers,ou=Users,ou=MyBusiness,dc=some,dc=domain,dc=com<br />
nss_base_group		ou=Security Groups,ou=MyBusiness,dc=some,dc=domain,dc=com?sub<br />
nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus,radvd,tomcat,radiusd,news,mailman,nscd,gdm<br />
# this configuration is based on SFU 3.5 schema that must be installed on the ActiveDirectory server<br />
nss_map_objectclass posixAccount user<br />
nss_map_objectclass shadowAccount user<br />
nss_map_attribute uid sAMAccountName<br />
nss_map_attribute homeDirectory unixHomeDirectory<br />
nss_map_attribute shadowLastChange pwdLastSet<br />
nss_map_objectclass posixGroup group<br />
nss_map_attribute uniqueMember member<br />
pam_login_attribute sAMAccountName<br />
pam_filter objectclass=User<br />
pam_password md5<br />
# configuration for the LDAP server connection<br />
ssl no<br />
uri ldap://LDAP.SERVER.NAME/<br />
tls_cacertdir /etc/openldap/cacerts<br />
</code></p>
<p>The <code>pam_ldap</code> and <code>nss_ldap</code> come with a default configuration file &#8211; just overwrite both of these with the content above (after adapting it to your needs &#8211; change the LDAP server name, the LDAP base DN, login user and search paths).</p>
<p>This is as good a time as any to make sure that your computer can indeed access the LDAP server. I recommend installing <code>openldap-clients</code> and running a test query using <code>ldapsearch</code>. For example, the following query will list all the users eligible for log in using the configuration above:</p>
<p><code><br />
ldapsearch -h LDAP.SERVER.NAME -D "CN=authuser,CN=Users,dc=some,dc=domain,dc=com" -w 123456 -b "ou=SBSUsers,ou=Users,ou=MyBusiness,dc=some,dc=domain,dc=com" dn<br />
</code>
</li>
<li>Now you need to configure the authentication stack to use your new LDAP configuration. Unfortunately, the Fedora configuration tool will not allow you to select LDAP without SSL or TLS and without Krebros, so we&#8217;d need to edit the configuration files by hand. But lets start with a clean setup &#8211; run <code>authconfig-tui --enablemkhomedir</code> and make sure only &#8220;Cache Information&#8221;, &#8220;Use Shadow Passwords&#8221; and &#8220;Local authorization is sufficient&#8221; are selected, and click &#8220;Next&#8221;.
<p>Now lets go edit the configuration files directory. There are two configuration files that need to be edited &#8211; <code>/etc/pam.d/system-auth</code> and <code>/etc/pam.d/password-auth</code>. The changes needed to both are identical so just go ahead and edit one of them with your favorite text editor and then copy it over the other one:</p>
<ul>
<li>In the <code>auth</code> section, before the line for <code>pam_deny</code> add:
<p><code><br />
auth        sufficient    pam_ldap.so use_first_pass<br />
</code>
</li>
<li>In the <code>account</code> section, before the line for <code>pam_permit</code> add:
<p><code><br />
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so<br />
</code>
</li>
<li>In the <code>password</code> section, before the line for <code>pam_deny</code> add:
<p><code><br />
password    sufficient    pam_ldap.so use_authtok<br />
</code>
</li>
<li>In the <code>session</code> section, after the last line, add:
<p><code><br />
session     optional      pam_ldap.so<br />
</code>
</li>
</ul>
<p>Alternatively, you can download <a href="http://geek.co.il/wp/wp-content/uploads/2012/02/fix-auth.txt">this patch file</a>, and execute it using <code>cd /etc/pam.d; patch < fix-auth.txt</code>.</p>
<p>Additionally you need to configure NSS separately by adding the </code><code>ldap</code> module to the configuration in <code>/etc/nsswitch.conf</code>: edit the file and add it in the lines for <code>passwd</code>, <code>shadow</code> and <code>groups</code>, like so:</p>
<p><code><br />
passwd:     files ldap<br />
shadow:     files ldap<br />
group:      files ldap<br />
</code>
</li>
<li>We also need to get SELinux to allow NSS and PAM to contact the LDAP server as part of the login process (before the user gets their own security context where such things are allowed). To do that, run this command: <code>setsebool authlogin_nsswitch_use_ldap 1</code></li>
</ol>
<p>Your system should now be ready to log in using LDAP. Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2012/02/16/ldap-authentication-on-fedora-16-and-why-it-sucks/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scanning Hand Written Texts Into High Quality Digital Files</title>
		<link>http://geek.co.il/wp/2012/01/04/scanning-hand-written-texts-into-high-quality-digital-files</link>
		<comments>http://geek.co.il/wp/2012/01/04/scanning-hand-written-texts-into-high-quality-digital-files#comments</comments>
		<pubDate>Tue, 03 Jan 2012 23:37:21 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2012/01/04/scanning-hand-written-texts-into-high-quality-digital-files</guid>
		<description><![CDATA[The purpose of this exercise is to convert a hand written note &#8211; such as your signature &#8211; to high quality digital files that can be used to embed &#8220;hand write&#8221; into documents &#8211; such as when someone asks you to fax them a &#8220;signed&#8221; copy of the PDF they emailed you. You&#8217;d be surprised [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose of this exercise is to convert a hand written note &#8211; such as your signature &#8211; to high quality digital files that can be used to embed &#8220;hand write&#8221; into documents &#8211; such as when someone asks you to fax them a &#8220;signed&#8221; copy of the PDF they emailed you. You&#8217;d be surprised how often that happens around here.</p>
<p>Required Ingridients:</p>
<ul>
<li>A computer with The GIMP installed</li>
<li>Your handy smart phone with a 5MP or better camera</li>
<li>A good pen and paper.</li>
</ul>
<p>So anyway, here&#8217;s the process from top to bottom, with pictures:</p>
<ol>
<li>Sit down at a proper table, and using a good black heavy-line pen on a white clean high-density paper, write what you need to write &#8211; slowly and deliberately but without pauses. Try not to smear the ink so you get clean continuous lines, otherwise the quality suffers a lot.<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/write-out.jpg"><img class="alignnone  wp-image-1896" title="write-out" src="http://geek.co.il/wp/wp-content/uploads/2012/01/write-out.jpg" alt="" width="576" height="432" /><span id="more-1895"></span></a></li>
<li>Now take your phone and start the camera app. Make sure that flash is on (not auto &#8211; always on), and if your camera supports it, set the &#8220;auto focus&#8221; mode to &#8220;Macro&#8221;. Position the camera close to the paper so that it sees your whole text and hold the shutter button (don&#8217;t release it yet) to let the camera focus. If you don&#8217;t get a clean focus then don&#8217;t take the shot, move the camera a bit away and try again until you get a clean focus.</li>
<li>After the picture is taken, load it into the computer. This part is usually the most complicated part of the whole process. On my phone I have &#8220;Google Docs&#8221; app installed, so I &#8220;Share&#8221; to &#8220;Docs&#8221; and I then use the browser to go to Google Docs and download the image file.<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/2012-01-03-22.21.01.jpg"><img class="alignnone  wp-image-1898" title="Hello World" src="http://geek.co.il/wp/wp-content/uploads/2012/01/2012-01-03-22.21.01.jpg" alt="" width="640" height="480" /></a></li>
<li>Now its time to start GIMP, load the picture and do the magic:<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_001.png"><img class="alignnone  wp-image-1899" title="Selection_001" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_001-300x207.png" alt="" width="441" height="303" /></a></li>
<li>The first tool to use is the &#8220;Crop&#8221; tool from the toolbox &#8211; we need the image contain only the actual hand written note we want to convert, and specifically we need to get rid of the edges of the picture where the flash didn&#8217;t highlight the paper well (because the camera was so close to the paper<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_0011.png"><img class="alignnone  wp-image-1902" title="Crop tool" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_0011.png" alt="" width="754" height="574" /></a><br />
The &#8220;Auto Shrink&#8221; feature is normally very useful for these kinds of jobs, but because of the inherently &#8220;noisy&#8217; background of the paper, it wouldn&#8217;t work at all &#8211; just do your best manually and leave a bit of margin around the text. When you&#8217;re done setting up the box around the text, then click the center of the selection to make the crop.</li>
<li>Next we need to clear the image of most of the background noise of the paper before the real work can begin &#8211; to do this we will use the popular &#8220;Unsharp Mask&#8221; filter<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_019.png"><img class="alignnone size-full wp-image-1912" title="Select &quot;Filters&quot; &quot;Enhance&quot; &quot;Unsharp Mask&quot;" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_019.png" alt="" width="790" height="466" /></a><br />
When the &#8220;Unsharp Mask&#8221; dialog comes up, push both the &#8220;Radius&#8221; and &#8220;Amount&#8221; sliders all the way to the end, while leaving the &#8220;Threshold&#8221; value at its default small value (I usually set it to 5, but any small number will work fine)<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_019.png"><img class="alignnone size-full wp-image-1913" title="Unsharp Mask at work" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_019.png" alt="" width="665" height="491" /></a><br />
After you apply the filter, the image would look drastically different, as you can see in the example below, but we&#8217;re not done yet<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_020.png"><img class="alignnone size-full wp-image-1914" title="Image much cleared up, but there are still a lot of artifacts" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Selection_020.png" alt="" width="666" height="440" /></a><br />
If you look closely you&#8217;ll see that there are still some color artifacts present. In this example the photograph source is of rather high quality, but with less high quality input you may still see here some blobs and spots which should get taken care of by the next step.</li>
<li>To completely separate the hand written text from the background, we will use the &#8220;Threshold&#8221; command from the &#8220;Colors&#8221; menu &#8211; this will highlight in black only the ink from the photograph and will clear everything else to white. When the &#8220;Threshold&#8221; dialog opens, click the &#8220;Auto&#8221; button to automatically select the correct threshold value.<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_0191.png"><img class="alignnone size-full wp-image-1915" title="Threshold dialog" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_0191.png" alt="" width="781" height="406" /></a><br />
At this point we are basically done with the major part of the work. We need only prepare the image for embedding and possibly due a bit more clean up if the original wasn&#8217;t of a good enough quality and we still got some black blotches where there shouldn&#8217;t be any.</li>
<li>The next step is to remove the white background from the image so it can be later embed the image into another document without having a white box around the text, that hides whatever we were supposedly &#8220;writing over&#8221;. From the &#8220;Colors&#8221; menu select the &#8220;Color to Alpha&#8221; command and apply its default setting (which should be to have the color White converted to transparency)<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_004.png"><img class="alignnone size-full wp-image-1905" title="Desktop 5_004" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_004.png" alt="" width="591" height="362" /></a></li>
<li>If we still got some inky looking blotches, left from the previous stage that we want to remove, you can clean them up manually by adding a layer mask<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_015.png"><img class="alignnone size-full wp-image-1916" title="Add a layer mask" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_015.png" alt="" width="654" height="535" /></a><br />
And set it up to start completely white (opaque &#8211; which is the default)<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_016.png"><img class="alignnone size-full wp-image-1917" title="Layer mask dialog" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_016.png" alt="" width="347" height="473" /></a><br />
Once that is done &#8211; and you can see the layer mask as a white box to the right of the layer preview in the layers tab, take a paintbrush from the toolbox, and touch it to where you have noise that you want removed, careful not to touch actual lines<br />
<a href="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_017.png"><img class="alignnone size-full wp-image-1918" title="Paintbrush tool" src="http://geek.co.il/wp/wp-content/uploads/2012/01/Desktop-5_017.png" alt="" width="525" height="401" /></a><br />
Finally apply the layer mask by right clicking the layer in the layers tab and selecting &#8220;Apply Mask&#8221;</li>
<li>The last step is to save the result as a PNG file &#8211; so that we keep the transparency of the background.</li>
</ol>
<p>The new image is now ready for import into your PDF editing software of choise, or into any other document where you need to fake ink on paper. You can also, obviously, keep the digital file and use it many times without bothering your hardware (pen, paper and camera) again.</p>
<p>Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2012/01/04/scanning-hand-written-texts-into-high-quality-digital-files/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up Subversion svnserve daemon on CentOS</title>
		<link>http://geek.co.il/wp/2011/11/28/setting-up-subversion-svnserve-daemon-on-centos</link>
		<comments>http://geek.co.il/wp/2011/11/28/setting-up-subversion-svnserve-daemon-on-centos#comments</comments>
		<pubDate>Mon, 28 Nov 2011 15:04:04 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Apache HTTP Server]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[Secure Shell]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[svnserve]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/11/28/setting-up-subversion-svnserve-daemon-on-centos</guid>
		<description><![CDATA[When you want to host a Subversion repository on your CentOS (or RHEL) server, its quite annoying that the only options available to serve your repository are SSH (using the svn+ssh:// schema in the Subversion URLs &#8211; it is basically set up out of the box, not tweaking necessary) and Apache&#8217;s mod_dav_svn (using the http:// [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to host a <a class="zem_slink" title="Apache Subversion" href="http://subversion.apache.org/" rel="homepage">Subversion</a> repository on your <a class="zem_slink" title="CentOS" href="http://www.centos.org/" rel="homepage">CentOS</a> (or <a class="zem_slink" title="Red Hat Enterprise Linux" href="http://www.redhat.com/rhel/" rel="homepage">RHEL</a>) server, its quite annoying that the only options available to serve your repository are <a class="zem_slink" title="Secure Shell" href="http://en.wikipedia.org/wiki/Secure_Shell" rel="wikipedia">SSH</a> (using the <code>svn+ssh://</code> schema in the Subversion URLs &#8211; it is basically set up out of the box, not tweaking necessary) and Apache&#8217;s mod_dav_svn (using the <code>http://</code> or <code>https://</code> schema in the Subversion URLs &#8211; this is somewhat complex to setup but good instructions are easy to find on the web).</p>
<p>The main advantage of either of these methods is security: both have easy transport security (SSH by default, Apache if you set it to server over SSL) and are easy to setup authentication for (SSH authenticate against the system&#8217;s accounts using <a class="zem_slink" title="Pluggable Authentication Modules" href="http://en.wikipedia.org/wiki/Pluggable_Authentication_Modules" rel="wikipedia">PAM</a> and Apache authenticate against basically anything with a simple setup).</p>
<p>The main disadvantage of these methods are that they are slow (SSH is apparently somewhat faster then HTTP) and when supporting multiple large projects of many developers I started running into all kinds of weird connection errors when you try to manipulate many files on many projects at the same time.</p>
<p>Subversion itself offers another alternative using their own network service called svnserve &#8211; this is a standard unix daemon that listens on a specific port and uses a native protocol to communicate with Subversion clients (using the <code>svn://</code> schema in Subversion URLs). It offers very good performance, but no transport security (encryption) by default. Another major problem with using svnserve as a network service is that while CentOS ships the binary itself (it is required as part of the way that the svn+ssh:// protocol is implemented) it doesn&#8217;t ship any support files to run it as a standalone service nor to help with its configuration. Also by default svnserve can only authenticate users using its own Apache-style password database file &#8211; which makes it unsuitable to integrate in large organizations.</p>
<p><span id="more-1878"></span></p>
<p>In this article I&#8217;ll document how I setup snvserve as a network service to support a large development environment. The requirements do not include transport security because the server is on a private network and can only be accessed by trusted computers (either local or through a VPN), but we do need to have Subversion users authenticate against a central authentication server that is used by all local services. In my setup the authentication services is Mirosoft ActiveDirectory, but the local server is setup to authenticate to the ActiveDirectory using PAM, so we will setup svnserve to use PAM and gloss over the ActiveDirectory specifics.</p>
<p>The process is as follows:</p>
<ol>
<li>Set up your server: Install CentOS 6 and configure PAM to authenticate to your central authentication. Verify that users can SSH into the server using their login credentials.</li>
<li>Set up your Subversion repository: Install subversion and use svnadmin to create your repository. In the below examples I&#8217;ve created the repository under /var/svn</li>
<li>Set up svnserve to require authentication and do the authentication using the Cyrus SASL libraries: copy the file <code>svnserve.conf</code> from your repository&#8217;s configuration directory (for example <code>/var/svn/svnserve.conf</code>) to <code>/etc/svnserve.conf</code>. Edit it and add in the <code>[general]</code> section the following lines: <code><br />
anon-access = none<br />
auth-access = write<br />
realm = The Name of Your Repository<br />
</code> make sure that all other settings in that section are commented out. Now add, at the bottom of the file, a new section like this: <code><br />
[sasl]<br />
use-sasl = true<br />
</code></li>
<li>Setup the Cyrus SASL library to work with the <code>saslauthd</code> authentication service: create the file <code>/etc/sasl2/svn.conf</code> with the following content: <code><br />
pwcheck_method: saslauthd<br />
mech_list: plain login<br />
</code></li>
<li>Start the <code>saslauthd</code> service and make sure it always run when the system start, by executing the following commands:<code><br />
# service saslauthd start<br />
# chkconfig saslauthd on<br />
</code></li>
<li>Set up <code>saslauthd</code> to allow svnserve to authenticate using the main system&#8217;s PAM configuration, by executing the following command:<code><br />
# cd /etc/pam.d<br />
# ln -s system-auth svn<br />
</code></li>
<li>Create the <a class="zem_slink" title="UNIX System V" href="http://en.wikipedia.org/wiki/UNIX_System_V" rel="wikipedia">SysV</a> initialization script for svnserve &#8211; this will allow you to start and stop svnserve using the <code>service</code> command and have it run when the system start. This is the major part that I expected CentOS to ship but is missing. Creating a good SysV script is not trivial &#8211; you can do it yourself but I suggest using the script presented here. I&#8217;ve used the script from <a href="http://mohanjith.net/blog/2007/07/svnserve-init-script.html">this blog post</a> which is not bad but its implementation of <code>status</code> didn&#8217;t report the status of a dead process, so I modified it and you can download my modified version <a title="svnserve SysV init script" href="http://geek.co.il/wp/wp-content/uploads/2011/11/svnserve.gz">here</a>. The file is compressed because of WordPress, just download it, run it through gunzip and copy the resulting file to <code>/etc/init.d/svnserve</code> and then give it &#8220;execute permissions&#8221; using: <code><br />
# chmod 755 /etc/init.d/svnserve<br />
</code></li>
<li>Create a configuration file for the service by creating and editing the file <code>/etc/sysconfig/subversion.conf</code> with this content: <code><br />
OPTIONS="--config-file=/etc/svnserve.conf -r /var/svn"<br />
</code><br />
We use the <code>-r</code> option to limit svnserve access to only our repository, so have the value there point to your actual repository if its not <code>/var/svn</code></li>
<li>Set up svnserve to run when the system start, and then start the service itself: <code><br />
# chkconfig svnserve on<br />
# service svnserve start<br />
</code></li>
</ol>
<p>And that&#8217;s it &#8211; you should have svnserve listening on port 3690 and ready to serve clients. The URL you use to access the repository should include only the server name as svnserve access is already rooted to only your repository by the configuration file. So for example if my server is called <code>svn</code> then the URL will be <code>svn://svn</code>.</p>
<p>This setup will still allow you to access the repository using the <code>svn+ssh://</code> protocol as you would under a normal setup. It can be a bit confusing as access over SSH uses different paths then over the Subversion svnserve network service, because you have to use the full path to the repository on the local file system in the <code>svn+ssh://</code> URL. To circumvent this, its possible to get the SSH access to also be rooted to your repository&#8217;s path and thus be symmetric with the above setup. To do this, create a new file at <code>/usr/local/bin/svnserve</code> and put the following code in it: <code><br />
#!/bin/bash<br />
exec /usr/bin/svnserve "$@" -r /var/svn<br />
</code><br />
Give the file &#8220;execute permissions&#8221; by running <code><br />
# chmod 755 /usr/local/bin/svnserve<br />
</code>, so it can be executed by the Subversion client instead of the system&#8217;s svnserve binary. Now both native Subversion and SSH access use basically the same URL, except for the schema part.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://waterbiscuit.wordpress.com/2011/08/04/centossubversion-configuration/">CentOS &#8211; Subversion Configuration</a> (waterbiscuit.wordpress.com)</li>
<li class="zemanta-article-ul-li"><a href="http://stackoverflow.com/questions/7505832/passwords-and-svn">Passwords and svn</a> (stackoverflow.com)</li>
<li class="zemanta-article-ul-li"><a href="http://stackoverflow.com/questions/7520886/importing-a-subversion-repository">Importing a subversion repository</a> (stackoverflow.com)</li>
<li class="zemanta-article-ul-li"><a href="http://stackoverflow.com/questions/375869/subversion-merging-repositories">Subversion &#8211; Merging Repositories</a> (stackoverflow.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=83f84754-5ff9-460b-a839-a9c61c13faa2" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/11/28/setting-up-subversion-svnserve-daemon-on-centos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>מאמר אקראי על תשישות החלטות</title>
		<link>http://geek.co.il/wp/2011/11/17/%d7%9e%d7%90%d7%9e%d7%a8-%d7%90%d7%a7%d7%a8%d7%90%d7%99-%d7%a2%d7%9c-%d7%aa%d7%a9%d7%99%d7%a9%d7%95%d7%aa-%d7%94%d7%97%d7%9c%d7%98%d7%95%d7%aa</link>
		<comments>http://geek.co.il/wp/2011/11/17/%d7%9e%d7%90%d7%9e%d7%a8-%d7%90%d7%a7%d7%a8%d7%90%d7%99-%d7%a2%d7%9c-%d7%aa%d7%a9%d7%99%d7%a9%d7%95%d7%aa-%d7%94%d7%97%d7%9c%d7%98%d7%95%d7%aa#comments</comments>
		<pubDate>Thu, 17 Nov 2011 14:30:37 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/11/17/%d7%9e%d7%90%d7%9e%d7%a8-%d7%90%d7%a7%d7%a8%d7%90%d7%99-%d7%a2%d7%9c-%d7%aa%d7%a9%d7%99%d7%a9%d7%95%d7%aa-%d7%94%d7%97%d7%9c%d7%98%d7%95%d7%aa</guid>
		<description><![CDATA[באחד הפודקסטים שאני שומע &#8211; Stack Exchange Podcast עם ג&#8217;ואל ספולסקי וג&#8217;ף אטווד &#8211; ספולסקי הזכיר כבר כמה פעמים מחקר שנעשה באוניברסיטת בן גוריון על &#8220;גורמים חיצוניים בהחלטות שיפוטיות&#8221; שבו החוקר מדד את אחוז ההצלחה בבקשות חנינה בהשוואה לכמה זמן עבר מאז ארוחת הבוקר של השופט ששומע את בקשת החנינה. ספיציפית החוקר &#8211; שי דנצינגר [...]]]></description>
			<content:encoded><![CDATA[<p>באחד הפודקסטים שאני שומע &#8211; Stack Exchange Podcast עם ג&#8217;ואל ספולסקי וג&#8217;ף אטווד &#8211; ספולסקי הזכיר כבר כמה פעמים מחקר שנעשה באוניברסיטת בן גוריון על &#8220;<a href="http://www.pnas.org/content/108/17/6889">גורמים חיצוניים בהחלטות שיפוטיות</a>&#8221; שבו החוקר מדד את אחוז ההצלחה בבקשות חנינה בהשוואה לכמה זמן עבר מאז ארוחת הבוקר של השופט ששומע את בקשת החנינה.</p>
<p>ספיציפית החוקר &#8211; שי דנצינגר &#8211; מצא ששופטים הדנים בבקשות חנינה של אסירים ישראלים מחלקים את הישיבות שלהם לשלושה חלקים המופרדים ביניהם בהפסקות אוכל, ובהנתן שאנחנו מפקטרים החוצה כל שיקול אחר (בין אם הוא לגיטימי או לא &#8211; כמו אחוז מזמן המאסר המקורי שהאסיר כבר עשה, חומרת הפשע, השתייכות עדתית וכו&#8217;) אפשר לראות בצורה מובהקת ירידה דרמטית באחוז ההצלחה של בקשות חנינה בין תחילת וסוף כל חלק, כשאחרי ההפסקה אחוזי ההצלחה חוזרים לרמתם הקודמת.</p>
<p><span id="more-1860"></span></p>
<p>יש כמה מאמרים באינטרנט שסוקרים את עבודת המחקר ומציאים מסקנות, לדוגמה <a href="blogs.discovermagazine.com/notrocketscience/2011/04/11/justice-is-served-but-more-so-after-lunch-how-food-breaks-sway-the-decisions-of-judges/">הסקירה של הבלוג &#8220;Not Rocket Science&#8221; של מגזין &#8220;Discover&#8221;</a>‮ שהיא מעניינת &#8211; ואני ממליץ עליה אם לא בא לכם לקרוא את המאמר המקורי, אבל רציתי לדבר על תשישות החלטות (&#8220;Decision Fatigue&#8221;) בהקשרים של טכנולוגית תקשורת &#8211; נושא שקרוב אלי בהרבה מאשר היעילות של המערכת השיפוטית הישראלית.</p>
<p>הזיהוי של ההתנהגות האנושית שבה ככל שאנשים נדרשים לבצע יותר החלטות &#8211; ו\או החלטות קשות יותר &#8211; כך הם נהיים יותר עדישים לבחירות שלהם, אינו משהו חדש או מפתיע לכל מי שצופה בהתנהגות אנושית באיזו שהיא רמה, בין אם מדובר מעצבת ממשקי משתמש חובבנית או פסיכולוג מורשה, כשבמאמר הנדון מה שבעיקר אמור להפתיע זה שההתנהגות הזאת נראית, בעוצמה, גם אצל שופטים מקצועיים שאמון עליהם שהחלטות שלהם חייבות להיות נקיות מכל שיקול חיצוני &#8211; מכיוון שהן נוגעות במישרין לחירות של אדם או לעיתים אפילו לחייו. כל שכן אפשר לזהות את ההתנהגות הזאת בכל מקום בחייו של אדם, בעיקר בעידן המודרני שבו אנחנו נאלצים לבצע החלטות אלפי או מיליוני פעמים ביום.</p>
<p>הכשל לזהות את הבעיה, ולתת פתרון נכון, נפוץ בקרב מי שמודעים לבעיה: אפילו באותו פודקסט (<a href="http://blog.stackoverflow.com/2011/10/se-podcast-24/">פודקסט מספר 24</a>, באזור דקה 63), קצת לאחר שספולסקי מזכיר את הנושא של תשישות החלטות, הם מדברים על ממשק המשתמש של המנהלים שבו רשימת האפשרויות לסימון סיבת סגירת שאלה היא ארוכה מדי &#8211; מעל 20 אפשרויות וצריך שיהיה שם לא יותר מ-16 אפשרויות שונות: שזה נשמע כמו התאמה נכונה לתשישות החלטות, אבל זו עדיין אופטימיזציה גרועה: רעיון יותר טוב הוא לחלק את האפשרויות לעץ החלטות רדוד ולהוביל את המשתמש דרך &#8220;ממשק אשף&#8221; המציג כל החלטה בתורה &#8211; לדוגמה, אם צריך לבחור בין כ-30 אפשרויות, אפשר לתרגם את זה לצעד אחד הבוחר בין כל האפשרויות (עץ החלטות בעומק 1) או סדרה של שאלות כן/לא (עץ החלטות בעומק 5) עם כי האופטימום הוא איפשהו באמצע &#8211; כנראה משהו כמו שלושה צעדים עם 3~4 החלטות בכל צעד, כמו &#8220;מבחן אמריקאי&#8221;.</p>
<p>מעבר לממשקי המשתמש, את תשישות ההחלטות &#8211; או אולי תרגום טוב יותר יהיה &#8220;הלם החלטות&#8221; (כמו &#8220;הלם קרב&#8221; &#8211; &#8220;combat fatigue&#8221;) אפשר לראות גם בחיים האמיתיים, בעיקר אצל עובדים בחברות סטארט-אפ: כמות הפרוייקטים הפתוחים בכל רגע נתון, והצורך לעבור כל הזמן בין עבודה מרוכזת בנושא אחד לעבודה בנושא אחר, לענות על דואר, להתייעץ או ליעץ לעובדים אחרים, וכו&#8217; היא בעצמה יוצרת עומס החלטות כבד &#8211; אפילו בלי להתחשב בעבודה עצמה. </p>
<p>לדעתי השיקול של הפחת הלם החלטות צריך להיות בין השיקולים הראשונים שצריך להתחשב בהם כשבאים לתכנן מערכות לשימוש בני אדם &#8211; בין אם זה ממשקי משתמש לתוכנה או נהלי והרגלי עבודה בחברות טכנולוגיה, וכל אדם הנמצא בחשיפה להלם החלטות צריך להיות מודע לסכנות הכרוכות בכך ולתכנן דרכי מניעה &#8211; רק לצערי שאין לי כרגע שום רעיון בנושא, ואשמח לשמוע כל הצעה ועצה.</p>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/11/17/%d7%9e%d7%90%d7%9e%d7%a8-%d7%90%d7%a7%d7%a8%d7%90%d7%99-%d7%a2%d7%9c-%d7%aa%d7%a9%d7%99%d7%a9%d7%95%d7%aa-%d7%94%d7%97%d7%9c%d7%98%d7%95%d7%aa/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script day: find the oldest file in a directory structure</title>
		<link>http://geek.co.il/wp/2011/11/14/script-day-find-the-oldest-file-in-a-directory-structure</link>
		<comments>http://geek.co.il/wp/2011/11/14/script-day-find-the-oldest-file-in-a-directory-structure#comments</comments>
		<pubDate>Mon, 14 Nov 2011 16:53:57 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[File Management]]></category>
		<category><![CDATA[log retention]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/11/14/script-day-find-the-oldest-file-in-a-directory-structure</guid>
		<description><![CDATA[This piece of script came in handy when I wrote a utility that &#8220;recycles&#8221; space on a logging partition: before log rotation archives the current log file, we move some old log files (depending on some archive freshness policy) to a remote storage that archives older files. The problem is that the &#8220;old archive storage&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>This piece of script came in handy when I wrote a utility that &#8220;recycles&#8221; space on a logging partition: before log rotation archives the current log file, we move some old log files (depending on some archive freshness policy) to a remote storage that archives older files.</p>
<p>The problem is that the &#8220;old archive storage&#8221; also has limited disk space and I got fed up managing the archive by hand. The solution I came up is to scan the hierarchy of  log files in the storage (logs are stored hierarchically according to origin and type) and delete old files until I have enough room to move some newer files in. That way the &#8220;old archive storage&#8221; is always kept full and keeps as much back-log as possible and does this automatically.</p>
<p>The piece of code that determines which files we want to delete works like this:</p>
<ol>
<li>Use <code>find</code> to list all the files in the directory structure</li>
<li>Pipe it to <code>perl</code> and collect all the file names in a list</li>
<li>Use perl&#8217;s sort operator to compare the modification times of each file in the list and show them in the order (i.e. oldest first)</li>
<li>Use <code>head</code> to get just the first file</li>
</ol>
<p>So it looks like this:</p>
<p><code>find /mnt/httpd_back/ -type f | perl -nle 'next unless -f; push @files, $_; END { foreach $file (sort { @a=stat($a); @b=stat($b); $a[9] &lt;=&gt; $b[9] } @files) { print $file; }}' | head -n1<br />
</code></p>
<p>Note: normally we use <code>head</code> to get some initial output and terminate the process early before it does more costly work &#8211; when <code>head</code> has enough data it terminates the pipe sending <code>SIGPIPE</code> to the upstream process and that usually terminates the process that generates the data. In this case &#8211; and in all other cases involving sort &#8211; the upstream process buffers all the data in its own memory before outputting anything, so it can sort everything, and using <code>head</code> here is just a filter to get what I want and does not actually save me from doing all the work. I could have easily done the same thing inside the perl script itself by replacing the block of  <code>print $file;</code> with <code>print $file; last;</code> &#8211; this has the same effect as using head, because <code>head</code> will send <code>SIGPIPE</code> to <code>perl</code> after getting the first print and will terminate it. Deciding which way you want to go is probably more about readability of the code and I prefer my original version because its easier to read to non-perl specialists.</p>
<p>I can then just remove that file, see if I have enough room to move in the newer log file and if no &#8211; repeat the process.</p>
<p>This would work well, I believe, but it may be inefficient if I find a bunch of small files and I want to copy in a large file. So what I did next is to take advantage of the fact that all the log files I have are named using the following simple format:</p>
<p><code>&lt;service&gt;-&lt;type&gt;_log-&lt;year&gt;&lt;month&gt;&lt;day&gt;.gz</code></p>
<p>and that allows me to easily find all the log files that record the same day and eliminate them at the same time. Subsequent moving of additional files will likely succeed because I cleared out all the log files of an entire day. If not, I can always go and clear up another day&#8217;s worth of logs.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=a8ef261f-81bb-4291-9d06-ccb32a631329" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/11/14/script-day-find-the-oldest-file-in-a-directory-structure/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling &#8220;Package file is invalid&#8221; problems on CyanogenMod 7</title>
		<link>http://geek.co.il/wp/2011/11/01/handling-package-file-is-invalid-problems-on-cyanogenmod-7</link>
		<comments>http://geek.co.il/wp/2011/11/01/handling-package-file-is-invalid-problems-on-cyanogenmod-7#comments</comments>
		<pubDate>Tue, 01 Nov 2011 13:59:03 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[CyanogenMod]]></category>
		<category><![CDATA[Motorola]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/11/01/handling-package-file-is-invalid-problems-on-cyanogenmod-7</guid>
		<description><![CDATA[Update: The latest update for CyanogenMod for Milestone &#8211; version 7.1.0.3 solves this problem as well. Lately I&#8217;ve been having problems updating software on my Motorola Milestone (1, as in A853) running CyanogenMod 7.1 (thanks to Nadalbak who maintains an unofficial and unsupported port of CyanogenMod for this old device). When I start the Android [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> The latest update for CyanogenMod for Milestone &#8211; version 7.1.0.3 solves this problem as well.</p>
<p>Lately I&#8217;ve been having problems updating software on my Motorola Milestone (1, as in A853) running CyanogenMod 7.1 (thanks to <a title="Nadalbak Milestone CyanogenMod port" href="http://android.doshaska.net/">Nadalbak</a> who maintains an unofficial and unsupported port of CyanogenMod for this old device). When I start the Android Market and do an update of an existing application, I get the error &#8220;Package file is invalid&#8221; for any application. Sometimes removing an application and reinstalling it will work, but often not.</p>
<p>There could be several problems that cause this, apparently a problem with the file permissions on the file systems is common, and if this is your problem then it can be fixed by opening the terminal emulator, executing &#8220;su&#8221; to gain super-user permissions and then running &#8220;fix_permissions&#8221; (it will take a while to complete).</p>
<p>If this doesn&#8217;t solve the problem for you, then likely the problem is that you ran out of space on your &#8220;data&#8221; partition or &#8220;cache&#8221; partition. This is very common if you have a large &#8220;apps partition&#8221; on your SD card and you are in the habit of installing tons of applications &#8211; I know I am <img src='http://geek.co.il/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .</p>
<p><span id="more-1836"></span></p>
<p>The problem is the &#8220;Dalvik cache&#8221; that gets full and apparently the operating system doesn&#8217;t clear old files from it so it will eventually run out of space.</p>
<p>I&#8217;ve tried cleaning the Dalvik cache, using Titanium backup and the OpenRecovery menu &#8211; but that doesn&#8217;t clean the cache properly for some reason, likely because it expects the cache to be on the &#8220;data&#8221; partition but in CyanogenMod 7 for Milestone the Dalvik cache is on the &#8220;cache&#8221; partition.</p>
<p>To solve the problem, boot into OpenRecovery then select &#8220;Wipe cache&#8221; from the main menu. Please note that you must wipe the entire cache partition and not just the Dalvik cache. Also make sure not to choose the similar option to wipe the data partition as that will remove all your personal data from the phone&#8230;</p>
<p>Good luck.</p>
<h4>Update:</h4>
<p>If your /cache partition is constantly overloaded in your Mileston A853 running CyanogenMode 7.1, you can disable the hosting of the apps dalvik cache under /cache by editing the system&#8217;s build.prop file. To do it follow these instructions.</p>
<ol>
<li>Start a terminal in your phone using the terminal emulator app (or an alternative &#8211; I use ConnectBot).</li>
<li>Execute <code>su</code> and approve the super user mode.</li>
<li>Execute <code>mount /system -o remount,rw</code> to allow editing the build.prop file.</li>
<li>Execute <code>vi /system/build.prop</code> to edit the file.</li>
<li>Find the instruction <code>dalvik.vm.dexopt-cache-only</code> &#8211; you can type <code>/dalvik&lt;ENTER&gt;</code> to find it. Move the cursor to the end of the line and press on &#8220;A&#8221; to start editing. Delete the &#8220;1&#8243; at the end of the that line and write &#8220;0&#8243; instead.</li>
<li>Issue an &#8220;ESC&#8221; button (in ConnectBot you can do it by pressing the camera shutter button) and then type &#8220;:x&#8221; to save the changes and leave the editor.</li>
<li>Execute <code>mount /system -o remount,ro</code> to return the system files to read only mode.</li>
<li>Reboot to OpenRecovery and use it to clear the dalvik cache and the cache partition, and then reboot the phone.</li>
<li>
</li>
</ol>
<p>Your device should now have enough space in the /cache partition.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://beast4romtheeast.wordpress.com/2011/10/13/cyanogenmod-7-1-released/">CyanogenMod 7.1 Released</a> (beast4romtheeast.wordpress.com)</li>
<li class="zemanta-article-ul-li"><a href="http://pocketnow.com/android/netflix-for-android-officially-recognizes-cyanogenmod-roms">Netflix for Android Officially Recognizes CyanogenMod ROMs</a> (pocketnow.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=1e32da23-1c9a-4620-a589-0c6baa9af717" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/11/01/handling-package-file-is-invalid-problems-on-cyanogenmod-7/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mounting SMB shares using URL under GNOME and KDE</title>
		<link>http://geek.co.il/wp/2011/10/25/mounting-smb-shares-using-url-under-gnome-and-kde</link>
		<comments>http://geek.co.il/wp/2011/10/25/mounting-smb-shares-using-url-under-gnome-and-kde#comments</comments>
		<pubDate>Tue, 25 Oct 2011 12:34:25 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[File Sharing]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/10/25/mounting-smb-shares-using-url-under-gnome-and-kde</guid>
		<description><![CDATA[As most Linux users are aware, you can access network shares with your file browser of choice (Dolphin, Nautilus and probably others) by writing URLs into the file browser&#8217;s &#8220;location bar&#8221;. If you ever had to work with MS-Windows file server, you should know that you can also access SMB file shares using URLs &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>As most Linux users are aware, you can access network shares with your file browser of choice (Dolphin, Nautilus and probably others) by writing URLs into the file browser&#8217;s &#8220;location bar&#8221;.</p>
<p>If you ever had to work with MS-Windows file server, you should know that you can also access SMB file shares using URLs &#8211; with the schema &#8220;smb&#8221;, like this: <code>smb://file-server/share-name.</code></p>
<p><span id="more-1816"></span></p>
<p>Using a URL like that will ask the file browser to open an SMB connection to the file server and try to list the content of the share. If your file server is not of the kind that likes anonymous users, a password dialog would come up where you have to enter a user name and a password, and a domain name. Nautilus will show an authentication dialog with a &#8220;domain&#8221; field pre-filled with the domain name &#8220;WORKGROUP&#8221; (which is unlikly to be what you want), while in KDE there is no distinct field for the domain as it expects MS-Windows like &#8220;DOMAIN\user&#8221; format, which users are likely not accustomed to. If you now type in your password and ask it to be saved, at best the file browser will open the share but not save the password and you will have to type it again the next time, while at worst &#8211; the browser will not be able to list the share and prompt you for the password again and again.</p>
<p>A useful way to workaround the issue is to have the &#8220;domain&#8221; part already in the &#8220;smb://&#8221; URL &#8211; that way the authentication process and the password keyring manager already knows the correct MS-Windows domain name to log in with and will either pre-fill it in the correct field.</p>
<h3>GNOME and Nautilus</h3>
<p>In GNOME (and using the GVFS command line tools &#8211; more about it later), the format of the URL is <code>smb://domain;user@server/share</code>, so for example if your domain name is &#8220;OFFICE&#8221; and your user is &#8220;oded&#8221;, and you want to access the share &#8220;Documents&#8221; on the server &#8220;files&#8221;, then the URL will be <code>smb://OFFICE;oded@files/Documents</code>:</p>
<p><a href="http://geek.co.il/wp/wp-content/uploads/2011/10/nautilus-smb-login.png"><img class="alignnone size-full wp-image-1817" title="SMB login in Nautilus" src="http://geek.co.il/wp/wp-content/uploads/2011/10/nautilus-smb-login.png" alt="" width="648" height="385" /></a></p>
<p>The password saving feature will now work fine and you can even bookmark the location and if you save the password, then next time you can just click the bookmark to automatically connect to the share.</p>
<h3>KDE and Dolphin</h3>
<p>In KDE the format of the URL is <code>smb://domain\user@server/share</code> (similar to the user specification in MS-Windows), so using the same example above the URL will be <code>smb://OFFICE\oded@files/Documents</code>:</p>
<p><a href="http://geek.co.il/wp/wp-content/uploads/2011/10/dolphin-smb-login.png"><img class="alignnone size-full wp-image-1818" title="Dolphin SMB authentication" src="http://geek.co.il/wp/wp-content/uploads/2011/10/dolphin-smb-login.png" alt="" width="624" height="452" /></a></p>
<p>As you can see, the user name field is pre-filled with the MS-Windows user specification and you are left with only putting in the password. You can also note that Dolphin has &#8220;URL encoded&#8221; the back-slash character &#8211; don&#8217;t worry about it, it will work just fine and you can also bookmark this location and the &#8220;Remember password&#8221; will faithfully keep your password regardless if the URL is &#8220;URL encoded&#8221; or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/10/25/mounting-smb-shares-using-url-under-gnome-and-kde/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Consolas TrueType Font for Linux</title>
		<link>http://geek.co.il/wp/2011/10/22/installing-consolas-truetype-font-for-linux</link>
		<comments>http://geek.co.il/wp/2011/10/22/installing-consolas-truetype-font-for-linux#comments</comments>
		<pubDate>Sat, 22 Oct 2011 12:48:14 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[ClearType]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/10/22/installing-consolas-truetype-font-for-linux</guid>
		<description><![CDATA[This is a short &#8220;how to&#8221; article on how to get and install the new Microsoft Consolas Monotype font &#8211; this is a very nice programmer font and as described in Dan Benjamin&#8217;s &#8220;Top 10 Programming Fonts&#8221; it is highly recommended for use in your programmer&#8217;s editor or IDE (As a side note, his top [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short &#8220;how to&#8221; article on how to get and install the new Microsoft <a class="zem_slink" title="Consolas" href="http://en.wikipedia.org/wiki/Consolas" rel="wikipedia">Consolas</a> Monotype font &#8211; this is a very nice programmer font and as described in <a href="http://hivelogic.com/articles/top-10-programming-fonts/">Dan Benjamin&#8217;s &#8220;Top 10 Programming Fonts&#8221;</a> it is highly recommended for use in your programmer&#8217;s editor or IDE (As a side note, his top selection, <a href="http://www.levien.com/type/myfonts/inconsolata.html">Inconsolata</a> is also very nice and I highly recommend it if you don&#8217;t feel like using Microsoft created software and/or aren&#8217;t interested in performing the steps below which may or may not be legally problematic).</p>
<p>The main problem with using Consolas on your Linux workstation, is that this font is provided by Microsoft, and while if you are running MS-Windows (or even Mac OS-X) it may already be installed &#8211; as it is bundled with many Microsoft products, us in the Linux world have no easy (and legal) way to get to use Consolas in our code editing. Unlike <a href="http://en.wikipedia.org/wiki/Core_fonts_for_the_Web">Microsoft Core Fonts for the Web</a> Consolas is not available for download &#8211; probably for the same reason the core fonts packages were pulled. But as Consolas is bundled with many Microsoft products, some are available for free download for anyone, we can use that to get us some nifty Consolas prettiness in our day to day Linux computing.</p>
<p><span id="more-1789"></span></p>
<p>The following steps will allow you to get Consolas on your system rather easily (assuming you don&#8217;t flinch at using a terminal) and without installing any Microsoft products. I&#8217;m pretty sure its also legal to do so, even when taking into account Microsoft&#8217;s EULA, and a discussion of this is at the end if you are interested. Well, into the fray!</p>
<h3>Requirements</h3>
<p>you need to have the following software packages installed. If you don&#8217;t already have them installed, they are available for all Linux operating system, probably using your built-in software management UI, such as Ubuntu&#8217;s Software Center or Fedora&#8217;s Software Management.</p>
<ul>
<li>Wine &#8211; the Microsoft Windows compatibility layer for Linux</li>
<li>cabextract &#8211; a Microsoft cabinet file format extractor</li>
</ul>
<h3>Procedure</h3>
<p>After you have these installed, lets start going to the Microsoft download center and downloading the latest edition of the free<a href="http://www.microsoft.com/download/en/details.aspx?id=13" target="_blank">PowerPoint Viewer</a>. In the page linked, click on &#8220;Download&#8221; and download the resulting file to somewhere on your computer. The default download location for Fedora is the &#8220;Downloads&#8221; directory and for Ubuntu it is the &#8220;Desktop&#8221; directory.</p>
<p>Next, let&#8217;s open a terminal window (&#8220;<code>gnome-terminal</code>&#8221; if you are running a GNOME desktop, or &#8220;<code>konsole</code>&#8221; if you are running a KDE desktop), and follow these steps:</p>
<ul>
<li><code>mkdir tmp</code> &#8211; Create a temporary directory. The process involves creating a &#8220;wine prefix&#8221; and unpacking some files into it, and I wouldn&#8217;t want to mess up an existing wine setup if you have one.</li>
<li><code>cd tmp</code> &#8211; move to the new temporary directory.</li>
<li><code>WINEPREFIX=$(pwd) wine ~/Downloads/PowerPointViewer.exe /extract:c:\\</code> &#8211; ask the PowerPoint Viewer, nicely, to extract its content to what Windows call &#8220;C:\&#8221; instead of installing it. Wine will setup a simulated &#8220;C: drive&#8221; inside your temporary directory and will then run the installer &#8211; you will have to read and agree to the PowerPoint Viewer EULA, but I don&#8217;t think you have anything to worry about (see the discussion below). For this command I&#8217;m assuming you&#8217;ve downloaded the PowerPoint Viewer executable to the &#8220;Downloads&#8221; directory. If this is not the case, you may change the command appropriately.</li>
<li><code>cabextract drive_c/ppviewer.cab -F 'CONSOLA*'</code> &#8211; The installer has put a &#8220;Microsoft Cabinet file&#8221; into the simulated &#8220;C: drive&#8221;, that contains the files we need, so here we extract the Consolas TTF files from the cabinet.</li>
<li><code>rename 'y/A-Z/a-z/;s/consola/Consolas /;s/b/Bold/;s/i/Italic/;s/z/Bold Italic/;s/ \./ Regular./' *.TTF</code> &#8211; Optional step &#8211; rename the extract files to something that a looks humanly readable. Unless you want to keep the TTF files for future use, you can skip this step.</li>
</ul>
<p>Now you can install the new fonts &#8211; open a file browser and go to your temporary directory. Under GNOME you can install the fonts by opening the font file and the font viewer window should have an &#8220;Install Font&#8221; button at the bottom right corner. Under KDE, right click the font files and select Actions-&gt;Install&#8230; and in the dialog that opens select &#8220;Personal&#8221; to install the font only for you or &#8220;System&#8221; to install the font to all the users (this will require a system administrator password). After you complete this step for all the TTF files that were created, you can copy the files elsewhere if you want to save them as backup for when you want to reinstall your computer. Finally it is recommended to remove the temporary directory and all its content &#8211; you have no further need for this.</p>
<h3>Legal Issues</h3>
<p>I am not a lawyer and the following is not actually a legal argument, but lets try to look at the above procedure through the Microsoft EULA that you have to agree to in order to get the files:</p>
<p>It is my belief that this procedure is perfectly reasonable for personal use on any device you use &#8211; paragraph 1.a of the EULA says &#8220;You may install and use any number of copies of the software on your devices.&#8221; The rest of the paragraph immediately goes and limits the use of the software but I do no believe that its possible for a license to limit the type of use you do with a software you legally obtained (as long as that use itself is not infringing on the copyright on the software). Its like buying a car and have the manufacturer say that this car may not be used to drive on dirt roads &#8211; the manufacturer may refuse to service the car after you drive on dirt roads, but he cannot sue your for violating the &#8220;terms of use&#8221;.</p>
<p>Please note that after extracting the TTF files, you <strong>may not distribute the files</strong>, i.e. copy them to other people &#8211; this is strictly prohibited both under copyright law and under paragraph 1.b of the EULA, because it will not be &#8220;complete and unmodified&#8221; copies of the PowerPoint Viewer. You may, though, distribute copies of the original PowerPoint Viewer download to friends along with these instructions <img src='http://geek.co.il/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>Regarding the legality of extracting files from the installer, the Microsoft EULA has this to say: &#8220;You may not work around any technical limitations in the software&#8221; &#8211; but we didn&#8217;t work around any technical limitations: the Microsoft software itself extracted the files for our use, so there is no technical limitation prevent us from copying files off the installer.</p>
<p>The PowerPoint cabinet also contains all the other fonts of the Microsoft <a class="zem_slink" title="ClearType" href="http://en.wikipedia.org/wiki/ClearType" rel="wikipedia">ClearType font</a> collection, of which only Calibri would be of any interest to users, the rest aren&#8217;t that interesting but then again &#8211; I hate serifs (interestingly all of the ClearType font collection fonts start with &#8220;C&#8221;).</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.makeuseof.com/tag/manage-compare-fonts-easily-font-manager-linux/">Manage &amp; Compare Fonts Easily With Font Manager [Linux]</a> (makeuseof.com)</li>
<li class="zemanta-article-ul-li"><a href="http://xpjimt.wordpress.com/2011/10/01/free-ttf-font-site/">Free TTF font site</a> (xpjimt.wordpress.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.androidpolice.com/2011/10/19/get-the-new-ics-font-roboto-on-your-android-device-right-now/">Get The New ICS Font Roboto On Your Android Device Right Now</a> (androidpolice.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=788d2c5d-a313-465f-9c2c-6e494282dd79" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/10/22/installing-consolas-truetype-font-for-linux/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Script day: automatically locate the next valid transaction in MySQL binlog</title>
		<link>http://geek.co.il/wp/2011/07/27/script-day-automatically-locate-the-next-valid-transaction-in-mysql-binlog</link>
		<comments>http://geek.co.il/wp/2011/07/27/script-day-automatically-locate-the-next-valid-transaction-in-mysql-binlog#comments</comments>
		<pubDate>Wed, 27 Jul 2011 18:08:13 +0000</pubDate>
		<dc:creator>Oded</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="true">http://geek.co.il/wp/2011/07/27/script-day-automatically-locate-the-next-valid-transaction-in-mysql-binlog</guid>
		<description><![CDATA[Sometimes the MySQL replication breaks due to some corruption in the binary log files. When your binary log files are corrupted, the only option (other then trying to rebuild a database of hundreds of gigabytes) is to try to skip over the corrupted region and get the slave to pick up from where the transactions [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes the <a class="zem_slink" title="MySQL" href="http://www.mysql.com" rel="homepage">MySQL</a> replication breaks due to some corruption in the binary log files. When your binary log files are corrupted, the only option (other then trying to rebuild a database of hundreds of gigabytes) is to try to skip over the corrupted region and get the slave to pick up from where the transactions are valid.</p>
<p>Locating the correct position in the binary log from which the server can carry on is difficult but can be made easier by the <code>mysqlbinlog</code> utility that can scan the binary log files and show you which position is valid using the <code>--start-position</code> to try random positions in the binary log file and see which position will let you read from the file.</p>
<p><span id="more-1764"></span>Still, testing each and every possible byte position by hand is very time consuming, not to say very boring. The following small script will allocate the next readable position in the binary log, given a beginning position (that you can see in the MySQL slave status IO position).</p>
<pre>start=1008443439
end=$(($start+20000))
binlog=mysql-bin.021468
for; do
  if mysqlbinlog -vv $binlog --start-position=$pos \
        --stop-position=$end &gt; /dev/null 2&gt;&amp;1; then
    echo $pos
    break
  fi
done</pre>
<p>[All numbers are made up, obviously - substitute your own]</p>
<p>This will echo the first position in the specified MySQL binary log, from which the log can be read correctly (assuming the corruption is smaller then 20K). You then can restart the slave after the corrupted part by issuing these commands to MySQL:</p>
<pre>STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='my-master', MASTER_USER='this-slave',
MASTER_PASSWORD='my-password', MASTER_LOG_FILE='mysql-bin.021468',
MASTER_LOG_POS=1008444916;
STOP SLAVE;</pre>
<p>[Where 1008444916 is the position the script reported]</p>
<p><strong>Important note:</strong> This is only relevant when it&#8217;s affordable to lose few transactions (you should pay attention to the distance between the last position of the IO thread and the position that this script find as usable). If you fear that there may be important data in the missing transactions &#8211; don&#8217;t use this method and do rebuild your database.</p>
<h6 class="zemanta-related-title">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://sqldbpool.com/2011/07/07/mysql-replication-setup/">MySQL Replication Setup</a> (sqldbpool.com)</li>
<li class="zemanta-article-ul-li"><a href="http://kozar.wordpress.com/2011/07/17/how-to-set-up-ssh-encrypted-mysql-replication/">How To Set Up SSH Encrypted MySQL Replication</a> (kozar.wordpress.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.prweb.com/releases/R1Soft_CDP_Database/Backup_MySQL_Conference/prweb5239714.htm">R1Soft Discusses CDP Backup Software for MySQL Databases at 2011 MySQL Conference and Expo</a> (prweb.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.pcworld.com/article/228786/Five_Things_You_Need_to_Know_About_MySQL.html">Five Things You Need to Know About MySQL</a> (pcworld.com)</li>
</ul>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" src="http://img.zemanta.com/zemified_a.png?x-id=e70f2103-60a6-4687-aa86-b6425fd15cb8" alt="Enhanced by Zemanta" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://geek.co.il/wp/2011/07/27/script-day-automatically-locate-the-next-valid-transaction-in-mysql-binlog/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

