{"@attributes":{"version":"2.0"},"channel":{"title":"Dhruva Sagar","link":"https:\/\/dhruvasagar.dev\/","description":"Recent content on Dhruva Sagar","generator":"Hugo","language":"en-us","lastBuildDate":"Sat, 18 Jul 2026 06:00:00 +0530","item":[{"title":"How the Water Holds","link":"https:\/\/dhruvasagar.dev\/posts\/how-the-water-holds\/","pubDate":"Sat, 18 Jul 2026 06:00:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/how-the-water-holds\/","description":"The water holds your body. It holds your attention. It holds what you carry. Notes on healing, disruption, and what a 4k swim through salt and tide taught me about being held."},{"title":"The Poverty of Language and the Search for Emotional Precision","link":"https:\/\/dhruvasagar.dev\/posts\/poverty-of-language-search-for-emotional-precision\/","pubDate":"Fri, 17 Jul 2026 10:54:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/poverty-of-language-search-for-emotional-precision\/","description":"Language compresses rich subjective experiences into symbols that others must reconstruct, making misunderstanding inevitable. Storytelling addresses this limitation by providing context, causality, and emotional structure, creating simulated experiences that allow people to understand one another more deeply. While perfect transmission of experience may be impossible, stories may be one of humanity&rsquo;s most powerful tools for narrowing the distance between minds"},{"title":"The Fear Tax","link":"https:\/\/dhruvasagar.dev\/posts\/the-fear-tax\/","pubDate":"Fri, 05 Jun 2026 10:00:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/the-fear-tax\/","description":"Fear in the workplace is not a motivator. It is a tax. Leaders who let it persist \u2014 or quietly benefit from it \u2014 are paying that tax with their team&rsquo;s initiative, creativity, and willingness to care. Here is what honest leadership looks like when the future is genuinely uncertain."},{"title":"Keep the Friction","link":"https:\/\/dhruvasagar.dev\/posts\/keep-the-friction\/","pubDate":"Thu, 04 Jun 2026 10:30:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/keep-the-friction\/","description":"AI is best at removing exactly the friction where craft, focus, and satisfaction used to live. Refusing it is a pose; there is no exit. The real move is to choose, deliberately, where you keep doing the hard part by hand; because doing it is the point."},{"title":"What I Got Wrong About Discipline, And You Might Too","link":"https:\/\/dhruvasagar.dev\/posts\/what-i-got-wrong-about-discipline\/","pubDate":"Wed, 06 May 2026 16:42:09 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/what-i-got-wrong-about-discipline\/","description":"For years, I thought discipline was simply working hard and striving to improve. Only recently did I realize that true discipline is the resilience to show up and do the work even when you least want to. Here\u2019s what I got wrong, and what you might too."},{"title":"Introducing ruby-upgrade-toolkit","link":"https:\/\/dhruvasagar.dev\/posts\/introducing-ruby-upgrade-toolkit\/","pubDate":"Fri, 01 May 2026 19:58:30 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/introducing-ruby-upgrade-toolkit\/","description":"A Claude Code plugin for Ruby and Rails upgrades. Phased commits, real estimates, project-specific rules. Audit, plan, fix, verify, commit."},{"title":"Slow Down to Speed Up","link":"https:\/\/dhruvasagar.dev\/posts\/slow-down-to-speed-up\/","pubDate":"Wed, 29 Apr 2026 11:00:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/slow-down-to-speed-up\/","description":"Why getting faster has always required slowing down first \u2014 and why the cycle never really ends. Lessons from the cube, the pool, and the codebase, learned and re-learned."},{"title":"The Matrix Has No Exit","link":"https:\/\/dhruvasagar.dev\/posts\/the-matrix-has-no-exit\/","pubDate":"Mon, 27 Apr 2026 11:00:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/the-matrix-has-no-exit\/","description":"The Matrix got the diagnosis right and the cure wrong \u2014 there is no Morpheus, no red pill, no city beneath the city, only the simulation we already inhabit and the seeing of it."},{"title":"Embrace the Wobble","link":"https:\/\/dhruvasagar.dev\/posts\/embrace-the-wobble\/","pubDate":"Wed, 14 Jan 2026 20:45:12 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/embrace-the-wobble\/","description":"<p>Watching my daughter grip her bike&rsquo;s handlebars for the first time, I\nsaw the familiar flicker of fear in her eyes, the apprehension of the\nunknown, the hesitation to stumble, the dread of failure. It reminded\nme of a feeling I know too well, one that lingers in moments of\nuncertainty throughout our lives.<\/p>\n<blockquote>\n<p>\u201cWhat if I fall?\u201d she asked.<\/p>\n<p>I met her gaze and smiled. \u201cDon\u2019t be afraid of falling; instead be\nafraid of never falling,\u201d I said.<\/p>"},{"title":"Building a Scalable Ingestion Pipeline With Rust","link":"https:\/\/dhruvasagar.dev\/posts\/building-a-scalable-ingestion-pipeline-with-rust\/","pubDate":"Mon, 05 May 2025 16:58:25 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/building-a-scalable-ingestion-pipeline-with-rust\/","description":"How to build a scalable ingestion pipeline with Rust"},{"title":"Positive Effects of Exercise on Mental Health","link":"https:\/\/dhruvasagar.dev\/posts\/positive-effects-of-exercise-on-mental-health\/","pubDate":"Mon, 18 Nov 2024 10:51:28 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/positive-effects-of-exercise-on-mental-health\/","description":"Exercise is also a form of meditation, has tremendous positive impact on mental health"},{"title":"Neovim as a Java IDE","link":"https:\/\/dhruvasagar.dev\/posts\/neovim-java-ide\/","pubDate":"Sun, 01 Sep 2024 04:16:00 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/neovim-java-ide\/","description":"<p>Neovim has come a long way today from it&rsquo;s original goal of being able to\nsupport asynchronous jobs. Today it comes packed with a ton of useful and high\nperformance libraries and plugins. To add to that it also has a highly\nenthusiastic and vibrant community of lua developers who are working\ntirelessly to make neovim better.<\/p>\n<p>Today we&rsquo;ll look at how one can easily configure neovim to work similar to\na modern Java IDE.<\/p>"},{"title":"How to Speak","link":"https:\/\/dhruvasagar.dev\/posts\/how-to-speak\/","pubDate":"Sun, 17 Mar 2024 19:54:06 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/how-to-speak\/","description":"Collection of my notes from the lecture titled &lsquo;How to Speak&rsquo; by Patrick Winston"},{"title":"Generic Callbacks in Rust","link":"https:\/\/dhruvasagar.dev\/posts\/generic-callbacks-in-rust\/","pubDate":"Mon, 11 Mar 2024 10:45:06 +0530","guid":"https:\/\/dhruvasagar.dev\/posts\/generic-callbacks-in-rust\/","description":"<p>In a recent project, we developed an ingestion pipeline in Rust. We wanted to\nexecute asynchronous tasks in response to messages received from SQS, as\na <strong>subscriber<\/strong>. Our goal was to leverage Rust generics to allow the\nsubscriber to take ownership of the payload schema and the pipeline\nimplementation details. This approach enables the separation of the SQS\nsubscription logic from the subscriber\u2019s responsibilities, promoting of\ncleaner separation of concerns. It also facilitates independent testing of\nboth components, ensuring they can be assessed in isolation.<\/p>"},{"title":"DIY remote controlled pan & tilt CCTV using Raspberry Pi","link":"https:\/\/dhruvasagar.dev\/2018\/07\/06\/diy-remote-controlled-pan-tilt-cctv-using-raspberry-pi\/","pubDate":"Fri, 06 Jul 2018 16:59:10 +0000","guid":"https:\/\/dhruvasagar.dev\/2018\/07\/06\/diy-remote-controlled-pan-tilt-cctv-using-raspberry-pi\/","description":"<p><strong>RPi CCTV in Action<\/strong> :<\/p>\n\n\n\n\n<div class=\"video-container\">\n<iframe\nclass=\"video video--16x9\"\nsrc=\"https:\/\/www.youtube-nocookie.com\/embed\/5gEBrlaixCk?cc_load_policy=1&cc=1\" allowfullscreen title=\"RPi CCTV in Action\" frameborder=\"0\" sandbox=\"allow-same-origin allow-scripts\" loading=\"lazy\"><\/iframe>\n<\/div>\n\n<p><strong>A simple web interface to control the RPi CCTV<\/strong> :<\/p>\n\n\n\n\n<div class=\"video-container\">\n<iframe\nclass=\"video video--16x9\"\nsrc=\"https:\/\/www.youtube-nocookie.com\/embed\/1G8wricwkds?cc_load_policy=1&cc=1\" allowfullscreen title=\"A simple web interface to control the RPi CCTV\" frameborder=\"0\" sandbox=\"allow-same-origin allow-scripts\" loading=\"lazy\"><\/iframe>\n<\/div>\n\n<p><strong>What you need to build this (hardware)<\/strong> :<\/p>\n<ol>\n<li>Raspberry Pi<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>Preferably Raspberry Pi-3, for on-board wireless, or\nRaspberry Pi Zero W, although you can achieve similar result without much\neffort using other boards\n<\/span>\n<\/li>\n<li>Pan &amp; Tilt frame, I used one available here on amazon :\n<a href=\"https:\/\/www.amazon.in\/gp\/product\/B010M25JVU\/\" target=\"_blank\">https:\/\/www.amazon.in\/gp\/product\/B010M25JVU\/<\/a><\/li>\n<li>2 servo motors. I used sg90 micro servo motors since I had them handy,\nhowever you can also use other similar ones available<\/li>\n<\/ol>\n<p>I have recently started learning GoLang, and I decided to try to make use of\nit for a small IOT project that I&rsquo;ve been meaning to do for a long time. In my\nresearch I came across <a href=\"https:\/\/gobot.io\" target=\"_blank\">Gobot<\/a>, which is a framework for\nbuilding robots written in golang. It comes with support for a lot of\ndevelopment boards available in the market such as Raspberry Pi, Beaglebone,\nArduino, and several more. Not only that it also has drivers available for\na wide variety of devices which can be used to create all sorts of nifty\nrobots.<\/p>"},{"title":"SSH Config Trick","link":"https:\/\/dhruvasagar.dev\/2017\/10\/07\/ssh-config-trick\/","pubDate":"Fri, 06 Oct 2017 19:21:20 +0000","guid":"https:\/\/dhruvasagar.dev\/2017\/10\/07\/ssh-config-trick\/","description":"<blockquote>\n<p>Update2 : As I have been informed now, there has recently been support added\nfor including external files in the ssh config. Refer\n<a href=\"https:\/\/man.openbsd.org\/ssh_config#Include\" target=\"_blank\">https:\/\/man.openbsd.org\/ssh_config#Include<\/a>\nfor details.<\/p>\n<\/blockquote>\n<blockquote>\n<p>Update : Modified the script for more flexibility to allow easy modifications<\/p>\n<\/blockquote>\n<p>I use SSH nearly every day to securely connect to remote servers. For\nsimplifying managing remote server configurations &amp; not having to remember IP\naddresses and other server specific details, I use ssh config. For those who\naren\u2019t familiar with this should read \u2013 <a href=\"http:\/\/nerderati.com\/2011\/03\/17\/simplify-your-life-with-an-ssh-config-file\/\" target=\"_blank\">http:\/\/nerderati.com\/2011\/03\/17\/simplify-your-life-with-an-ssh-config-file\/<\/a><\/p>"},{"title":"Text Editor Choice & Peer Pressure","link":"https:\/\/dhruvasagar.dev\/2017\/03\/01\/text-editor-choice-peer-pressure\/","pubDate":"Wed, 01 Mar 2017 10:37:42 +0000","guid":"https:\/\/dhruvasagar.dev\/2017\/03\/01\/text-editor-choice-peer-pressure\/","description":"<p>I am a <a href=\"https:\/\/www.vim.org\" target=\"_blank\">VIM<\/a> user and have been for quite a long\ntime<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>~7 years\n<\/span>\n. I am both a vim plugin author and\nalso like to believe I have helped a lot of people switch \/ grok the core\nphilosophy that I believe distinguishes it from all other editors and gives it\nan edge (IMO).<\/p>\n<p>However, in this article I am not here to convince you to choose VIM as your\nchoice of text editor, on the contrary, I am going to suggest you to do the\nopposite, especially if the only motivation to do so is driven by some form of\npeer pressure.<\/p>"},{"title":"Template with Context using ERB","link":"https:\/\/dhruvasagar.dev\/2017\/02\/01\/template-context-using-erb\/","pubDate":"Wed, 01 Feb 2017 12:15:49 +0000","guid":"https:\/\/dhruvasagar.dev\/2017\/02\/01\/template-context-using-erb\/","description":"<p>Recently, I was required to build a template rendering component that should\nrender within a dynamic context, i.e. it would have methods \/ variables\ndefined within a predefined context available during rendering, apart from\nwhat was provided directly.<\/p>\n<p>For simplicity we chose <a href=\"http:\/\/www.stuartellis.name\/articles\/erb\/\" target=\"_blank\">ERB<\/a>,\nsince we can place them within locale files for internationalisation and\ndesigners could edit them with ease if need arises.<\/p>\n<p>Following is a very simple implementation. Since we extend <code>OpenStruct<\/code> we\ncan simply pass a hash to it during instantiation and all the keys will be\naccessible as methods and will be exposed directly during rendering.<\/p>"},{"title":"Slack old school style","link":"https:\/\/dhruvasagar.dev\/2016\/11\/13\/slack-old-school-style\/","pubDate":"Sun, 13 Nov 2016 12:27:39 +0000","guid":"https:\/\/dhruvasagar.dev\/2016\/11\/13\/slack-old-school-style\/","description":"<p><a href=\"http:\/\/slack.com\" target=\"_blank\">Slack<\/a> has gained a lot of popularity in recent times as\na tool for inter-team communication and for the right reasons. It offers a lot\nof features such as 3rd party software integrations, rich content\ncommunication, collaboration, bots etc. which when put together help create\na rich collaborative user experience for teams to work together, especially\nwhen they are not co-located, which is fairly common these days.<\/p>\n<p>If you&rsquo;re anything like me and have been around long enough to know what\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Internet_Relay_Chat\" target=\"_blank\">IRC<\/a> is and when you look\nat various elements that slack provides like channels, accounts (servers),\nprivate messaging, etc. you know that it draws a lot of parallels and\ninspiration from that old school communication tool.<\/p>"},{"title":"WebRTC Broadcast","link":"https:\/\/dhruvasagar.dev\/2016\/11\/02\/webrtc-broadcast\/","pubDate":"Wed, 02 Nov 2016 12:52:30 +0000","guid":"https:\/\/dhruvasagar.dev\/2016\/11\/02\/webrtc-broadcast\/","description":"<p>WebRTC is fun! I recently gave a quick session on WebRTC at Bangalore Ruby\nUser Group (BRUG). Following are the slides of my presentation.<\/p>\n<iframe\n  style=\"width: 100%; height: 500px;\"\n  frameborder=\"0\"\n  marginwidth=\"0\"\n  marginheight=\"0\"\n  scrolling=\"no\"\n  src=\"https:\/\/www.slideshare.net\/slideshow\/embed_code\/key\/3n2wUUKX2yV3EJ?startSlide=1\"\n  allowfullscreen\n  webkitallowfullscreen\n  mozallowfullscreen>\n<\/iframe>\n<div style=\"margin-bottom: 5px;text-align: center;\">\n  <strong>\n    <a\n        href=\"https:\/\/www.slideshare.net\/dhruvasagar\/webrtc-67392562\"\n        title=\"WebRTC\"\n        target=\"_blank\">\n      WebRTC\n    <\/a>\n  <\/strong> from <strong>\n    <a href=\"https:\/\/www.slideshare.net\/dhruvasagar\" target=\"_blank\">\n      Dhruva Sagar\n    <\/a>\n  <\/strong>\n<\/div>\n\n<p>For demo I had recently created a demo application in elixir using the phoenix\nframework because it makes dealing with websockets really easy. That is used\nfor creating the custom signaling service that is required to facilitate such\na broadcast. The source code is available at <a href=\"https:\/\/github.com\/dhruvasagar\/webrtc-broadcast\" target=\"_blank\">dhruvasagar\/webrtc-broadcast<\/a><\/p>"},{"title":"Pristine \u2013 ZSH Theme","link":"https:\/\/dhruvasagar.dev\/2015\/11\/28\/pristine-zsh-theme\/","pubDate":"Sat, 28 Nov 2015 06:24:13 +0000","guid":"https:\/\/dhruvasagar.dev\/2015\/11\/28\/pristine-zsh-theme\/","description":"<p>A while back I posted about <a href=\"https:\/\/dhruvasagar.dev\/2013\/03\/13\/amuse-zsh-theme\">Amuse<\/a> my prompt theme for ZSH targeting\n<code>oh-my-zsh<\/code>. Since this was a much appreciated theme, I would like to share\nanother theme, Pristine, that I have created.<\/p>\n<p>However, I recently switched to using\n<a href=\"https:\/\/github.com\/sorin-ionescu\/prezto\" target=\"_blank\">Prezto<\/a>. This is because it felt\nlike a more minimalistic configuration framework for ZSH. I also wanted to get\nfaster load times. I must say my experience has been quite good and I really\nlike it. Obviously there are pros and cons but I digress.<\/p>"},{"title":"Google open sources it\u2019s machine learning system","link":"https:\/\/dhruvasagar.dev\/2015\/11\/10\/google-open-sources-its-machine-learning-system\/","pubDate":"Mon, 09 Nov 2015 19:46:28 +0000","guid":"https:\/\/dhruvasagar.dev\/2015\/11\/10\/google-open-sources-its-machine-learning-system\/","description":"<p>I am a huge proponent of open source technologies and having worked\npredominantly in various web technologies in the course of my career, I mostly\nwork exclusively with open source stacks.<\/p>\n<p>In the recent past I have been very keen to try and wrap my head around\nArtificial Intelligence and more specifically Machine Learning, although I am\nstill barely even scratching the surface of the nitty-gritty\u2019s of the\nfield, especially the mathematical underpinnings, this is still a huge deal!<\/p>"},{"title":"Grow your brain!","link":"https:\/\/dhruvasagar.dev\/2015\/11\/09\/grow-your-brain\/","pubDate":"Mon, 09 Nov 2015 14:27:20 +0000","guid":"https:\/\/dhruvasagar.dev\/2015\/11\/09\/grow-your-brain\/","description":"<p>Learning is key in brain development. Of course what aspects and how much of\nbrain function improve as a result depends on the mode \/ type \/ content\n&amp; method of learning. But I am not here to talk about that. Now, this\nknowledge isn&rsquo;t new information, we all know this already, and have seen\nit in good effect in children and hence we all know and understand the\nimportance of education &amp; sport for children.<\/p>"},{"title":"Find huge files in linux","link":"https:\/\/dhruvasagar.dev\/2015\/05\/08\/find-huge-files-in-linux\/","pubDate":"Fri, 08 May 2015 04:17:01 +0000","guid":"https:\/\/dhruvasagar.dev\/2015\/05\/08\/find-huge-files-in-linux\/","description":"<p>Switching to SSD&rsquo;s for better performance and compromising on disk space can\nbe a tough decision to make. Though nowadays with the prices of SSD&rsquo;s going\ndown, it is something that a lot of people are consciously doing.<\/p>\n<p>However <label for=\"marginnote-1\" class=\"margin-toggle marginnote-ind\"><\/label>\n<input type=\"checkbox\" id=\"marginnote-1\" class=\"margin-toggle\"\/>\n<span class=\"marginnote\">\nhaving spoilt by past experiences of having ample disk\nspace\n<\/span>\n when you switch from a 500GB (or 1TB) hard disk to an,\nalbeit super fast, 128GB SSD, you will inevitably run into situations where\nyou need to clean out large files taking space on your disk. Something I had\nrun into myself about a year back when I made the switch myself on my macbook.\nOddly enough this problem turned out to be significant enough that I had to\nseek out a way to quickly find out which were the top biggest files on my file\nsystem so I could get rid of them \/ move to an external hard disk.<\/p>"},{"title":"Google Code Jam 2014 Qualifiers","link":"https:\/\/dhruvasagar.dev\/2014\/04\/14\/google-code-jam-2014-qualifiers\/","pubDate":"Mon, 14 Apr 2014 08:55:35 +0000","guid":"https:\/\/dhruvasagar.dev\/2014\/04\/14\/google-code-jam-2014-qualifiers\/","description":"<p>Google Code Jam has always been a competition I have cherished, simply because\nthe problems they post are brilliant and the closest to reality as compared to\nproblems of other competitions. They&rsquo;re always fun to read, disect &amp; solve,\nmore often than not, the solutions are reasonably\ntrivial<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>Especially for the qualifiers\n<\/span>\n yet\nextremely subtle &amp; deceptive.<\/p>\n<p>Today I want to share the solutions of 3 problems I was able to solve, the\ncode should pretty much speak for itself because none of it is very complex.<\/p>"},{"title":"VIM Custom TabLine","link":"https:\/\/dhruvasagar.dev\/2014\/04\/06\/vim-custom-tabline\/","pubDate":"Sat, 05 Apr 2014 18:40:01 +0000","guid":"https:\/\/dhruvasagar.dev\/2014\/04\/06\/vim-custom-tabline\/","description":"<p>Hi guys,<\/p>\n<p>VIM has an option <code>tabline<\/code> that one can use to configure how the tab line\nwould look like. Back when I used to use gvim, I could very easily manipulate\nhow the text on the tab looked like by setting the <code>guitablabel<\/code> setting,\nhowever <code>tabline<\/code> is not all that easy to configure.<\/p>\n<p>Here is what I use now :<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-vim\" data-lang=\"vim\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">function<\/span><span class=\"p\">!<\/span> <span class=\"nx\">MyTabLine<\/span><span class=\"p\">()<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> <span class=\"p\">=<\/span> <span class=\"s1\">&#39;&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"nx\">for<\/span> <span class=\"nx\">i<\/span> <span class=\"nx\">in<\/span> <span class=\"nx\">range<\/span><span class=\"p\">(<\/span><span class=\"nx\">tabpagenr<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;$&#39;<\/span><span class=\"p\">))<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">tabnr<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">i<\/span> <span class=\"p\">+<\/span> <span class=\"m\">1<\/span> <span class=\"c\">&#34; range() starts at 0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">winnr<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">tabpagewinnr<\/span><span class=\"p\">(<\/span><span class=\"nx\">tabnr<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">buflist<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">tabpagebuflist<\/span><span class=\"p\">(<\/span><span class=\"nx\">tabnr<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">bufnr<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">buflist<\/span>[<span class=\"nx\">winnr<\/span> <span class=\"p\">-<\/span> <span class=\"m\">1<\/span>]\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">bufname<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">fnamemodify<\/span><span class=\"p\">(<\/span><span class=\"nx\">bufname<\/span><span class=\"p\">(<\/span><span class=\"nx\">bufnr<\/span><span class=\"p\">),<\/span> <span class=\"s1\">&#39;:t&#39;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"s1\">&#39;%&#39;<\/span> . <span class=\"nx\">tabnr<\/span> . <span class=\"s1\">&#39;T&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"p\">(<\/span><span class=\"nx\">tabnr<\/span> <span class=\"p\">==<\/span> <span class=\"nx\">tabpagenr<\/span><span class=\"p\">()<\/span> ? <span class=\"s1\">&#39;%#TabLineSel#&#39;<\/span> : <span class=\"s1\">&#39;%#TabLine#&#39;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"s1\">&#39; &#39;<\/span> . <span class=\"nx\">tabnr<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">n<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">tabpagewinnr<\/span><span class=\"p\">(<\/span><span class=\"nx\">tabnr<\/span><span class=\"p\">,<\/span><span class=\"s1\">&#39;$&#39;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">if<\/span> <span class=\"nx\">n<\/span> <span class=\"p\">&gt;<\/span> <span class=\"m\">1<\/span> <span class=\"p\">|<\/span> <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"s1\">&#39;:&#39;<\/span> . <span class=\"nx\">n<\/span> <span class=\"p\">|<\/span> <span class=\"k\">endif<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"nx\">empty<\/span><span class=\"p\">(<\/span><span class=\"nx\">bufname<\/span><span class=\"p\">)<\/span> ? <span class=\"s1\">&#39; [No Name] &#39;<\/span> : <span class=\"s1\">&#39; &#39;<\/span> . <span class=\"nx\">bufname<\/span> . <span class=\"s1\">&#39; &#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">let<\/span> <span class=\"nx\">bufmodified<\/span> <span class=\"p\">=<\/span> <span class=\"nx\">getbufvar<\/span><span class=\"p\">(<\/span><span class=\"nx\">bufnr<\/span><span class=\"p\">,<\/span> <span class=\"s2\">&#34;&amp;mod&#34;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">if<\/span> <span class=\"nx\">bufmodified<\/span> <span class=\"p\">|<\/span> <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"s1\">&#39;+ &#39;<\/span> <span class=\"p\">|<\/span> <span class=\"k\">endif<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"nx\">endfor<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">let<\/span> <span class=\"nx\">s<\/span> .<span class=\"p\">=<\/span> <span class=\"s1\">&#39;%#TabLineFill#&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"nx\">return<\/span> <span class=\"nx\">s<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">endfunction<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">set<\/span> <span class=\"nx\">tabline<\/span><span class=\"p\">=<\/span>%<span class=\"p\">!<\/span><span class=\"nx\">MyTabLine<\/span><span class=\"p\">()<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>This is what it looks like :<\/p>"},{"title":"Creating Custom Scratch Buffers in VIM","link":"https:\/\/dhruvasagar.dev\/2014\/03\/11\/creating-custom-scratch-buffers-in-vim\/","pubDate":"Tue, 11 Mar 2014 09:07:22 +0000","guid":"https:\/\/dhruvasagar.dev\/2014\/03\/11\/creating-custom-scratch-buffers-in-vim\/","description":"<p>The other day I wanted to open a scratch buffer to write some temporary code\nand the pass it on to a repl to test it out, the idea was that I could modify\nit as needed and resend it back to the repl and see the changes, helps to\ndebug easily.<\/p>\n<p>So I just wrote out this simple code here that allows me to launch a scratch\nbuffer in different ways, but the difference is I can set various options for\nit while creating it. First lets have a look at the code :<\/p>"},{"title":"VIM \u2013 Filter Quickfix List","link":"https:\/\/dhruvasagar.dev\/2013\/12\/17\/vim-filter-quickfix-list\/","pubDate":"Tue, 17 Dec 2013 10:15:07 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/12\/17\/vim-filter-quickfix-list\/","description":"<p>If you are used to using the quickfix list in VIM there are times when you\nwant to filter certain things out of the quickfix list to narrow it down to\nrelevant results that you need. Rather than firing the quickfix command all\nover again with a refined expression, it is easier &amp; often faster to simply\nremove items from the list. I wrote this simple vimscript to do just that.<\/p>"},{"title":"VIM \u2013 Toggle Ruby Hash Syntax","link":"https:\/\/dhruvasagar.dev\/2013\/11\/26\/vim-toggle-ruby-hash-syntax\/","pubDate":"Tue, 26 Nov 2013 15:05:55 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/11\/26\/vim-toggle-ruby-hash-syntax\/","description":"<p>Ruby 1.9 introduced a new json style ruby hash syntax. Although we can use\nthis to define static hash objects and puts a limitation on the key we can\nuse, it&rsquo;s a fairly neat syntax nevertheless. However I work on several\nprojects, both new and old and hence the new syntax is not always readily\navailable.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Old style hash<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">hash<\/span> <span class=\"o\">=<\/span> <span class=\"p\">{<\/span> <span class=\"ss\">:a<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"s1\">&#39;test&#39;<\/span> <span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># New style hash<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">hash<\/span> <span class=\"o\">=<\/span> <span class=\"p\">{<\/span> <span class=\"ss\">a<\/span><span class=\"p\">:<\/span> <span class=\"s1\">&#39;test&#39;<\/span> <span class=\"p\">}<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>To demonstrate the sheer power of regular expressions &amp; VIM, here&rsquo;s\na tiny snippet that allows you to quickly toggle a ruby hash syntax from one\nform to other.<\/p>"},{"title":"VIM for Multiple Projects in separate Tmux windows","link":"https:\/\/dhruvasagar.dev\/2013\/11\/26\/vim-for-multiple-projects-in-tmux-windows\/","pubDate":"Tue, 26 Nov 2013 05:20:57 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/11\/26\/vim-for-multiple-projects-in-tmux-windows\/","description":"<p>My development environment setup consists of several tools, however the 2 most\nused and essential tools that have a great impact on my workflow are <code>tmux<\/code>\n&amp; <code>vim<\/code>. Since I often work on several projects, I find it best to work on\ndifferent vim sessions in separate tmux windows.<\/p>\n<p>However tmux by default only shows the name of the currently running process\nin the title and that can often lead to confusion as to which tmux window is\nwhich project. To solve this issue I came up with a very simple vim script\nthat utilizes tmux&rsquo;s powerful API to automatically rename the tmux\nwindow appropriately and hence make it incredibly easy for me to know which\ntmux window is for which project.<\/p>"},{"title":"ActiveRecord like where for array of hashes in ruby","link":"https:\/\/dhruvasagar.dev\/2013\/04\/20\/activerecord-like-where-for-array-of-hashes-in-ruby\/","pubDate":"Sat, 20 Apr 2013 05:36:35 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/04\/20\/activerecord-like-where-for-array-of-hashes-in-ruby\/","description":"<blockquote>\n<p>Edit : Updated the code as per the suggestions made by Masklinn.<\/p>\n<\/blockquote>\n<p>Recently I was working on\n<a href=\"https:\/\/github.com\/dhruvasagar\/soulmate_rails\/issues\/1\" target=\"_blank\">Issue#1<\/a> of my\n<a href=\"https:\/\/github.com\/dhruvasagar\/soulmate_rails\" target=\"_blank\">Soulmate Rails<\/a> gem, which is\na very simple and obvious optimization that I should have thought of myself.\nThanks to <a href=\"https:\/\/github.com\/lephyrius\" target=\"_blank\">lephyrius<\/a> though for pointing it\nout. In my search method I was looping through the search results and calling\nfind on each to get it from db. The fix involved to instead use a single where\nfor all ids so that it translates to a single db call. A simple fix as well as\nan optimization.<\/p>"},{"title":"VIM Markify","link":"https:\/\/dhruvasagar.dev\/2013\/04\/01\/vim-markify\/","pubDate":"Mon, 01 Apr 2013 13:06:29 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/04\/01\/vim-markify\/","description":"<p>Recently I picked up some minor configs for ruby from <a href=\"http:\/\/tpo.pe\" target=\"_blank\">Time\nPope&rsquo;s<\/a>\n<a href=\"https:\/\/github.com\/tpope\/tpope\/blob\/master\/.vimrc#L505\" target=\"_blank\">vimrc<\/a>. Here&rsquo;s the\ncode :<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-vim\" data-lang=\"vim\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">autocmd<\/span> <span class=\"nx\">FileType<\/span> <span class=\"nx\">ruby<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\ <span class=\"k\">if<\/span> <span class=\"nx\">expand<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;%&#39;<\/span><span class=\"p\">)<\/span> <span class=\"p\">=~<\/span># <span class=\"s1\">&#39;_test\\.rb$&#39;<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\   <span class=\"nx\">compiler<\/span> <span class=\"nx\">rubyunit<\/span> <span class=\"p\">|<\/span> <span class=\"nx\">setl<\/span> <span class=\"nx\">makeprg<\/span><span class=\"p\">=<\/span><span class=\"nx\">testrb<\/span>\\ \\<span class=\"s2\">&#34;%:p\\&#34;<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\ <span class=\"k\">elseif<\/span> <span class=\"nx\">expand<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;%&#39;<\/span><span class=\"p\">)<\/span> <span class=\"p\">=~<\/span># <span class=\"s1\">&#39;_spec\\.rb$&#39;<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\   <span class=\"nx\">compiler<\/span> <span class=\"nx\">rspec<\/span> <span class=\"p\">|<\/span> <span class=\"nx\">setl<\/span> <span class=\"nx\">makeprg<\/span><span class=\"p\">=<\/span><span class=\"nx\">rspec<\/span>\\ \\<span class=\"s2\">&#34;%:p\\&#34;<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\ <span class=\"k\">else<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\   <span class=\"nx\">compiler<\/span> <span class=\"nx\">ruby<\/span> <span class=\"p\">|<\/span> <span class=\"nx\">setl<\/span> <span class=\"nx\">makeprg<\/span><span class=\"p\">=<\/span><span class=\"nx\">ruby<\/span>\\ <span class=\"p\">-<\/span><span class=\"nx\">wc<\/span>\\ \\<span class=\"s2\">&#34;%:p\\&#34;<\/span> <span class=\"p\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    \\ <span class=\"k\">endif<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>What this does is given the filetype is Ruby, it correctly sets up the\ncompiler and makeprg such that it allows you to run your tests via <code>:make!<\/code>\nThis is pretty neat I must say :), because it correctly loads the quickfix\nlist with the errors and I can actually traverse them in order and fix them.\nAll this without needing any plugin whatsoever :).<\/p>"},{"title":"VIM Better FoldText","link":"https:\/\/dhruvasagar.dev\/2013\/03\/28\/vim-better-foldtext\/","pubDate":"Thu, 28 Mar 2013 18:00:54 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/03\/28\/vim-better-foldtext\/","description":"<blockquote>\n<p><strong>Update 3<\/strong>: Improved the code for extraction of fillchar from <code>fillchars<\/code>\noption and taking <code>foldcolumn<\/code> into account.<\/p>\n<\/blockquote>\n<blockquote>\n<p><strong>Update 2<\/strong>: Fixed the regex for removing the fold marker from the\ndisplayed text by splitting the <code>'{{{'<\/code> in the regex to\n<code>'{{'. '{'<\/code> so that it is not treated as a fold marker\nby vim. Thanks to <a href=\"http:\/\/www.reddit.com\/user\/Amadan\" target=\"_blank\">Amadan<\/a> on reddit\n<a href=\"http:\/\/www.reddit.com\/r\/vim\/comments\/1b6viw\/vim_better_foldtext\/c94it43\" target=\"_blank\">Reddit\nTip<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<p><strong>Update<\/strong>: Fixed <code>NeatFoldText()<\/code> to get <code>foldchar<\/code> from <code>fillchars<\/code>\nsettings.<\/p>\n<\/blockquote>\n<p>Initially when I started using VIM, I had borrowed configs from my mentor\n<a href=\"http:\/\/vagmim.in\/\" target=\"_blank\">Vagmi Mudumbai<\/a> <label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>To whom I am Eternally\nThankful!!!\n<\/span>\n.<\/p>"},{"title":"VIM Table Mode","link":"https:\/\/dhruvasagar.dev\/2013\/03\/17\/vim-table-mode\/","pubDate":"Sun, 17 Mar 2013 07:20:15 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/03\/17\/vim-table-mode\/","description":"<blockquote>\n<p>UPDATE 2: Released v 2.0 of the plugin. Check github for details.<\/p>\n<\/blockquote>\n<blockquote>\n<p>UPDATE : I have added more features to the original plugin, showcasing some\ncore features in a new demo (Part 2).<\/p>\n<\/blockquote>\n<p>Recently a friend of mine showed off emacs table mode to me and to be honest,\nI felt a bit jealous :). Hence I began to search for existing vim plugins that\nmight offer a similar functionality and I did find a plugin <a href=\"https:\/\/github.com\/nvie\/vim-rst-tables\" target=\"_blank\">VIM RST\nTables<\/a>, which is a ftplugin that aids\nthe creation of tables within rst files and allows you to format existing\ncontent into a table, although this plugin came closest to what I was looking\nfor it wasn&rsquo;t quite there. Then I found a very interesting &amp; simple plugin\nshared as a gist by the infamous <a href=\"http:\/\/tpo.pe\" target=\"_blank\">Tim Pope<\/a>:\n<a href=\"https:\/\/gist.github.com\/tpope\/287147\" target=\"_blank\">cucumbertables.vim<\/a> which I found quite\nimpressive.<\/p>"},{"title":"Amuse \u2013 ZSH Theme","link":"https:\/\/dhruvasagar.dev\/2013\/03\/13\/amuse-zsh-theme\/","pubDate":"Wed, 13 Mar 2013 11:12:50 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/03\/13\/amuse-zsh-theme\/","description":"<p>Amuse is a simplistic theme I built for the popular shell ZSH that I use.<\/p>\n<p>Features :<\/p>\n<ol>\n<li>Shows git prompt with additional support for dirty (! in red) and untracked\n(? in green) git flags.<\/li>\n<li>Shows the system time with a neat time unicode character. Although I am\nsure most wouldn&rsquo;t find having time on the prompt useful, I find it\nvery useful since it helps me get a good idea on how long a command took to\nexecute or even how long back I executed some command. Check the screenshot\nfor reference.<\/li>\n<li>Prompt where you type the command starts after a $ on a new line giving you\nample space (full width barring the $ and a space) to type your command and\nso the prompt (especially if it\u2019s long, eg. if you are in some deep\nnested directory) does not interfere with your commands and avoids wrapping\nfor the most part unless you are typing an excessively long command in which\ncase you should probably use an editor (<a href=\"https:\/\/dhruvasagar.dev\/2012\/08\/24\/vim-in-my-muscle-memory\" title=\"VIM in my muscle memory\">VIM<\/a>) to edit it with\n<kbd>^X^E<\/kbd>\n.<\/li>\n<li>Shows you the current ruby version in use from rvm, using the <code>rvm current<\/code>\ncommand in the right prompt. The ZSH right prompt is really\ncool and since I use rvm with several ruby versions which change with\ndifferent projects .rvmrc files, the right prompt helps me to know the ruby\ncontext at all times. It shows the full ruby version along with the gemset\nname in use. The nice thing about the right prompt in ZSH is that it hides\nautomatically if you happen to type a command that&rsquo;s long enough to\nreach it :).<\/li>\n<\/ol>\n<blockquote>\n<p><strong>UPDATE<\/strong>: My AMUSE theme for <a href=\"https:\/\/github.com\/robbyrussell\/oh-my-zsh\" target=\"_blank\">Oh My\nZsh<\/a> was merged into the\nrepository so you don&rsquo;t need my fork anymore which has since been deleted.<\/p>"},{"title":"Vim Railscasts Colorscheme","link":"https:\/\/dhruvasagar.dev\/2013\/03\/08\/vim-railscasts-colorscheme\/","pubDate":"Fri, 08 Mar 2013 08:03:00 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/03\/08\/vim-railscasts-colorscheme\/","description":"<p><a href=\"https:\/\/dhruvasagar.dev\/2012\/08\/24\/vim-in-my-muscle-memory\" title=\"VIM in my muscle memory\">VIM in my muscle memory<\/a>\u00a0is one of my popular posts, the day I published\nit, I attracted over 3,200 unique views in a single day, mostly from <a href=\"http:\/\/news.ycombinator.com\/\" target=\"_blank\">Hacker\nNews<\/a> and <a href=\"http:\/\/www.reddit.com\/r\/programming\" target=\"_blank\">Reddit\nProgramming<\/a>. Although it is an extremely\ndensely packed post with lots of information, I hope it has helped some to\nappreciate <a href=\"http:\/\/www.vim.org\/\" target=\"_blank\">VIM<\/a> like I do.<\/p>\n<p>In my several years of VIM usage, I have tried several colorscheme\u2019s, though\nI have come to like only a select few. One colorscheme that I have liked the\nmost and have always ended up coming back to is the Railscasts theme. There\nare 2 versions of this script :<\/p>"},{"title":"Soulmate Rails","link":"https:\/\/dhruvasagar.dev\/2013\/03\/04\/soulmate-rails\/","pubDate":"Mon, 04 Mar 2013 08:11:28 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/03\/04\/soulmate-rails\/","description":"<blockquote>\n<p>UPDATE : I released the first stable version 0.2.1, it should be usable as\nis without any issues.<\/p>\n<\/blockquote>\n<p>One of the most common things to do in any standard rails web applications is\nauto-completion. One interesting solution for this is by using redis\u2019 sorted\nsets <label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>Which are blazing fast\n<\/span>\n, storing key value\npairs for partial matches. For example, if we wish to index the word \u2018Dhruva\nSagar\u2019, you can simply create key -&gt; value pairs of \u2018d\u2019 -&gt; \u2018Dhruva Sagar\u2019,\n\u2018dh\u2019 -&gt; \u2018Dhruva Sagar\u2019, \u2018dhr\u2019 -&gt; \u2018Dhruva Sagar\u2019 and so on. Since hash lookups\nare of constant time complexity O(1), they\u2019re very fast and hence the\ncompletions are too! Combine this with using sorted sets of redis to easily\norder \/ sort information on a specific criteria and you have a blazing fast\nsolution. Of course the actual implementation can be further optimized by\nmeans of caching query results and make the system perform even further.<\/p>"},{"title":"Tmux Powerline Special Characters Issue","link":"https:\/\/dhruvasagar.dev\/2013\/02\/23\/tmux-powerline-special-characters-issue\/","pubDate":"Sat, 23 Feb 2013 07:16:45 +0000","guid":"https:\/\/dhruvasagar.dev\/2013\/02\/23\/tmux-powerline-special-characters-issue\/","description":"<p><a href=\"http:\/\/tmux.sourceforge.net\/\" target=\"_blank\">Tmux<\/a> is a terminal multiplexer like\n<a href=\"http:\/\/www.gnu.org\/software\/screen\/\" target=\"_blank\">Screen<\/a> on steroids. It is faster,\nslicker and much more easily extendable than screen. For why you might want to\ntry tmux over screen checkout these articles :<\/p>\n<ul>\n<li><a href=\"http:\/\/dominik.honnef.co\/posts\/2010\/10\/why_you_should_try_tmux_instead_of_screen\/\" target=\"_blank\">Why you should try Tmux instead of Screen<\/a><\/li>\n<li><a href=\"https:\/\/www.wikivs.com\/wiki\/Screen_vs_tmux\" target=\"_blank\">Screen Vs Tmux<\/a><\/li>\n<\/ul>\n<p>Tmux Powerline is an extension to tmux&rsquo;s statusline which makes it look\nincredibly cool. Look at this screenshot:<\/p>\n\n\n    <figure class=\"fullwidth\">\n  \n  \n  <img src=\"https:\/\/dhruvasagar.dev\/wp-content\/uploads\/2013\/02\/Screenshot-from-2013-02-23-122131.png\" alt=\"Image\">\n  \n  <figcaption>\n\n<strong>Tmux Powerline. <\/strong>\n\n\n\n\n\n  <\/figcaption>\n\n\n\n\n\n\n<\/figure>\n\n\n<p>There are 2 projects that provide this feature.<\/p>"},{"title":"Ubuntu on Macbook Pro","link":"https:\/\/dhruvasagar.dev\/2012\/12\/28\/ubuntu-on-macbook-pro\/","pubDate":"Fri, 28 Dec 2012 11:02:32 +0000","guid":"https:\/\/dhruvasagar.dev\/2012\/12\/28\/ubuntu-on-macbook-pro\/","description":"<p>As I have mentioned before ([Magician Chrome makes RAM disappear][1]), I had\nbeen facing several issues with Mac OSX. I use vim extensively, and so I had\ninstalled <a href=\"http:\/\/macvim.org\/\" target=\"_blank\">MacVim<\/a><label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>after great\ndifficulty\n<\/span>\n on my Macbook Pro, but recently while trying out\na new plugin I found there was something amiss between MacVim &amp; Python on my\nsystem and as a result I was unable to use the plugin. In my attempt at trying\nto repair MacVim, I ended up uninstalling it.<\/p>"},{"title":"Magician Chrome makes RAM disappear","link":"https:\/\/dhruvasagar.dev\/2012\/08\/28\/magician-chrome-makes-ram-disappear\/","pubDate":"Tue, 28 Aug 2012 08:47:19 +0000","guid":"https:\/\/dhruvasagar.dev\/2012\/08\/28\/magician-chrome-makes-ram-disappear\/","description":"<p>Recently I have been experiencing a very weird issue on my Macbook Pro, I have\nLion v10.7.4, with a decent configuration : 2.8 GHz Intel Core i7 processor,\n8GB Ram with a 750GB sata hard disk. But over a reasonably prolonged period of\nusage, of around 4-6 hours, I notice from time to time that Mac OSX runs\ncompletely out of RAM! The Activity Monitor reports mere MBs of Free Memory,\nsometimes even less than 10MB. Needless to say this makes the Macbook loose\nit&rsquo;s mind, it would freeze up on random, seemingly basic tasks, even switching\nto a window can freeze the macbook for minutes, if not hours. Which is\nunderstandable, though, given how low memory it is left with.<\/p>"},{"title":"VIM in my muscle memory","link":"https:\/\/dhruvasagar.dev\/2012\/08\/24\/vim-in-my-muscle-memory\/","pubDate":"Fri, 24 Aug 2012 17:59:45 +0000","guid":"https:\/\/dhruvasagar.dev\/2012\/08\/24\/vim-in-my-muscle-memory\/","description":"<p>I have been an ardent VIM user for almost 4 years now, and it&rsquo;s been\na while since I have been wanting to write this Blog. My motivation is not to\nshowoff or to start any flame war against any other popular text editors that\nmay or <strong>may not<\/strong> be better ;), but to simply showcase the things I like and\nhave come to appreciate in VIM, and show why you should seriously consider it\nwhen deciding which programming editor you should use. Hopefully I will be\nable to do justice to VIM - the <strong>Ultimate Programmer&rsquo;s Editor<\/strong>.<\/p>"},{"title":"Artificially Intelligent Spyware","link":"https:\/\/dhruvasagar.dev\/2012\/08\/21\/artificially-intelligent-spyware\/","pubDate":"Tue, 21 Aug 2012 09:58:49 +0000","guid":"https:\/\/dhruvasagar.dev\/2012\/08\/21\/artificially-intelligent-spyware\/","description":"<p>There has been tremendous advancement in the domain of Artificial Intelligence\n(AI) and Machine Learning (ML) in the recent years. Although people often like\nto take a shot at the state of AI on the grounds of the fact that several of\nthe early claims on AI that it will soon become almost as real as humans\nhaven&rsquo;t really materialized, there still has been an incredible amount\nof growth in this domain.<\/p>"},{"title":"Getting started with Ruby \u2013 TOC","link":"https:\/\/dhruvasagar.dev\/2010\/12\/24\/getting-started-with-ruby-toc\/","pubDate":"Fri, 24 Dec 2010 18:29:47 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/12\/24\/getting-started-with-ruby-toc\/","description":"<p>Hi,<\/p>\n<p>I have written a series of articles (in several parts) in an attempt to guide\nbeginners to get comfortable with Ruby. This article is my attempt to build\na TOC (Table of Contents) for it to act as an index for people to get a brief\nidea regarding what each article is about and help them get to the sections\nthey are interested in.<\/p>\n<ul>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part1\/\" title=\"Getting started with Ruby - Part 1\">Getting started with Ruby - Part 1<\/a>: In this article I begin with an\nintroduction to myself and my motivation behind writing these articles. I give\nan introduction to Ruby, about how to get started with building your\ndevelopment environment and introduce a few tools that ship along with Ruby\nwhich will make your life that much better.<\/li>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part2\/\" title=\"Getting started with Ruby - Part 2\">Getting started with Ruby - Part 2<\/a>: In this article I introduce Ruby in\nslightly more detail and I get started with describing different data types in\nRuby. I cover Strings and Numbers in this article.<\/li>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/21\/getting-started-with-ruby-part3\/\" title=\"Getting started with Ruby - Part 3\">Getting started with Ruby - Part 3<\/a>: In this article I continue from my\nprevious article describing data types in Ruby and cover Ranges and Arrays.<\/li>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/23\/getting-started-with-ruby-part4\/\" title=\"Getting started with Ruby - Part 4\">Getting started with Ruby - Part 4<\/a>: In this article I continue further\nand cover Hashes, one of the most commonly used data types in Ruby. I also\nintroduce blocks and about using blocks with functions.<\/li>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/26\/getting-started-with-ruby-part5\/\" title=\"Getting started with Ruby - Part 5\">Getting started with Ruby - Part 5<\/a>: In this article I move onto\ndescribing various looping constructs in Ruby, and also various flow control\nmodifiers in Ruby. After that I introduce Variables, Symbols, Constants,\nMethods and Global Variables in Ruby.<\/li>\n<li><a href=\"https:\/\/dhruvasagar.dev\/2010\/11\/03\/getting-started-with-ruby-part6\/\" title=\"Getting started with Ruby - Part 6\">Getting started with Ruby - Part 6<\/a>: After having covered basics of\nvarious constructs in Ruby, I considered it better to take a problem statement\nand solve it in Ruby to bring most of what we\u2019ve discussed into use. I chose\nGoogle Codejam 2009\u2032s qualification round problem \u2013\u00a0<a href=\"http:\/\/code.google.com\/codejam\/contest\/dashboard?c=90101\" target=\"_blank\">Alien Language<\/a><\/li>\n<\/ul>\n<p>I tried to be clear, precise and specific. My intention was write more code\nthan to waste time in trying to explain and so I\u2019ve used code comments to help\npeople understand what each part of the code is meant to do. I have plans on\ngoing further and go onto describing classes &amp; modules, sometime soon, even\nthough I expected more people to read and give their feedback, but owing to\na lot of work and hence a lack of time, I haven\u2019t been able to do much justice\nto the same, but hopefully I will be able to do so very soon. I hope it helps\npeople appreciate Ruby and motivate them to learn and understand it.<\/p>"},{"title":"MongoMapper Plugin \u2013 Versionable","link":"https:\/\/dhruvasagar.dev\/2010\/12\/02\/mongomapper-plugin-versionable\/","pubDate":"Thu, 02 Dec 2010 03:53:38 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/12\/02\/mongomapper-plugin-versionable\/","description":"<p>There was a requirement at one of our projects here at <a href=\"http:\/\/web.archive.org\/web\/20110917020206\/http:\/\/www.artha42.com\/\" title=\"Artha42 Innovations Private Limited\" target=\"_blank\">Artha42 Innovations\nPrivate Limited<\/a> that our Mongo Mapper documents have inherent versioning\nso as to be able to track the changes being made and also if required revert\nthe changes to a previous state. Since we\u2019re using MongoMapper, I set out to\ncreate a simple plugin for the same to add the required functionality.<\/p>\n<p>Initially, from the initial research I did, I found <a href=\"http:\/\/shapado.com\/\" title=\"Shapado\" target=\"_blank\">Shapado<\/a> had an\nimplementation of exactly what I wanted, however when I studied and understood\ntheir implementation in detail, I realized that it doesn\u2019t really work that\nwell in most scenarios, especially the ones we were tackling in our project.\nShapado\u2019s versionable allows you to define a set of keys for a document, whose\nchanges would trigger creation of new versions. However in our project we\nneeded to track changes at the complete document level, i.e. even for changes\nin the associations. Also the versions were embedded within the document\nitself, which implied that the document would grow in size very rapidly, even\nthough our changes in each iteration could be minor, since each version would\nliterally be a snapshot of the complete document itself.<\/p>"},{"title":"Calculating Hashes","link":"https:\/\/dhruvasagar.dev\/2010\/11\/25\/calculating-hashes\/","pubDate":"Thu, 25 Nov 2010 09:30:27 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/11\/25\/calculating-hashes\/","description":"<p>Showcasing how to calculate hashes in Java, C# and Ruby!<\/p>\n<h2 id=\"java-\">Java :<\/h2>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"line\"><span class=\"cl\"><span class=\"kd\">public<\/span><span class=\"w\"> <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"nf\">getHash<\/span><span class=\"p\">(<\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">message<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">algorithm<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"k\">try<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"kt\">byte<\/span><span class=\"o\">[]<\/span><span class=\"w\"> <\/span><span class=\"n\">buffer<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">message<\/span><span class=\"p\">.<\/span><span class=\"na\">getBytes<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"n\">MessageDigest<\/span><span class=\"w\"> <\/span><span class=\"n\">md<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">MessageDigest<\/span><span class=\"p\">.<\/span><span class=\"na\">getInstance<\/span><span class=\"p\">(<\/span><span class=\"n\">algorithm<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"n\">md<\/span><span class=\"p\">.<\/span><span class=\"na\">update<\/span><span class=\"p\">(<\/span><span class=\"n\">buffer<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"kt\">byte<\/span><span class=\"o\">[]<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">md<\/span><span class=\"p\">.<\/span><span class=\"na\">digest<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">hexValue<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"k\">for<\/span><span class=\"p\">(<\/span><span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">0<\/span><span class=\"w\"> <\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"p\">.<\/span><span class=\"na\">length<\/span><span class=\"w\"> <\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"o\">++<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">            <\/span><span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">b<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"o\">[<\/span><span class=\"n\">i<\/span><span class=\"o\">]<\/span><span class=\"w\"> <\/span><span class=\"o\">&amp;<\/span><span class=\"w\"> <\/span><span class=\"n\">0xff<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">            <\/span><span class=\"k\">if<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">Integer<\/span><span class=\"p\">.<\/span><span class=\"na\">toHexString<\/span><span class=\"p\">(<\/span><span class=\"n\">b<\/span><span class=\"p\">).<\/span><span class=\"na\">length<\/span><span class=\"p\">()<\/span><span class=\"w\"> <\/span><span class=\"o\">==<\/span><span class=\"w\"> <\/span><span class=\"n\">1<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">+<\/span><span class=\"w\"> <\/span><span class=\"s\">&#34;0&#34;<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">            <\/span><span class=\"n\">hex<\/span><span class=\"w\">  <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">+<\/span><span class=\"w\"> <\/span><span class=\"n\">Integer<\/span><span class=\"p\">.<\/span><span class=\"na\">toHexString<\/span><span class=\"p\">(<\/span><span class=\"n\">b<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"k\">return<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\"> <\/span><span class=\"k\">catch<\/span><span class=\"p\">(<\/span><span class=\"n\">NoSuchAlgorithmException<\/span><span class=\"w\"> <\/span><span class=\"n\">e<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"n\">e<\/span><span class=\"p\">.<\/span><span class=\"na\">printStackTrace<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"k\">return<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><\/code><\/pre><\/div><h2 id=\"c-\">C# :<\/h2>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System.Text<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System.Security.Cryptography<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getHash<\/span><span class=\"p\">(<\/span><span class=\"n\">String<\/span> <span class=\"n\">message<\/span><span class=\"p\">,<\/span> <span class=\"n\">String<\/span> <span class=\"n\">algo<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"kt\">byte<\/span><span class=\"p\">[]<\/span> <span class=\"n\">sourceBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Encoding<\/span><span class=\"p\">.<\/span><span class=\"n\">Default<\/span><span class=\"p\">.<\/span><span class=\"n\">GetBytes<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"kt\">byte<\/span><span class=\"p\">[]<\/span> <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"kc\">null<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"n\">Console<\/span><span class=\"p\">.<\/span><span class=\"n\">WriteLine<\/span><span class=\"p\">(<\/span><span class=\"n\">algo<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">switch<\/span><span class=\"p\">(<\/span><span class=\"n\">algo<\/span><span class=\"p\">.<\/span><span class=\"n\">Trim<\/span><span class=\"p\">().<\/span><span class=\"n\">ToUpper<\/span><span class=\"p\">())<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">case<\/span> <span class=\"s\">&#34;MD5&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">MD5CryptoServiceProvider<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA1&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA1Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA256&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA256Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA384&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA384Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA512&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA512Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"k\">default<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">            <span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"n\">StringBuilder<\/span> <span class=\"n\">sb<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">StringBuilder<\/span><span class=\"p\">();<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">for<\/span><span class=\"p\">(<\/span><span class=\"kt\">int<\/span> <span class=\"n\">i<\/span> <span class=\"p\">=<\/span> <span class=\"m\">0<\/span> <span class=\"p\">;<\/span> <span class=\"n\">hashBytes<\/span> <span class=\"p\">!=<\/span> <span class=\"kc\">null<\/span> <span class=\"p\">&amp;&amp;<\/span> <span class=\"n\">i<\/span> <span class=\"p\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;<\/span> <span class=\"n\">hashBytes<\/span><span class=\"p\">.<\/span><span class=\"n\">Length<\/span> <span class=\"p\">;<\/span> <span class=\"n\">i<\/span><span class=\"p\">++)<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">        <span class=\"n\">sb<\/span><span class=\"p\">.<\/span><span class=\"n\">AppendFormat<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;{0:x2}&#34;<\/span><span class=\"p\">,<\/span> <span class=\"n\">hashBytes<\/span><span class=\"p\">[<\/span><span class=\"n\">i<\/span><span class=\"p\">]);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"k\">return<\/span> <span class=\"n\">sb<\/span><span class=\"p\">.<\/span><span class=\"n\">ToString<\/span><span class=\"p\">();<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span>\n<\/span><\/span><\/code><\/pre><\/div><h2 id=\"ruby-\">Ruby :<\/h2>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"line\"><span class=\"cl\"><span class=\"nb\">require<\/span> <span class=\"s1\">&#39;digest&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">def<\/span> <span class=\"nf\">getHash<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">,<\/span> <span class=\"n\">algo<\/span><span class=\"o\">=<\/span><span class=\"s1\">&#39;md5&#39;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">case<\/span> <span class=\"n\">algo<\/span><span class=\"o\">.<\/span><span class=\"n\">strip<\/span><span class=\"o\">.<\/span><span class=\"n\">upcase<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">when<\/span> <span class=\"s2\">&#34;MD5&#34;<\/span> <span class=\"k\">then<\/span> <span class=\"no\">Digest<\/span><span class=\"o\">::<\/span><span class=\"no\">MD5<\/span><span class=\"o\">.<\/span><span class=\"n\">hexdigest<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">when<\/span> <span class=\"s2\">&#34;SHA1&#34;<\/span> <span class=\"k\">then<\/span> <span class=\"no\">Digest<\/span><span class=\"o\">::<\/span><span class=\"no\">SHA1<\/span><span class=\"o\">.<\/span><span class=\"n\">hexdigest<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">when<\/span> <span class=\"s2\">&#34;SHA256&#34;<\/span> <span class=\"k\">then<\/span> <span class=\"no\">Digest<\/span><span class=\"o\">::<\/span><span class=\"no\">SHA256<\/span><span class=\"o\">.<\/span><span class=\"n\">hexdigest<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">when<\/span> <span class=\"s2\">&#34;SHA384&#34;<\/span> <span class=\"k\">then<\/span> <span class=\"no\">Digest<\/span><span class=\"o\">::<\/span><span class=\"no\">SHA384<\/span><span class=\"o\">.<\/span><span class=\"n\">hexdigest<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">when<\/span> <span class=\"s2\">&#34;SHA512&#34;<\/span> <span class=\"k\">then<\/span> <span class=\"no\">Digest<\/span><span class=\"o\">::<\/span><span class=\"no\">SHA512<\/span><span class=\"o\">.<\/span><span class=\"n\">hexdigest<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">  <span class=\"k\">end<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">end<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>As you can see, the Ruby version to calculate hashes is the most concise\n&amp; simple.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 6","link":"https:\/\/dhruvasagar.dev\/2010\/11\/03\/getting-started-with-ruby-part6\/","pubDate":"Wed, 03 Nov 2010 04:22:09 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/11\/03\/getting-started-with-ruby-part6\/","description":"<p>After having covered most of the basics of Ruby, lets get started on an actual\nproblem, just like I had promised in my previous article \u2013 <a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/26\/getting-started-with-ruby-part5\/\" title=\"Getting started with Ruby - Part 5\">Getting started\nwith Ruby \u2013 Part 5<\/a><\/p>\n<p>I am taking a relatively simple problem that came in <a href=\"http:\/\/code.google.com\/codejam\/\" target=\"_blank\">Google\nCodejam<\/a> 2009 qualification round. Here is\nthe direct link to the problem : <a href=\"http:\/\/code.google.com\/codejam\/contest\/dashboard?c=90101\" target=\"_blank\">Alien\nLanguage<\/a><\/p>\n<blockquote>\n<p>After years of study, scientists at Google Labs have discovered an alien\nlanguage transmitted from a faraway planet. The alien language is very\nunique in that every word consists of exactly L lowercase letters. Also,\nthere are exactly D words in this language.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 5","link":"https:\/\/dhruvasagar.dev\/2010\/10\/26\/getting-started-with-ruby-part5\/","pubDate":"Tue, 26 Oct 2010 03:35:06 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/10\/26\/getting-started-with-ruby-part5\/","description":"<p>Hi in my previous article\u00a0<a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/23\/getting-started-with-ruby-part4\/\" title=\"Getting started with Ruby - Part 4\">Getting started with Ruby \u2013 Part 4<\/a> I covered\nHashes &amp; blocks.<\/p>\n<p>Today I will take you through the various forms of loops in Ruby.<\/p>\n<h2 id=\"while\">While<\/h2>\n<p>Executes <em>code<\/em> as long as the given condition is true. We can separate the\ncode from the condition using either the keyword <strong>do<\/strong>, a newline or\na semi-colon (;)<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"line\"><span class=\"cl\"><span class=\"n\">i<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">while<\/span> <span class=\"n\">i<\/span> <span class=\"o\">&gt;<\/span> <span class=\"mi\">5<\/span> <span class=\"k\">do<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"nb\">puts<\/span> <span class=\"s2\">&#34;Iteration <\/span><span class=\"si\">#{<\/span><span class=\"n\">i<\/span><span class=\"si\">}<\/span><span class=\"s2\">&#34;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"n\">i<\/span> <span class=\"o\">+=<\/span> <span class=\"mi\">1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">end<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Output :<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 2<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 3<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 4<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Alternatively, it is also possible to use the while loop as a modifier<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># towards the end of a statement or a code block<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">i<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">begin<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"nb\">puts<\/span> <span class=\"s2\">&#34;Iteration <\/span><span class=\"si\">#{<\/span><span class=\"n\">i<\/span><span class=\"si\">}<\/span><span class=\"s2\">&#34;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">    <span class=\"n\">i<\/span> <span class=\"o\">+=<\/span> <span class=\"mi\">1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">end<\/span> <span class=\"k\">while<\/span> <span class=\"n\">i<\/span> <span class=\"o\">&gt;<\/span> <span class=\"mi\">5<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Output :<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 2<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 3<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># Iteration 4<\/span>\n<\/span><\/span><\/code><\/pre><\/div><h2 id=\"until\">Until<\/h2>\n<p>Is very similar to the while loop with respect to the syntax &amp; usage, the only\ndifference between the two is the fact that the while loop executes the code\nblock as long as the condition is true, the until loop does exactly the\nopposite, i.e. it executes the code block as long as the condition is false.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 4 \u2013 Hashes & Blocks","link":"https:\/\/dhruvasagar.dev\/2010\/10\/23\/getting-started-with-ruby-part4\/","pubDate":"Fri, 22 Oct 2010 19:57:01 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/10\/23\/getting-started-with-ruby-part4\/","description":"<p>In my previous article\u00a0<a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/21\/getting-started-with-ruby-part3\/\" title=\"Getting started with Ruby\">Getting started with Ruby \u2013 Part 3<\/a> I started with\nCollections and covered basics of Ranges &amp; Arrays. Like I mentioned towards\nthe end of the article (in case you couldn\u2019t manage to reach the end) I will\nstart with one of the most commonly used Collection objects in Ruby, namely\nHashes.<\/p>\n<p>Hashes are essentially data structures to store key \u2013 value pairs, when you\nwish to store an element in the Hash you do so by assigning a unique key to it\nwithin the hash and while retrieving you do so with the help of that unique\nkey. The beauty of hashes is the fact that the \u2018key\u2019 in question here could be\njust about any object in Ruby, most commonly however in practice strings or\nsymbols (i\u2019ll get to what these are soon) are used as keys.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 3 \u2013 Collections, Ranges & Arrays","link":"https:\/\/dhruvasagar.dev\/2010\/10\/21\/getting-started-with-ruby-part3\/","pubDate":"Wed, 20 Oct 2010 19:27:19 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/10\/21\/getting-started-with-ruby-part3\/","description":"<p>In my previous article <a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part2\/\" title=\"Getting started with Ruby - Part 2\">Getting started with Ruby \u2013 Part 2<\/a> I introduced\nyou all to Ruby &amp; its philosophy and I started out with data type classes in\nRuby. I was able to give you an overview about Strings &amp; Numbers in ruby.\nToday I will start with <strong>Collections<\/strong>.<\/p>\n<h2 id=\"the-range\">The Range<\/h2>\n<p>As the name suggests, ranges hold a sequential collection of numbers. Defining\na range in Ruby is extremely simple, instead of explaining, i\u2019ll show it to\nyou. Don\u2019t be afraid to start an IRB shell to try the code out.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 2 \u2013 Introduction & Philosophy","link":"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part2\/","pubDate":"Mon, 18 Oct 2010 18:53:29 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part2\/","description":"<p>Hi again, this is part 2 of my series of articles to help beginners getting\nstarted with the Ruby programming language. At this point of time I would like\nto quote the definition of Ruby from the <a href=\"http:\/\/www.ruby-lang.org\/en\/\" target=\"_blank\">Ruby Programming Language<\/a>:<\/p>\n<blockquote>\n<p>A dynamic, open source programming language with a focus on simplicity and\nproductivity. It has an elegant syntax that is natural to read and easy to\nwrite.<\/p>\n<\/blockquote>\n<p>I know I had already quoted Ruby\u2019s definition from wikipedia in my previous\narticle <a href=\"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part1\/\">Getting started with Ruby - Part\n1<\/a>, but that was more from\na technical standpoint. Here I wanted to draw your attention to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Yukihiro_Matsumoto\" target=\"_blank\">Yukihiro\nMatsumoto<\/a>\u2018s<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>Popularly\nknown as Matz\n<\/span>\n philosophy behind creating Ruby, which is\nmaking programming as simple &amp; natural as humanely possible. We will be\nwitnessing that very soon.<\/p>"},{"title":"Getting started with Ruby \u2013 Part 1","link":"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part1\/","pubDate":"Mon, 18 Oct 2010 18:38:33 +0000","guid":"https:\/\/dhruvasagar.dev\/2010\/10\/19\/getting-started-with-ruby-part1\/","description":"<p>Before we get started with Ruby, let me first give you a brief on who I am,\nI am Dhruva Sagar, a software engineer having a little over 4 years of\nprofessional experience having worked in technologies in and around Java,\nJavascript, Adobe Flex, PHP and Ruby. I have always been fascinated by\nprogramming languages and have been eager to learn new ones and I can also\ncode comfortably in Perl, Python &amp; Groovy, however I haven\u2019t worked\nextensively on these. Right now I am working in a startup <a href=\"http:\/\/www.artha42.com\/\" target=\"_blank\">Artha42 Innovations\nPrivate Limited<\/a> and am having the best time of my\nlife!<\/p>"},{"title":"Moving to Ubuntu","link":"https:\/\/dhruvasagar.dev\/2008\/05\/06\/moving-to-ubuntu\/","pubDate":"Tue, 06 May 2008 09:59:31 +0000","guid":"https:\/\/dhruvasagar.dev\/2008\/05\/06\/moving-to-ubuntu\/","description":"<p>I have worked on quite a few Linux distros, Redhat, Knoppix, BackTrack, PHLAK,\nubuntu, etc. But most of the times I did that only to explore the realm of\nLinux and see for myself what its all about and explore a little more for the\nparticular distro\u2019s utilities, and not to actually shift myself completely to\nusing it solely, since I have been accustomed to using windows and the various\nsoftwares that I use on windows.<\/p>"},{"title":"Cleaning data on my computer","link":"https:\/\/dhruvasagar.dev\/2008\/05\/05\/cleaning-data-on-my-computer\/","pubDate":"Mon, 05 May 2008 03:50:14 +0000","guid":"https:\/\/dhruvasagar.dev\/2008\/05\/05\/cleaning-data-on-my-computer\/","description":"<p>I remember my first computer which I had when I was in about 4th\nstandard<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>About 15 years back if I remember\ncorrectly\n<\/span>\n. It was a real source of entertainment for me at\nthe time. Although I did enjoy playing basic dos games on it for long\ndurations a lot, but I remember that computer and most importantly it\u2019s exact\nconfiguration because of a really hilarious incident that happened with\nme!<label for=\"sidenote-2\" class=\"margin-toggle sidenote-number\">(2)<\/label>\n<input type=\"checkbox\" id=\"sidenote-2\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(2)<\/span>Well considering my age at that time and my level of\nunderstanding of computers, it really was hilarious, not that dumb\n\ud83d\ude00\n<\/span>\n<\/p>"},{"title":"Calculating a MD5, SHA1, SHA256, SHA384, SHA512 Hash in C#","link":"https:\/\/dhruvasagar.dev\/2007\/08\/15\/calculating-a-md5-sha1-sha256-sha384-sha512-hash-in-c\/","pubDate":"Wed, 15 Aug 2007 18:12:56 +0000","guid":"https:\/\/dhruvasagar.dev\/2007\/08\/15\/calculating-a-md5-sha1-sha256-sha384-sha512-hash-in-c\/","description":"<p>Following up on my <a href=\"https:\/\/dhruvasagar.dev\/2007\/08\/13\/calculating-a-md5-sha1-sha256-sha384-sha512-hash-in-java\" title=\"Calculating a MD5, SHA1, SHA256, SHA384, SHA512 hash in Java\">Creating a Hash in Java<\/a> post, here I am giving another\nimplementation through a simple function for calculating a Hash in C#.<\/p>\n<p>Here&rsquo;s the code:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System.Text<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">using<\/span> <span class=\"nn\">System.Security.Cryptography<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"kd\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">computeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">String<\/span> <span class=\"n\">message<\/span><span class=\"p\">,<\/span> <span class=\"n\">String<\/span> <span class=\"n\">algo<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"kt\">byte<\/span><span class=\"p\">[]<\/span> <span class=\"n\">sourceBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Encoding<\/span><span class=\"p\">.<\/span><span class=\"n\">Default<\/span><span class=\"p\">.<\/span><span class=\"n\">GetBytes<\/span><span class=\"p\">(<\/span><span class=\"n\">message<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"kt\">byte<\/span><span class=\"p\">[]<\/span> <span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"kc\">null<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"n\">Console<\/span><span class=\"p\">.<\/span><span class=\"n\">WriteLine<\/span><span class=\"p\">(<\/span><span class=\"n\">algo<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"k\">switch<\/span><span class=\"p\">(<\/span><span class=\"n\">algo<\/span><span class=\"p\">.<\/span><span class=\"n\">Trim<\/span><span class=\"p\">().<\/span><span class=\"n\">ToUpper<\/span><span class=\"p\">())<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">case<\/span> <span class=\"s\">&#34;MD5&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">MD5CryptoServiceProvider<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA1&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA1Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA256&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA256Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA384&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA384Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">case<\/span> <span class=\"s\">&#34;SHA512&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"n\">hashBytes<\/span> <span class=\"p\">=<\/span> <span class=\"n\">SHA512Managed<\/span><span class=\"p\">.<\/span><span class=\"n\">Create<\/span><span class=\"p\">().<\/span><span class=\"n\">ComputeHash<\/span><span class=\"p\">(<\/span><span class=\"n\">sourceBytes<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"k\">default<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t\t<span class=\"k\">break<\/span><span class=\"p\">;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"n\">StringBuilder<\/span> <span class=\"n\">sb<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">StringBuilder<\/span><span class=\"p\">();<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"k\">for<\/span><span class=\"p\">(<\/span><span class=\"kt\">int<\/span> <span class=\"n\">i<\/span> <span class=\"p\">=<\/span> <span class=\"m\">0<\/span> <span class=\"p\">;<\/span> <span class=\"n\">hashBytes<\/span> <span class=\"p\">!=<\/span> <span class=\"kc\">null<\/span> <span class=\"p\">&amp;&amp;<\/span> <span class=\"n\">i<\/span> <span class=\"p\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;<\/span> <span class=\"n\">hashBytes<\/span><span class=\"p\">.<\/span><span class=\"n\">Length<\/span> <span class=\"p\">;<\/span> <span class=\"n\">i<\/span><span class=\"p\">++)<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t\t<span class=\"n\">sb<\/span><span class=\"p\">.<\/span><span class=\"n\">AppendFormat<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;{0:x2}&#34;<\/span><span class=\"p\">,<\/span> <span class=\"n\">hashBytes<\/span><span class=\"p\">[<\/span><span class=\"n\">i<\/span><span class=\"p\">]);<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\t<span class=\"k\">return<\/span> <span class=\"n\">sb<\/span><span class=\"p\">.<\/span><span class=\"n\">ToString<\/span><span class=\"p\">();<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span>\n<\/span><\/span><\/code><\/pre><\/div>"},{"title":"Calculating a MD5, SHA1, SHA256, SHA384, SHA512 Hash in Java","link":"https:\/\/dhruvasagar.dev\/2007\/08\/13\/calculating-a-md5-sha1-sha256-sha384-sha512-hash-in-java\/","pubDate":"Mon, 13 Aug 2007 17:58:32 +0000","guid":"https:\/\/dhruvasagar.dev\/2007\/08\/13\/calculating-a-md5-sha1-sha256-sha384-sha512-hash-in-java\/","description":"<p>Hi, today I will show you with examples how to evaluate Hashes in Java\nprogramming language. I hope this information comes in useful for many\npeople.<\/p>\n<p>Java which is my favorite programming language because of sheer simplicity,\nvastness and ease with which you can customize and extend existing libraries\nto suit your needs.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"line\"><span class=\"cl\"><span class=\"cm\">\/**\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> * The getHash method returns the hash of the message\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> *\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> * @param message The message to be hashed\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> * @param algorithm The hashing algorithm to be used,\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> *                  Possible values are MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> *\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> * @return The hash of the message\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> *\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> * @author Dhruva Sagar\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"cm\"> *\/<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"kd\">public<\/span><span class=\"w\"> <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"nf\">getHash<\/span><span class=\"p\">(<\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">message<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">algorithm<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">  <\/span><span class=\"k\">try<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"kt\">byte<\/span><span class=\"o\">[]<\/span><span class=\"w\"> <\/span><span class=\"n\">buffer<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">message<\/span><span class=\"p\">.<\/span><span class=\"na\">getBytes<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"n\">MessageDigest<\/span><span class=\"w\"> <\/span><span class=\"n\">md<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">MessageDigest<\/span><span class=\"p\">.<\/span><span class=\"na\">getInstance<\/span><span class=\"p\">(<\/span><span class=\"n\">algorithm<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"n\">md<\/span><span class=\"p\">.<\/span><span class=\"na\">update<\/span><span class=\"p\">(<\/span><span class=\"n\">buffer<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"kt\">byte<\/span><span class=\"o\">[]<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">md<\/span><span class=\"p\">.<\/span><span class=\"na\">digest<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"n\">String<\/span><span class=\"w\"> <\/span><span class=\"n\">hexValue<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"k\">for<\/span><span class=\"p\">(<\/span><span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">0<\/span><span class=\"w\"> <\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"w\"> <\/span><span class=\"o\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"p\">.<\/span><span class=\"na\">length<\/span><span class=\"w\"> <\/span><span class=\"p\">;<\/span><span class=\"w\"> <\/span><span class=\"n\">i<\/span><span class=\"o\">++<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      <\/span><span class=\"kt\">int<\/span><span class=\"w\"> <\/span><span class=\"n\">b<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">digest<\/span><span class=\"o\">[<\/span><span class=\"n\">i<\/span><span class=\"o\">]<\/span><span class=\"w\"> <\/span><span class=\"o\">&amp;<\/span><span class=\"w\"> <\/span><span class=\"n\">0xff<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"k\">if<\/span><span class=\"w\"> <\/span><span class=\"p\">(<\/span><span class=\"n\">Integer<\/span><span class=\"p\">.<\/span><span class=\"na\">toHexString<\/span><span class=\"p\">(<\/span><span class=\"n\">b<\/span><span class=\"p\">).<\/span><span class=\"na\">length<\/span><span class=\"p\">()<\/span><span class=\"w\"> <\/span><span class=\"o\">==<\/span><span class=\"w\"> <\/span><span class=\"n\">1<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">+<\/span><span class=\"w\"> <\/span><span class=\"s\">&#34;0&#34;<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">          <\/span><span class=\"n\">hex<\/span><span class=\"w\">  <\/span><span class=\"o\">=<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"w\"> <\/span><span class=\"o\">+<\/span><span class=\"w\"> <\/span><span class=\"n\">Integer<\/span><span class=\"p\">.<\/span><span class=\"na\">toHexString<\/span><span class=\"p\">(<\/span><span class=\"n\">b<\/span><span class=\"p\">);<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      <\/span><span class=\"k\">return<\/span><span class=\"w\"> <\/span><span class=\"n\">hex<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\"> <\/span><span class=\"k\">catch<\/span><span class=\"p\">(<\/span><span class=\"n\">NoSuchAlgorithmException<\/span><span class=\"w\"> <\/span><span class=\"n\">e<\/span><span class=\"p\">)<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">      <\/span><span class=\"n\">e<\/span><span class=\"p\">.<\/span><span class=\"na\">printStackTrace<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"k\">return<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">;<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><\/code><\/pre><\/div>"},{"title":"About","link":"https:\/\/dhruvasagar.dev\/about\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/dhruvasagar.dev\/about\/","description":"<h2 id=\"i-am-dhruva-sagar\">I am Dhruva Sagar<\/h2>\n<p>When I was 15 year old. My dream was very simple. I wanted to write code. Open\nSource code, more specifically. I have been chasing that dream for a long\ntime<label for=\"sidenote-1\" class=\"margin-toggle sidenote-number\">(1)<\/label>\n<input type=\"checkbox\" id=\"sidenote-1\" class=\"margin-toggle\"\/>\n<span class=\"sidenote\">\n<span class=\"sidenote-number\">(1)<\/span>~18 years professionally, significantly longer if you count\nthe time since I was writing code in school \/ college\n<\/span>\n.\nStill at it. <strong>That&rsquo;s what keeps me going<\/strong>.<\/p>\n<p>This site is my little corner of the web where I jot down some of the\ninteresting things I come across<\/p>"},{"title":"Now","link":"https:\/\/dhruvasagar.dev\/now\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/dhruvasagar.dev\/now\/","description":"What I am focused on NOW"}]}}