<?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>self.send(belongs_to :me)</title>
	<atom:link href="http://rushthinking.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rushthinking.com</link>
	<description>Amr Numan Tamimi</description>
	<lastBuildDate>Sat, 28 May 2011 08:04:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Using Monit to manage and monitor server&#8217;s processes and services on Ubuntu &gt;= 10.04</title>
		<link>http://rushthinking.com/using-monit/</link>
		<comments>http://rushthinking.com/using-monit/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 10:36:53 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://blog.rushthinking.com/?p=51</guid>
		<description><![CDATA[Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. Why Monit? Monit is light weight application runs on UNIX systems. You can run it daemonized in the background to [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.</p>
</div>
<p><span id="more-51"></span></p>
<div>
<h2>Why Monit?</h2>
<p>Monit is light weight application runs on UNIX systems. You can run it daemonized in the background to watch all the processes you specify in the Monit configuration file. Also, it has a good web Graphical User Interface, that let you watch the tasks you specify for Monit. you can <code class="codecolorer text geshi"><span class="text">start service(s)</span></code>, <code class="codecolorer text geshi"><span class="text">stop service(s)</span></code>, <code class="codecolorer text geshi"><span class="text">restart service(s)</span></code> via the web interface.</p>
</div>
<div>
<h2>What Monit can do?</h2>
<p>Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamp changes, checksum changes or size changes. You can also monitor remote hosts; Monit can ping a remote host and can check TCP/IP port connections and server protocols. Monit is controlled via an easy to use control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions and recovery status via customizable alert.</p>
</div>
<div>
<h3>Example problem</h3>
<p>Let’s say you have <code class="codecolorer text geshi"><span class="text">Apache</span></code> or <code class="codecolorer text geshi"><span class="text">Nginx</span></code> web server that runs on your server. Suddenly, your website is down, because the used memory exceeded the limits, lets say that! The solution is to restart your <code class="codecolorer text geshi"><span class="text">web server</span></code>. You have to login your server via <code class="codecolorer text geshi"><span class="text">ssh</span></code> and restart the server! This would take time. So what about restarting it via a simple web page? What about make the server restart automatically when some conditions happen? Cool yeah?</p>
</div>
<div>
<h2>Up and running in 15 minutes</h2>
<h3>Installing on Ubuntu</h3>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> monit</div></td></tr></tbody></table></div>
</div>
<div>
<h3>Configurations</h3>
<p>Default configurations are located at <code class="codecolorer text geshi"><span class="text">/etc/monit/monitrc</span></code> you can edit it. Or if you find that it includes some other files in the bottom of <code class="codecolorer text geshi"><span class="text">/etc/monit/monitrc</span></code> it’s recommended to edit the included files!</p>
</div>
<div>
<p>In my case all lines of <code class="codecolorer text geshi"><span class="text">/etc/monit/monitrc</span></code> are commented out, and in the bottom of the file there’s this snippet:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">###############################################################################</span><br />
<span style="color: #666666; font-style: italic;">## Includes</span><br />
<span style="color: #666666; font-style: italic;">###############################################################################</span><br />
<span style="color: #666666; font-style: italic;">##</span><br />
<span style="color: #666666; font-style: italic;">## It is possible to include additional configuration parts from other files or</span><br />
<span style="color: #666666; font-style: italic;">## directories.</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>monit.d<span style="color: #000000; font-weight: bold;">/*</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;">#</span></div></td></tr></tbody></table></div>
</div>
<div>
<p>So, now we have to make edits in the folder of <code class="codecolorer text geshi"><span class="text">/etc/monit.d/</span></code>. By default you’ll find <code class="codecolorer text geshi"><span class="text">localhost</span></code> file in <code class="codecolorer text geshi"><span class="text">/etc/monit.d/</span></code> and that seems that this is the only file that be loaded for Monit. Note that maybe you have get <code class="codecolorer text geshi"><span class="text">sudo</span></code> permission to edit this file.</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">set</span> daemon <span style="color: #000000;">20</span><br />
<span style="color: #000000; font-weight: bold;">set</span> logfile syslog facility log_daemon<br />
<br />
<span style="color: #000000; font-weight: bold;">set</span> mailserver smtp.gmail.com port <span style="color: #000000;">587</span> <span style="color: #666666; font-style: italic;"># if you want to use Gmail/Google app mail as a sender</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; username <span style="color: #ff0000;">&quot;_EMAIL_&quot;</span> password <span style="color: #ff0000;">&quot;_PASSWORD_&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; using tlsv1<br />
&nbsp; &nbsp; &nbsp; &nbsp; with timeout <span style="color: #000000;">30</span> seconds<br />
<br />
<span style="color: #000000; font-weight: bold;">set</span> alert MY_PERSONAL_EMAIL<span style="color: #000000; font-weight: bold;">@</span>domain.com <span style="color: #666666; font-style: italic;"># set this to recive alerts and notifications</span><br />
<br />
<span style="color: #000000; font-weight: bold;">set</span> httpd port <span style="color: #000000;">2812</span> and <span style="color: #666666; font-style: italic;"># Monit will run on port 2812</span><br />
&nbsp; &nbsp; use address localhost<br />
&nbsp; &nbsp; allow localhost<br />
&nbsp; &nbsp; allow 192.168.0.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #666666; font-style: italic;">#set your network ip range</span><br />
&nbsp; &nbsp; allow USERNAME:PASSWORD <span style="color: #666666; font-style: italic;">#set your username and password to loin to your Monit</span></div></td></tr></tbody></table></div>
</div>
<div>
<p>Now run Monit with the new configs with <code class="codecolorer text geshi"><span class="text">sudo monit -d 60 -c /etc/monit/monitrc</span></code></p>
<p>Try to curl localhost:2812 by <code class="codecolorer text geshi"><span class="text">curl localhost:2812</span></code> and you’ll get this response, Unauthorized response as expected.</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;</span>html<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">head</span><span style="color: #000000; font-weight: bold;">&gt;&lt;</span>title<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">401</span> Unauthorized<span style="color: #000000; font-weight: bold;">&lt;/</span>title<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span><span style="color: #c20cb9; font-weight: bold;">head</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>body <span style="color: #007800;">bgcolor</span>=<span style="color: #666666; font-style: italic;">#FFFFFF&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>h2<span style="color: #000000; font-weight: bold;">&gt;</span>Unauthorized<span style="color: #000000; font-weight: bold;">&lt;/</span>h2<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; You are <span style="color: #000000; font-weight: bold;">&lt;</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>not<span style="color: #000000; font-weight: bold;">&lt;/</span>b<span style="color: #000000; font-weight: bold;">&gt;</span> authorized to access <span style="color: #000000; font-weight: bold;">&lt;</span>i<span style="color: #000000; font-weight: bold;">&gt;</span>monit<span style="color: #000000; font-weight: bold;">&lt;/</span>i<span style="color: #000000; font-weight: bold;">&gt;</span>.<br />
&nbsp; &nbsp; Either you supplied the wrong credentials <span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g. bad password<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<br />
&nbsp; &nbsp; or your browser doesn<span style="color: #ff0000;">'t understand how to supply the credentials required<br />
&nbsp; &nbsp; &lt;p&gt;&lt;hr&gt;&lt;a href='</span>http:<span style="color: #000000; font-weight: bold;">//</span>mmonit.com<span style="color: #000000; font-weight: bold;">/</span>monit<span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">'&gt;&lt;font size=-1&gt;monit 5.0.3&lt;/font&gt;&lt;/a&gt;<br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</span></div></td></tr></tbody></table></div>
</div>
<div>
<p>Congratulations! Your Monit is running well!</p>
</div>
<div>
<h2>I wanna see what I&#8217;ve done!!</h2>
<p>If you are running <code class="codecolorer text geshi"><span class="text">Nginx</span></code> on your server, and you want to access Monit on some domain, you can get this behavior using a proxy pass.</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">server <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; listen <span style="color: #000000;">80</span>;<br />
&nbsp; server_name services.DOMAIN.com;<br />
&nbsp; location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; proxy_pass http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">2812</span>;<br />
&nbsp; &nbsp; proxy_set_header Host <span style="color: #007800;">$host</span>;<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Or on <code class="codecolorer text geshi"><span class="text">Apache</span></code></p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; ServerName services.DOMAIN.com<br />
&nbsp; &nbsp; ProxyPass <span style="color: #000000; font-weight: bold;">/</span> http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">2812</span><br />
&nbsp; &nbsp; ProxyPassReverse <span style="color: #000000; font-weight: bold;">/</span> http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">2812</span><br />
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
</div>
<div>
<p>Restart you <code class="codecolorer text geshi"><span class="text">Apache</span></code> or <code class="codecolorer text geshi"><span class="text">Nginx</span></code> server and go to <code class="codecolorer text geshi"><span class="text">services.DOMAIN.com</span></code>. You’ll get a prompt to put your username and password. Enter what we already set in <code class="codecolorer text geshi"><span class="text">/etc/monit.d/localhost</span></code>. And here we go!</p>
<p class="center">
<img src="http://mmonit.com/monit/screenshots/images/screenshots/1.png" alt="Monit GUI" width="500" />
</p>
</div>
<div>
<h2>Adding services</h2>
<p>You can add services to monitor as much as you want, just add some lines in the bottom of <code class="codecolorer text geshi"><span class="text">/etc/monit.d/localhost</span></code>.</p>
</div>
<div>
<h3>Monit service</h3>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">check process monit<br />
&nbsp; &nbsp;with pidfile <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>monit.pid<br />
&nbsp; &nbsp;start program &nbsp;<span style="color: #ff0000;">&quot;/etc/init.d/monit start&quot;</span><br />
&nbsp; &nbsp;stop program &nbsp;<span style="color: #ff0000;">&quot;/etc/init.d/monit stop&quot;</span></div></td></tr></tbody></table></div>
</div>
<div>
<h3>Nginx service</h3>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">check process nginx <br />
&nbsp; with pidfile <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid <span style="color: #666666; font-style: italic;">#Pid file for nginx in my case it located in /opt/nginx/logs/</span><br />
&nbsp; start program = <span style="color: #ff0000;">&quot;/etc/init.d/nginx start&quot;</span><br />
&nbsp; stop program = <span style="color: #ff0000;">&quot;/etc/init.d/nginx stop&quot;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> failed host IP_ADDRESS port <span style="color: #000000;">80</span> protocol HTTP <span style="color: #000000; font-weight: bold;">then</span> restart <span style="color: #666666; font-style: italic;">#set your server IP that runs nginx</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000;">5</span> restarts with <span style="color: #000000;">5</span> cycles <span style="color: #000000; font-weight: bold;">then</span> timeout<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> cpu is greater than <span style="color: #000000;">30</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000;">2</span> cycles <span style="color: #000000; font-weight: bold;">then</span> alert<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> cpu is greater than <span style="color: #000000;">50</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000;">5</span> cycles <span style="color: #000000; font-weight: bold;">then</span> restart<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> totalmem is greater than <span style="color: #000000;">50.0</span> MB <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000;">5</span> cycles <span style="color: #000000; font-weight: bold;">then</span> restart<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> children is greater than <span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">then</span> restart</div></td></tr></tbody></table></div>
</div>
<div>
<h3>I will update and add more services later.</h3>
<h2>Good cases to use Monit</h2>
<ul>
<li>- Monitoring Web Applications that run as deamons, like: thin, mongrel, passenger standalone, …</li>
<li>- Monitoring MongoDB database folder’s permissions.</li>
<li>- Monitoring <a href="http://nodejs.org/">Node.js</a> applications.</li>
</ul>
</div>
<div>
<h2>Conclusion</h2>
<p><a href="http://mmonit.com/monit/">Monit</a> is a great tool to monitor your server. It has lots of feature that I didn’t mention in this blog post. You have to give a try. Also don’t forget to take a look at <a href="http://mmonit.com/monit/documentation/">Monit Official Documentation</a> and there’s a <a href="http://fosscasts.com/screencasts/6-System-Monitoring-With-Monit">screencast by FOSSCasts</a>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/using-monit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real Web Based Console</title>
		<link>http://rushthinking.com/real-web-based-console/</link>
		<comments>http://rushthinking.com/real-web-based-console/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 22:01:11 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.rushthinking.com/?p=32</guid>
		<description><![CDATA[Couple weeks ago I worked on making a web based shell. Before, I started googling &#8221;web based shell&#8221;, but couldn’t find what I was looking for. Later, I decided to start build my own with my own view. I picked Sinatra Web Framework for its ease of use for building APIs. And here I will talk about [...]]]></description>
			<content:encoded><![CDATA[<p>Couple weeks ago I worked on making a web based shell.</p>
<p>Before, I started googling &#8221;web based shell&#8221;, but couldn’t find what I was looking for. Later, I decided to start build my own with my own view.</p>
<p><span id="more-32"></span></p>
<p>I picked <a href="http://www.sinatrarb.com/">Sinatra Web Framework</a> for its ease of use for building APIs. And here I will talk about the concept of building it.</p>
<p>First the tree of the application was like this:</p>
<div>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">console<br />
<span style="color: #000000; font-weight: bold;">`|</span>- app.rb<br />
&nbsp;<span style="color: #000000; font-weight: bold;">|</span>- config.ru<br />
&nbsp;<span style="color: #000000; font-weight: bold;">|</span>- public<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">|</span>- views<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">|</span>- web<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">`|</span>- folder_1<br />
&nbsp; <span style="color: #000000; font-weight: bold;">|</span>- folder_2</div></td></tr></tbody></table></div>
</div>
<div>
<h2>Building the API</h2>
<div>
<h3>app.rb</h3>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Console <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Sinatra::Base</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'json'</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'yaml'</span><br />
<br />
&nbsp; BASE_PATH = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/web&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># BASE_PATH is The folder the the console will only access</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># Also, enable Sinatra Cookies and Sessions</span><br />
<br />
&nbsp; get <span style="color:#996600;">'/'</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_path</span><span style="color:#006600; font-weight:bold;">&#93;</span> = BASE_PATH<br />
&nbsp; &nbsp; haml <span style="color:#ff3333; font-weight:bold;">:index</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; before <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; set_current_dir<br />
&nbsp; &nbsp; @<span style="color:#CC0066; font-weight:bold;">p</span> = env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;rack.request.query_hash&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;">#accessing `q` and `XXX` like ?q=XXX</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># I dont know if theres another way</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> set_current_dir <span style="color:#008000; font-style:italic;">#set @current for the current folder we are</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@current</span> = session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_path</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp;<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> f_level<span style="color:#006600; font-weight:bold;">&#40;</span>path1_string, path2_string<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Check http://stackoverflow.com/questions/4353410/any-function-in-ruby-determine-the-difference-between-folders-level</span><br />
&nbsp; &nbsp; path1, path2 = <span style="color:#006600; font-weight:bold;">&#91;</span>path1_string, path2_string<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> s.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>::SEPARATOR<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; minsize = <span style="color:#006600; font-weight:bold;">&#91;</span>path1, path2<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>amp;:size<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">min</span><br />
&nbsp; &nbsp; path1.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span>minsize<span style="color:#006600; font-weight:bold;">&#41;</span> == path2.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span>minsize<span style="color:#006600; font-weight:bold;">&#41;</span> ? path1.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">-</span> path2.<span style="color:#9900CC;">size</span> : <span style="color:#0000FF; font-weight:bold;">nil</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; get <span style="color:#996600;">'/api/v0.1/:command'</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; content_type <span style="color:#ff3333; font-weight:bold;">:json</span><br />
&nbsp; &nbsp; msg = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># a hash for returning errors, messages etc.</span><br />
<br />
&nbsp; &nbsp; f = <span style="color:#996600;">&quot;#{@current}/#{@p['q']}&quot;</span><br />
&nbsp; &nbsp; f = <span style="color:#996600;">&quot;#{@current}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> @<span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; msg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;No such file or directory - #{@p['q']} in ~/#{@current[@current.index('web'), @current.length]}&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> msg.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; level = f_level<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span>, BASE_PATH<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> level.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#006600; font-weight:bold;">||</span> level <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">||</span> level.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#006600; font-weight:bold;">||</span> @<span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&amp;</span>amp;<span style="color:#006600; font-weight:bold;">&amp;</span>amp; @<span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">'/'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># this prevents user to go up the folder `/web` Or that you specified in BASE_PATH</span><br />
&nbsp; &nbsp; &nbsp; msg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Unauthorized to access #{@p['q']}&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> msg.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; f = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:command</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;pwd&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/LOTS_OF_FOLDERS/#{@current[@current.index('web'), @current.length]}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_json</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;cd&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_path</span><span style="color:#006600; font-weight:bold;">&#93;</span> = f<br />
&nbsp; &nbsp; &nbsp; &nbsp; session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_path</span><span style="color:#006600; font-weight:bold;">&#93;</span> = BASE_PATH <span style="color:#9966CC; font-weight:bold;">if</span> @<span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f = session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_path</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;cd: #{@p['q']}: Not a directory&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;ls&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{f}/*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;ls: #{@p['q']}: Not a directory&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;cat&quot;</span> <span style="color:#008000; font-style:italic;">#show file content</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">file</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result = <span style="color:#996600;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">&amp;</span>lt; file.<span style="color:#CC0066; font-weight:bold;">gets</span>.<span style="color:#9900CC;">strip</span> <span style="color:#9966CC; font-weight:bold;">while</span> !file.<span style="color:#9900CC;">eof</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; result.<span style="color:#9900CC;">strip</span>.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;cat: #{@p['q']}: Is a directory&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; msg.<span style="color:#9900CC;">to_json</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># &quot;cat: No such file or directory - #{@p['q']} in #{@current}&quot;.to_json</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;invalid all&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
</div>
<div>
<h3>config.ru</h3>
<div class="codecolorer-container ruby railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sinatra'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'haml'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sass'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'./app'</span><br />
run Console</div></td></tr></tbody></table></div>
</div>
</div>
<div>
<h2>Examples that return JSON object</h2>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>api<span style="color: #000000; font-weight: bold;">/</span>v0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">pwd</span><br />
<span style="color: #000000; font-weight: bold;">/</span>api<span style="color: #000000; font-weight: bold;">/</span>v0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">cd</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>?<span style="color: #007800;">q</span>=SOME_FOLDER<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">/</span>api<span style="color: #000000; font-weight: bold;">/</span>v0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ls</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>?<span style="color: #007800;">q</span>=SOME_FOLDER<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">/</span>api<span style="color: #000000; font-weight: bold;">/</span>v0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">cat</span>?<span style="color: #007800;">q</span>=SOME_FILE</div></td></tr></tbody></table></div>
</div>
<div>
<h2>Also try the plain JSON returns of the API (use them one by one to get the concept)</h2>
<p>
- <a href="http://lab.rushthinking.com/api/v1.0/pwd">http://lab.rushthinking.com/api/v1.0/pwd</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/cd">http://lab.rushthinking.com/api/v1.0/cd</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/cd?q=posts">http://lab.rushthinking.com/api/v1.0/cd?q=posts</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/pwd">http://lab.rushthinking.com/api/v1.0/pwd</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/cd?q=..">http://lab.rushthinking.com/api/v1.0/cd?q=..</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/ls">http://lab.rushthinking.com/api/v1.0/ls</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/cd?q=pages">http://lab.rushthinking.com/api/v1.0/cd?q=pages</a><br />
- <a href="http://lab.rushthinking.com/api/v1.0/cat?q=about.page">http://lab.rushthinking.com/api/v1.0/cat?q=about.page</a>
</p>
</div>
<div>
<h2>Finally</h2>
<p>You have to run the Sinatra app. I will release its full source on Github soon. For the Graphical user interface I used a custom modified version of <a href="https://github.com/chrisdone/jquery-console">JQuery Console 1.0</a> and some Javascript here and there! You can check a working example <a href="http://lab.rushthinking.com/">here http://lab.rushthinking.com</a>.</p>
</div>
<div>
<h2>Update</h2>
<p>This post is about how building an API in general, I used Ruby File API, and the only methods I worked on is<code class="codecolorer text geshi"><span class="text">cd</span></code>, <code class="codecolorer text geshi"><span class="text">pwd</span></code>, <code class="codecolorer text geshi"><span class="text">ls</span></code>, <code class="codecolorer text geshi"><span class="text">cat</span></code>. Though <code class="codecolorer text geshi"><span class="text">nano</span></code>, <code class="codecolorer text geshi"><span class="text">su</span></code>, <code class="codecolorer text geshi"><span class="text">sudo</span></code> and others will not work! Thanks Jamal Shaheen.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/real-web-based-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yalla &#8217;3 Demo.ps</title>
		<link>http://rushthinking.com/yalla-3-demo-ps/</link>
		<comments>http://rushthinking.com/yalla-3-demo-ps/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 10:30:42 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rushthinking.com/?p=79</guid>
		<description><![CDATA[The title means &#8220;Let&#8217;s go to Demo.ps&#8221; After the second meeting of Demo.ps, I understand now! There are alot of entrepreneurs. Demo.ps: Palestinian Entrepreneurship Forum for Startups and Technology Or in Arabic: تجمع المبادرين و الرياديين الفلسطينيين &#8220;. It&#8217;s the first gesture of its kind in Palestine, to talk about innovations and startups in general, [...]]]></description>
			<content:encoded><![CDATA[<p>The title means &#8220;Let&#8217;s go to Demo.ps&#8221;</p>
<p>After the second meeting of Demo.ps, I understand now! There are alot of entrepreneurs.</p>
<p><span id="more-79"></span></p>
<p><i>Demo.ps: Palestinian Entrepreneurship Forum for Startups and Technology</i><br /> Or in Arabic: تجمع المبادرين و الرياديين الفلسطينيين  &#8220;.</p>
<p>It&#8217;s the first gesture of its kind in Palestine, to talk about innovations and startups in general, e-marketing and solutions, technology and much more.</p>
<p>Day after a day, people wants to know more about Demo.ps, the people behind it and the idea itself. In my previous post &#8220;what&#8217;s demo.ps&#8221;, I wrote it in rush, and nothing -almost- was clear. Well, some more information.</p>
<h3>The Team</h3>
<ul>
<li>- Mohamad Asmar (<a href="http://twitter.com/daigoor">@daigoor</a>)</li>
<li>- Omar Abu Safieh (<a href="http://twitter.com/omarnas">@omarnas</a>)</li>
<li>- Ayman Awartani</li>
<li>- Amr N Tamimi (<a href="http://twitter.com/amrnt">@amrnt</a>)</li>
</ul>
<h3>The Idea</h3>
<p> From the beginning, the idea came and buzzed while a meeting of the three Guys of the team: Amr, Ayman and Omar. First we thought of a video community for technologist in Nablus. Later, we decide to make it such an event from time to time.</p>
<h3>In The Action</h3>
<p>We&#8217;ve done the first session and the introduction session was in my dad office, with the help of Mohammed Salameh, and attending of 20 invited people including Dr. Baker Abdulhaq. The attendees were encouraging of the idea, they liked it and wanted to know more.</p>
<p>We begun our activity through a <a href="http://facebook.com/demops">facebook page for Demo.ps</a>. We collected more than 100 of fans in couple of days. We made a twitter channel (<a href="http://twitter.com/demo_ps">@demo_ps</a>) also! We&#8217;ve gone social! The <a href="http://demo.ps">Demo.ps website</a> is currently in the beta stage, check it out!</p>
<p>For preparing the second meeting, we&#8217;ve got help from Dr. Baker Abdulhaq. And it was done on Saturday, Feb, 20 in a computer lab in the university. Yes, it was amazing. We faced the rapid reaction of the attendees that we didn&#8217;t expect! Many people would like to talk.</p>
<h3>Shots&#8230; Say Cheese!</h3>
<p class="center">
<img src="http://rushthinking.com/wp-content/uploads/2010/02/1.jpg" alt="" title="1" width="300" height="171" class="aligncenter size-full wp-image-93" />
</p>
<p class="center">
<img src="http://rushthinking.com/wp-content/uploads/2010/02/2.jpg" alt="" title="2" width="225" height="300" class="aligncenter size-full wp-image-94" />
</p>
<p class="center">
<img src="http://rushthinking.com/wp-content/uploads/2010/02/3.jpg" alt="" title="3" width="300" height="225" class="aligncenter size-full wp-image-95" />
</p>
<h3>Challenges</h3>
<p>In the second meeting, some people bet on us, that the attendees won&#8217;t break the 10 people! Well, the attendees were 10 multiply 8. Yes almost 80 people were attended this meeting, and many others said sorry that they couldn&#8217;t attend. So, see you next meeting.</p>
<p>Next time, we expect more people, so more space is needed!</p>
<h3>Special Thanks</h3>
<ul>
<li>- Dr. Baker Abdulhaq</li>
<li>- Inst. Mohammed Salameh</li>
<li>- Dr. Maher Arafat</li>
<li>- All attendees of the previous sessions so far.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/yalla-3-demo-ps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Demo.ps?</title>
		<link>http://rushthinking.com/what-is-demo-ps/</link>
		<comments>http://rushthinking.com/what-is-demo-ps/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 10:22:51 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rushthinking.com/?p=72</guid>
		<description><![CDATA[In Palestine, the core of the information technology growth is the youth. And the Technical openness which happened in previous years is the gate for the perfect progress in the natural life, especially in the technological development. Recently, an union of information technology has been established in Nablus. A good move. But what then? It [...]]]></description>
			<content:encoded><![CDATA[<p>In Palestine, the core of the information technology growth is the youth. And the Technical openness which happened in previous years is the gate for the perfect progress in the natural life, especially in the technological development.</p>
<p><span id="more-72"></span></p>
<p>Recently, an union of information technology has been established in Nablus. A good move. But what then? It must be effective for tech activities etc..</p>
<p>Ummm, okay, Demo.ps has a solution.</p>
<h3>The Name</h3>
<p>Demo is the shortcut of demonstration word. .PS is the Palestinian domain. And because we/you want to show and talk it&#8217;s Demo.ps</p>
<p class="center">
<img src="http://rushthinking.com/wp-content/uploads/2010/02/demo-300x102.jpg" alt="" title="demo" width="300" height="102" class="aligncenter size-medium wp-image-76" />
</p>
<h3>So what?</h3>
<p>Demo.ps came to hold the initiative minds of youth, developing their technical knowledge, to make them motivated to discover more.</p>
<p>Demo.ps is your stage to talk, share and exchange ideas/information in technology domain.</p>
<h3>In other way</h3>
<p>Demo.ps is a series of sessions that talk about many topics, such as:</p>
<ul>
<li>- Startups and innovations</li>
<li>- Web applications, and development</li>
<li>- E-marketing and solutions for making business</li>
<li>- Mobile development</li>
<li>- New Technologies</li>
<li>- Programming Language</li>
<li>- And more other&#8230;</li>
</ul>
<h3>Get connected</h3>
<p>Currently, <a href="http://demo.ps">Demo.ps Website</a> is in development stage. Visit it bookmark it and come back again</p>
</p>
<p>Also, Demo.ps has social channels on Facebook and Twitter. To stay updated, become a fan on Facebook: <a href="http://www.facebook.com/profile.php?id=295163667153">here</a>. And follow Demo.ps on Twitter: <a href="http://twitter.com/demo_ps">here</a>. Or subscribe to this blog: <a href="http://feeds.feedburner.com/RushThinking">here</a></p>
<h3>Sponsors</h3>
<p>Now, Demo.ps is leaded by <a href="http://highruns.com">Highruns, Inc.</a></p>
<p>If you want to support Demo.ps, contact info[at]demo.ps</p>
<h3>Conclusion</h3>
<p>Demo.ps is a unique-type of sessions/events in Palestine. Now, It covers Nablus area, and soon will cover All the Westbank.</p>
<h2>You have to come! </h2>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/what-is-demo-ps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thinking Global!</title>
		<link>http://rushthinking.com/thinking-global/</link>
		<comments>http://rushthinking.com/thinking-global/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 10:47:09 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rushthinking.com/?p=88</guid>
		<description><![CDATA[In this article I will talk about the thinking global role in making web innovations and startups in Palestine. Young People Well, six years ago, Facebook published as a social web site for Harvard students. The Creator of Facebook, Mark Zucherburg, was only 20 years old. Years later he made Facebook a world wide social [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I will talk about the thinking global role in making web innovations and startups in Palestine.</p>
<p><span id="more-88"></span></p>
<h3>Young People</h3>
<p>Well, six years ago, Facebook published as a social web site for Harvard students. The Creator of Facebook, Mark Zucherburg, was only 20 years old. Years later he made Facebook a world wide social community with millions of users. Nowadays, Mark is rated as the richest guy in the world. Yes, all because Facebook.</p>
<p class="center"><img alt="mark" src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Mark_Zuckerberg_CEO_Facebook.jpg/200px-Mark_Zuckerberg_CEO_Facebook.jpg"/></p>
<h3>Status</h3>
<p>Let&#8217;s back to Palestine, Palestine is witnessing the rapidly rise in the field of technology. All noticed the changes in the daily lives of citizens, we all use iPhones to explore the Internet on the roads, yes, also we have 3G technology. And no books any more, <a href="http://www.amazon.com/Kindle-Amazons-Original-Wireless-generation/dp/B000FI73MA">Amazon Kindle</a> is available for using, and everybody use it. The Internet connection available in 50Mb/s lately. Yes Yes Yes it all Lies.</p>
<p>Honestly, Palestine got the worst. No 3G technology. The Internet Connection is available only up to 2Mb/s &#8211;and everybody has limited quota for his monthly download. This is only about how people connect the WWW. And that is a tip of the iceberg.</p>
<h3>Don&#8217;t wonder, begin with yourself.</h3>
<p>Could we find a guy like Mark in this land. Maybe. Why maybe? say &#8220;Yes&#8221;, say I know somebody, say: &#8220;Me&#8221;. If your answer is &#8220;No&#8221;, then ask again Why no? say &#8220;Yes&#8221;, say I know somebody, say: &#8220;Me&#8221;.</p>
<h3>YES WE CAN</h3>
<p><a href="http://en.wikipedia.org/wiki/Martin_Luther_King,_Jr.">Martin Luther King</a> had a dream and Obama said <a href="http://www.youtube.com/watch?v=jjXyqcx-mYY">Yes We Can</a>, and we all saw how the black people of the US switched from being slaves to be presidents and billionaires.</p>
<p class="center"><img alt="yes we can" src="http://robertsravings.files.wordpress.com/2009/01/barack-obama-yes-we-can-posters.jpg"/></p>
<h3>The Problem</h3>
<p>It&#8217;s itself complicated. Specialists needed to list the problem(s) in the points.</p>
<h3>The Solution</h3>
<p>The solution in my opinion, is to think global -see the needs of the world, not even the area you live in, apply it, share it and I promise you&#8217;ll success.</p>
<p>Thinking locally destroys me. Give me an exact number of people who will use your own social community. Nobody will leave Facebook or Twitter to interacts with such social network that its visitor won&#8217;t hit 1000 people.</p>
<p>Let&#8217;s take <a href="http://www.peeks.ps">Peeks</a> as an example, Peeks means Palestinian Geeks. Well its great idea, but not great as it applied now. Peeks uses <a href="http://www.ning.com/">NING</a> as a ready to use social network -not so nerdy. Okay, first time I saw this &#8220;geeks&#8221; website, I got exited, I signed up, and played around, but naaahhh, I have months with no one login record, why? Ask Peeks Owners.</p>
<p>Another funny example is the Open Advertisements Websites. Let&#8217;s count how many website specialized with such things.</p>
<ul>
<li>- <a href="http://www.safqaonline.com">Safqa Online</a></li>
<li>- <a href="http://www.shobiddak.com">Sho Biddak</a></li>
<li>- <a href="http://www.daleel.ps">Daleel</a></li>
<li>- <a href="http://e-daleelak.ps">E-daleelak</a></li>
<li>- <a href="http://bedkash.ps">Bedkash</a></li>
<li>- And much more&#8230;</li>
</ul>
<p>So do you think people like things like that, they get enough of one at least, so don&#8217;t think of a new website with same idea.</p>
<p>More to talk about&#8230;</p>
<h3>Conclusion</h3>
<p>Think Global, not local. Pick a talent team. Have no limits. Go over sky.</p>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/thinking-global/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world! My world</title>
		<link>http://rushthinking.com/hello-world-my-world/</link>
		<comments>http://rushthinking.com/hello-world-my-world/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:17:13 +0000</pubDate>
		<dc:creator>Amr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.rushthinking.com/?p=1</guid>
		<description><![CDATA[Well, this is my first article in this blog. I wrote lots in my previous blog, and I used Mephisto. Now since my blog is out of date and really out of date, I decided to start a new blog, elegant, clean and in a geeky style! Since I’m a Rubyist, I chose a blog engine [...]]]></description>
			<content:encoded><![CDATA[<p>Well, this is my first article in this blog.</p>
<p>I wrote lots in my previous blog, and I used <a href="http://mephistoblog.com/">Mephisto</a>. Now since my blog is out of date and really out of date, I decided to start a new blog, elegant, clean and in a geeky style!</p>
<p><span id="more-1"></span></p>
<p>Since I’m a Rubyist, <del>I chose a blog engine written in Ruby and one make me feel like real hacker, and here’s My Blog running on the top of <a href="https://github.com/mojombo/jekyll">Jekyll</a></del>. I&#8217;m running it on <a href="http://wordpress.org/">WordPress</a>. <em>&#8220;Time is Gold&#8221;</em></p>
<p>I always try to keep blogging, but unfortunately I’m lazy in writing -even in my Arabic language, And as I am saying <code class="codecolorer text geshi"><span class="text">programmers don't write else code</span></code>.</p>
<p>This blog is my lab, test stage and knowledge “exchange and share” place.</p>
<h3>My World</h3>
<p>I’m a freelance web developer, working with <a href="http://ruby-lang.org/">Ruby Language</a> and its frameworks and Gems. I started learning Ruby with learning <a href="http://rubyonrails.org/">Ruby on Rails</a> in the middle of 2007, at that time I was almost busy so I went back to PHP. I learnt <a href="http://cakephp.org/">CakePHP</a>, and 2 weeks later I returned to Rails, I read 3 of its books, I was in love with that charming language.</p>
<h3>This Blog</h3>
<p>In this blog I’ll write about programming in general, Ruby, technology, tips and tricks, some tutorial series, events around me, ah and my life status.</p>
<h3>Let&#8217;s Go!</h3>
<p>And here we go!!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://rushthinking.com/hello-world-my-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

