<?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>dan.thoughts &#187; Linux</title>
	<atom:link href="http://blog.sosedoff.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sosedoff.com</link>
	<description>Web-development, PHP, Ruby, Sinatra, Merb, Rails, MySQL, SQLite, Web Services.</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:54:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scaling images with RScale</title>
		<link>http://blog.sosedoff.com/2011/01/22/scaling-images-with-rscale/</link>
		<comments>http://blog.sosedoff.com/2011/01/22/scaling-images-with-rscale/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 00:59:40 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[image-processing]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[rscale]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=307</guid>
		<description><![CDATA[There are few different image processing libraries out there right now:
- Paperclip
- DragonFly
- CarrierWave
But sometimes you need just a tool that does the simple job &#8211; scale and save to fs as easy as possible. Here is the library i made for this specific role: RScale. It is a simple image processing library for ruby [...]]]></description>
			<content:encoded><![CDATA[<p>There are few different image processing libraries out there right now:<br />
- <a href="https://github.com/thoughtbot/paperclip">Paperclip</a><br />
- <a href="https://github.com/markevans/dragonfly">DragonFly</a><br />
- <a href="https://github.com/jnicklas/carrierwave">CarrierWave</a></p>
<p>But sometimes you need just a tool that does the simple job &#8211; scale and save to fs as easy as possible. Here is the library i made for this specific role: <a href="http://github.com/sosedoff/rscale">RScale</a>. It is a simple image processing library for ruby scripts based on ImageMagick terminal tool. Allows you to define a set of image formats and its exact dimensions and generate thumbnails just with one call. It does not have any other features than making thumbnails, neither it keeps the original source. You also can use it with Rails 2/3, Sinatra or any other framework.</p>
<h3>Installation</h3>
<p>Make sure you have <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a> installed on your system.<br />
You can install it using aptitude or compile from source.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> imagemagick</pre></div></div>

<p>Install Rscale as ruby gem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rscale</pre></div></div>

<h3>Getting Started</h3>
<p>First, we need to setup the actual store folder. In rails it would be Rails.root + &#8220;/public&#8221;.<br />
Make sure this folder is writable.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">RScale.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span>
  c.<span style="color:#9900CC;">public</span> = <span style="color:#996600;">&quot;PATH_TO_YOUR_OUTPUT_DIR&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now, we need to define formats. Format is a holder of different image styles.<br />
Here is &#8216;avatar&#8217; format with 3 styles (64&#215;64, 128&#215;128, 256&#215;256).</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> RScale.<span style="color:#CC0066; font-weight:bold;">format</span> <span style="color:#ff3333; font-weight:bold;">:avatar</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
   f.<span style="color:#9900CC;">url</span> = <span style="color:#996600;">'/static/:format/:style/:uuid_dir/:uuid.jpg'</span> <span style="color:#008000; font-style:italic;"># optional</span>
   f.<span style="color:#9900CC;">style</span> <span style="color:#ff3333; font-weight:bold;">:small</span>,       <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'64x64'</span>, <span style="color:#ff3333; font-weight:bold;">:sharp</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:q</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">50</span>
   f.<span style="color:#9900CC;">style</span> <span style="color:#ff3333; font-weight:bold;">:medium</span>,  <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'128x128'</span>
   f.<span style="color:#9900CC;">style</span> <span style="color:#ff3333; font-weight:bold;">:large</span>,       <span style="color:#ff3333; font-weight:bold;">:size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'256x256'</span>
 <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>Style options:</strong></p>
<ul>
<li>:size &#8211; Exact image size in pixels as follows: &#8216;Width x Height&#8217;
<li>:sharp &#8211; Sharpen image after processing (true/false)</li>
<li>:q &#8211; Output image quality (0..100)</li>
</ul>
<p>URL parameter is just a path to store generated thumbnails, relative to public path defined in configuration block. Available URL parameters:</p>
<li>:uuid &#8211; 32-byte UUID string</li>
<li>:uuid_dir &#8211; /xx/xx directory structure generated from uuid string</li>
<li>:md5 &#8211; 32-byte source image MD5 checksum</li>
<li>:time &#8211; Unix timestamp</li>
<li>:extension &#8211; Original extension of source image</li>
<li>:filename &#8211; Original filename of source image</li>
<li>:format &#8211; Name of user-defined format</li>
<li>:style  &#8211; Name of user-defined format style (ex. :small, :medium, :large)</li>
<h3>Usage example</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">path = <span style="color:#996600;">'/tmp/.....'</span> <span style="color:#008000; font-style:italic;"># path to the source/uploaded image</span>
result = RScale.<span style="color:#9900CC;">image_for</span> <span style="color:#ff3333; font-weight:bold;">:avatar</span>, path
&nbsp;
<span style="color:#008000; font-style:italic;"># If source file cannot be processed result will always be null</span>
<span style="color:#9966CC; font-weight:bold;">unless</span> result.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  <span style="color:#008000; font-style:italic;"># result will contain processed thumbnails with path relative to public path</span>
  result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:small</span><span style="color:#006600; font-weight:bold;">&#93;</span>           <span style="color:#008000; font-style:italic;"># 64x64</span>
  result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:medium</span><span style="color:#006600; font-weight:bold;">&#93;</span>      <span style="color:#008000; font-style:italic;"># 128x128</span>
  result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:large</span><span style="color:#006600; font-weight:bold;">&#93;</span>           <span style="color:#008000; font-style:italic;"># 256x256</span>
 <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>RScale does not support uploads to any remote storage systems like AmazonS3, CloudFiles, etc.<br />
Maybe it will support it later, but i dont think it needs that due to its purpose. </p>
<h3>Source</h3>
<p>Feel free to extend the library: <a href="http://github.com/sosedoff/rscale">RScale on Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2011/01/22/scaling-images-with-rscale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom field aggregations in Sphinx using SphinxQL</title>
		<link>http://blog.sosedoff.com/2010/09/06/custom-field-aggregations-in-sphinx-using-sphinxql/</link>
		<comments>http://blog.sosedoff.com/2010/09/06/custom-field-aggregations-in-sphinx-using-sphinxql/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 01:52:23 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[aggregations]]></category>
		<category><![CDATA[indexing]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[query language]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[sphinx ql]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=270</guid>
		<description><![CDATA[Sphinx is a really powerful tool for a full-text database search. It is the perfect option as a search engine on your website&#8217;s data.
In default mode it works as a regular tcp server and has multiple native language bindings for php, ruby, c, etc. But its another outstanding feature is MySQL Protocol Connectoin and SphinxQL, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sphinxsearch.com/">Sphinx</a> is a really powerful tool for a full-text database search. It is the perfect option as a search engine on your website&#8217;s data.<br />
In default mode it works as a regular tcp server and has multiple native language bindings for php, ruby, c, etc. But its another outstanding feature is MySQL Protocol Connectoin and SphinxQL, which is similar to native mysql query language. </p>
<p>So, ok. Lets say we have N documents with M attributes. Attributes could be different: string, integer, double, boolean. Out objective is to perform attribute aggregation based on specified search term (user-defined, etc). That will give us full information on data selected only by search term. Its only use-case when you really need to get these aggregate fields.  Next part is tricky and not really efficient. </p>
<p>First of all, you have to setup Sphinx search daemon instance using different configuration file (it could not run both). Another problem &#8211; you have to setup another data sources and index files, Sphinx puts a lock on all used-right-now files. </p>
<p>Lets assume we have a database of books. We need to build a form with sliders which could be used as user-friendly search filter. All we need is to get a list of min and max attributes values. But there is a problem: sometimes, while working with sphinx you might find yourself trying to use it like you usually do with regular RDMS. Unfortunately, sphinx has a different design. Basically, sphinx has one primary field which presents in each search request &#8211; DocumentID. Its an unique id that represents your data ID, which makes it harder to product aggregate data. And there is no way to get rid of that field.<br />
The whole idea of our aggregation &#8211; using boolean match mode with no weighting performed at all. In that case all results will have weight field = 1. That will give us ability to group all the results by weight field, rejecting the DocumentID field. </p>
<p>Here is the sample query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
  MIN<span style="color: #66cc66;">&#40;</span>reviews<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> min_reviews<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>reviews<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> max_reviews<span style="color: #66cc66;">,</span>
  MIN<span style="color: #66cc66;">&#40;</span>pages<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> min_pages<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>pages<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> max_pages<span style="color: #66cc66;">,</span>
  MIN<span style="color: #66cc66;">&#40;</span>pub_year<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> min_date<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>pub_year<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> max_date<span style="color: #66cc66;">,</span>
  @weight <span style="color: #993333; font-weight: bold;">AS</span> w
<span style="color: #993333; font-weight: bold;">FROM</span> 
  INDEX_NAME
<span style="color: #993333; font-weight: bold;">WHERE</span>
  MATCH<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SEARCH_TERM'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> pages <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">30</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> w <span style="color: #993333; font-weight: bold;">OPTION</span> ranker <span style="color: #66cc66;">=</span> none</pre></div></div>

<p>The result of this query will be one row with field alias names. Thats&#8217;s it. </p>
<p>All statements are fully customizable. Just check <a href="http://www.sphinxsearch.com/docs/current.html#sphinxql-reference">full SphinxQL reference</a> for details.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/09/06/custom-field-aggregations-in-sphinx-using-sphinxql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting processor affinity for a certain task or process in Linux</title>
		<link>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/</link>
		<comments>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 01:43:37 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[cores]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[smp]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=218</guid>
		<description><![CDATA[When you are using SMP you might want to override the kernel&#8217;s process scheduling and bind a certain process to a specific CPU(s).
What is this?
CPU affinity is nothing but a scheduler property that &#8220;bonds&#8221; a process to a given set of CPUs on the SMP system. The Linux scheduler will honor the given CPU affinity [...]]]></description>
			<content:encoded><![CDATA[<p>When you are using <a href="http://en.wikipedia.org/wiki/Symmetric_multiprocessing">SMP</a> you might want to override the kernel&#8217;s process scheduling and bind a certain process to a specific CPU(s).</p>
<h4>What is this?</h4>
<p>CPU affinity is nothing but a scheduler property that &#8220;bonds&#8221; a process to a given set of CPUs on the SMP system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity:</p>
<blockquote><p>The scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. For example, application such as Oracle (ERP apps) use # of cpus per instance licensed. You can bound Oracle to specific CPU to avoid license problem. This is a really useful on large server having 4 or 8 CPUS</p></blockquote>
<h4>Setting processor affinity for a certain task or process using taskset command</h4>
<p>taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. However taskset is not installed by default. You need to install schedutils (Linux scheduler utilities) package.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> shedutils</pre></div></div>

<p>Under latest version of Debian / Ubuntu Linux taskset is installed by default using util-linux package.</p>
<p>The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. For example:</p>
<ul>
<li>0&#215;00000001 is processor #0 (1st processor)</li>
<li>0&#215;00000003 is processors #0 and #1</li>
<li>0&#215;00000004 is processors #2 (3rd processor)</li>
</ul>
<p>To set the processor affinity of process 13545 to processor #0 (1st processor) type following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ taskset 0x00000001 <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span></pre></div></div>

<p>If you find a bitmask hard to use, then you can specify a numerical list of processors instead of a bitmask using -c flag:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ taskset <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span>
$ taskset <span style="color: #660033;">-c</span> <span style="color: #000000;">3</span>,<span style="color: #000000;">4</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span></pre></div></div>

<p>where  -p : Operate on an existing PID and not launch a new task (default is to launch a new task)</p>
<p><small>via <a href="http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html">http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing simple daemons in C</title>
		<link>http://blog.sosedoff.com/2009/02/13/writing-simple-daemons-in-c/</link>
		<comments>http://blog.sosedoff.com/2009/02/13/writing-simple-daemons-in-c/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 07:03:26 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[simple daemon]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=63</guid>
		<description><![CDATA[Since i started writing simple manuals about how to make system daemons i found bunch of interesting documents. For today, i just want to publish one of them instead of writing source code. This is manual originally written by Devin Watson, can be very useful for those how have no idea how to develop such [...]]]></description>
			<content:encoded><![CDATA[<p>Since i started writing simple manuals about how to make system daemons i found bunch of interesting documents. For today, i just want to publish one of them instead of writing source code. This is manual originally written by Devin Watson, can be very useful for those how have no idea how to develop such system daemons. It`s only a basic information.</p>
<p><a href="http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html">http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/02/13/writing-simple-daemons-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

