Top-rated Ruby recipes http://code.activestate.com/recipes/langs/ruby/top/2014-07-12T16:58:06-07:00ActiveState Code RecipesDisplay a git repository (Ruby) 2012-07-05T17:01:53-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577572-display-a-git-repository/ <p style="color: grey"> Ruby recipe 577572 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/graphviz/">graphviz</a>, <a href="/recipes/tags/grit/">grit</a>, <a href="/recipes/tags/visualisation/">visualisation</a>). Revision 2. </p> <p>A tiny script to display the entire contents of a medium sized git repository. It will display tags, branches and commits with different shapes and colours and the commits messages in a dimmed colour. </p> <p>It relies on graphviz to do the plotting. Use it like so </p> <pre class="prettyprint"><code> ruby plotrepo.rb /path/to/repository | dot -Tpng | display -antialias </code></pre> Analog clock (Ruby) 2013-10-11T05:23:49-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578682-analog-clock/ <p style="color: grey"> Ruby recipe 578682 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/analog/">analog</a>, <a href="/recipes/tags/clock/">clock</a>). </p> <p>Analog clock with Qt4</p> Get external IP (Ruby) 2013-07-01T05:51:36-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578580-get-external-ip/ <p style="color: grey"> Ruby recipe 578580 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/ipv4/">ipv4</a>). Revision 3. </p> <p>Checks IPv4</p> Playing with GDI+ (brushes) (Ruby) 2012-11-21T11:05:20-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578346-playing-with-gdi-brushes/ <p style="color: grey"> Ruby recipe 578346 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/gdiplus/">gdiplus</a>, <a href="/recipes/tags/ironruby/">ironruby</a>). </p> <p>Just for fun. Enjoy!</p> Easy way to use Graph Facebook API without ad-hoc libraries (Ruby) 2012-11-20T14:14:27-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/578343-easy-way-to-use-graph-facebook-api-without-ad-hoc-/ <p style="color: grey"> Ruby recipe 578343 by <a href="/recipes/users/4174931/">Filippo Squillace</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/facebook/">facebook</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/ruby/">ruby</a>). </p> <p>I was painfully lokking for a simple function that allow easily make GET or POST requests in Ruby without using complex libraries such as Koala for accessing to the Facebook Graph. At the end I gave up and did it by myself, so the function fb_api, based on net/http, is able to make GET or POST requests (depending if the request is for retrieving information of the graph or is for changing the graph such as post feed etc.). It returns a dict from a JSON data structure.</p> <p>This might be useful for your facebook app ;)</p> Loaded assemblies (Ruby) 2012-11-19T08:53:23-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578341-loaded-assemblies/ <p style="color: grey"> Ruby recipe 578341 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/assemblies/">assemblies</a>, <a href="/recipes/tags/ironruby/">ironruby</a>). </p> <p>Sometimes (working with IronRuby with interactive mode) it's very useful to know what assemblies was loaded. This sample shows how to do it.</p> Retrieve codecs (Ruby) 2012-11-19T08:49:26-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578340-retrieve-codecs/ <p style="color: grey"> Ruby recipe 578340 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/codecs/">codecs</a>, <a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/registry/">registry</a>). </p> <p>On WinXP (there is no other Windows in my VMWare Player :) you can do it with Ruby in the next way:</p> <p>require 'win32/registry'</p> <p>Win32::Registry::HKEY_CLASSES_ROOT.open( 'CLSID{083863F1-70DE-11d0-BD40-00A0C911CE86}\Instance' ) do |reg| reg.each_key do |key| val = reg.open(key) puts val['FriendlyName'] end end</p> <p>But what about extended information, aah? I'm talking about script which shows additional data such as CLSID and codec location. With IronRuby it can be done so easy.</p> Checking hashes of files (Ruby) 2012-11-19T08:45:51-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578339-checking-hashes-of-files/ <p style="color: grey"> Ruby recipe 578339 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/md5/">md5</a>, <a href="/recipes/tags/ripemd160/">ripemd160</a>, <a href="/recipes/tags/sha1/">sha1</a>, <a href="/recipes/tags/sha256/">sha256</a>, <a href="/recipes/tags/sha384/">sha384</a>, <a href="/recipes/tags/sha512/">sha512</a>). </p> <p>There is HashAlgorithm class in System.Security.Cryptography namespace which is stored into mscorlib, a core assembly of .NET Framework. So...</p> Multidimensional arrays (Ruby) 2012-11-19T08:43:11-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578338-multidimensional-arrays/ <p style="color: grey"> Ruby recipe 578338 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/multidimensional/">multidimensional</a>). </p> <p>The next example shows how to create rectangular and jagged arrays.</p> Reading all subvalues of key (Ruby) 2012-11-19T08:41:11-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578337-reading-all-subvalues-of-key/ <p style="color: grey"> Ruby recipe 578337 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/registry/">registry</a>). </p> <p>With Ruby you can make wonders ;) This snippet shows how to read all subvalues of a key at one time.</p> Print letters with different case (Ruby) 2012-11-19T08:38:31-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578336-print-letters-with-different-case/ <p style="color: grey"> Ruby recipe 578336 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/letters/">letters</a>). </p> <p>It seems just for fun but sometimes it very useful (for example, writing a script to generate random password).</p> Retrieving product key with IronRuby (Ruby) 2012-11-03T18:22:01-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578320-retrieving-product-key-with-ironruby/ <p style="color: grey"> Ruby recipe 578320 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/productkey/">productkey</a>). </p> <p>If you like <a href="http://code.activestate.com/recipes/578317-product-key/?in=lang-text">IronPython script</a> for retrieving MS products' keys then you like IronRuby analog. Maybe...</p> rdd (mostly broken but shows how to do a few things in ruby) (Ruby) 2014-07-12T16:58:06-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578034-rdd-mostly-broken-but-shows-how-to-do-a-few-things/ <p style="color: grey"> Ruby recipe 578034 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/dd/">dd</a>, <a href="/recipes/tags/ftp/">ftp</a>, <a href="/recipes/tags/io/">io</a>, <a href="/recipes/tags/net_ftp/">net_ftp</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>). Revision 3. </p> <p>Meant to be a slightly more "advanced" dd utility. Supporting FTP/File/STDIN as input streams, and File/STDOUT/PIPE as output targets, and sporting a progress display (very rudimentary atm), add lets you combine network, and file or pipe processing in a single command. But kind of ended up a mess, see the <a href="https://code.activestate.com/recipes/578907-python-awesome-dd/?in=user-4179778">Python version</a> which is pretty clean.</p> Easy ansi color plus more. (Ruby) 2014-04-16T15:36:04-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578018-easy-ansi-color-plus-more/ <p style="color: grey"> Ruby recipe 578018 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/clear/">clear</a>, <a href="/recipes/tags/console/">console</a>, <a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/movement/">movement</a>, <a href="/recipes/tags/output/">output</a>, <a href="/recipes/tags/ruby/">ruby</a>, <a href="/recipes/tags/screen/">screen</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/underline/">underline</a>). </p> <p>This quick class extends the base String class to add the ability to chain escape codes onto your output. For instance: puts 'String'.bold.underline.blink.red for something truly hideous. Aside from the colors (all are supported, but I haven't put in support for background colors as of the time of this post), cursor placement (ymmv based on the term type), screen clearing, bold, underline, blink reverse, conceal are all handled as well.</p>