If you have ever used the git command-line utility, you will be pleasantly surprised that if you run git clone --help it automatically displays the man page for git clone instead of the usual --help output. This blog post will show you how to add the same functionality to your Ruby command-line utility. Introducing kramdown-man Man pages are written in the roff typesetting markup language , which…
This year I decided to try my hand at the Advent of Cyber challenges. The Day 2 challenge involves Data Science. We are given a Jupyter Notebook file containing a table of log data showing ports scan events. Now the challenge teaches you how to use Jupyter Notebook and Python, but we’re not going to solve it using Python. We are going to solve it using only Ruby! While Python is very popular in…
Recently, I wanted to use ActiveRecord in a library, not in a Rails app or a Rails engine. After doing a bit of Googling, I found this excellent tutorial . While it covered the basics, such as connecting to the database, defining a model and a migration, it missed a few things. In this blog post I will provide a more detailed example of how to connect to a default or arbitrary database, “connect”…
In XKCD comic #936 it explains how to measure password strength and how to come up with a more “secure” password. In this blog post I will show you how to enumerate such XKCD-style passwords using Ruby . To do this we will use two libraries: wordlist and chars . $ gem install wordlist chars The wordlist library allows one to open/build wordlists, enumerate them, combine multiple wordlists…
The Problem Normally in Ruby if you need to write a method which accepts one or more arguments and executes a command, you would write something like this: def git_pull ( branch ) system ( "git pull origin #{ branch } " ) end However, there are a few problems with the above code: Does not validate the input (ex: git_pull(nil) , git_pull("") , git_pull(true) , git_pull(false) , git_pull([1,2,3]) ,…
Warning: Controversial Content If you are morally or ethically opposed to building/releasing Ruby Gems with rake , this blog post may anger you. If this is the case, you are advised to STOP READING and CLICK THE BACK BUTTON. Ever since we could release Ruby Gems, we have had Gem helpers that could generate new projects and provided Rake tasks to automate the building/publishing of Gems. The most…
Warning: Controversial Content If you are morally or ethically opposed to using Project Generators and prefer to create RubyGems by hand, STOP READING AND CLICK THE BACK BUTTON . I am perfectly aware that one does not need any tools to create a RubyGem, and that all you really need is RubyGems and a *.gemspec file. However, the majority of users do not have the time or patience to create each Ruby…
A while back tenderlove blogged about using Ruby to interact with NFC tags . Near Field Communication (NFC) grew out of the Radio Frequency Identification ( RFID ) standard and has been used for contact-less payment with SmartPhones. Although, NFC tags are not yet widely deployed in the US, as opposed to Japan. On the other hand, RFID is widely deployed in the US, used in Payment systems, Asset…
There are many pagination solutions out there. Of course there’s the venerable will_pagination and the much newer Kaminari . However, all of the pagination solutions usually contain boiler-plate HTML. What if we only want the pagination logic, maybe in a JSON API, without using Rails or ActiveRecord, but instead Sinatra and DataMapper . As it turns out, DataMapper makes DIY pagination as simple…
Recently mephux began working on a hexdump.js library ( epic demo ). Naturally, I thought I should go back and improve my Ruby Hexdump library. Hexdump 0.2.x Hexdump now supports word-sizes and endianness. This is useful for dumping packed unsigned int s: Hexdump.dump("\x12\x34\x00\x00\x42\x42", :word_size => 2, :endian => :big) # 00000000 1234 0000 4242 |ሴ䉂| :word_size can have any value, and is…
TL;DR net-http-server : $ gem install net-http-server pure-Ruby HTTP Parser and Server Small codebase Fast-ish Rack-like API Rack Handler included full YARD Documentation WEBrick Some have said that the WEBrick HTTP Server is a Ghetto . While WEBrick is very fast for a pure-Ruby HTTP Server, the parsing code is hand written and difficult to read . WEBrick is also one of the oldest Ruby HTTP…
More likely than you think. Having good documentation (internal and external) can make or break bigger projects. Good documentation helps skilled users/developers get up to speed with your project. However, bad documentation will drive potential users away. Typos are probably the most embarrassing thing to find in documentation. One day I was fixing a trivial bug in my code for a new-user, and…
When Rails 3.0.0.beta.1 was first released, there was some confusion about how to deploy a Rails3 app with this new Bundler thing. A few blog posts were written with some monkey patches for injecting into Capistrano , which enable early Bundler support. Unfortunately, Bundler was still very new and none of the deployment tools had official support yet. Around the same time, I needed to deploy a…
Recently there has been some interesting discussion on the role of Gem builders and gemspecs. Jeff Kreeftmeijer wrote about how easy it is to build a RubyGem using a hand-written .gemspec file. With just a stand-alone .gemspec file one can: Build RubyGems: gem build my-project.gemspec . Publish RubyGems: gem push my-project-0.1.0.gem . One thing worries me is the fact that you either have to…
I decided to take my List Comprehension code with some other Combinatorics code I had floating around and release Combinatorics 0.2.0: $ gem install combinatorics After getting specs on the List Comprehension code, it became easy to refactor it and get the specs passing on Ruby 1.8.7, 1.9.2 and JRuby. Unfortunately, Rubinius does not yet support Enumerator#next . The Combinatorics library also…
Recently I have been interested in Haskell and been skimming the whimsical (yet informative) Learn a Haskell, for Great Good! . One feature I really like from Haskell is their implementation of list comprehensions: Prelude> [(x,y) | x <- [1..10], y <- [2..8]] [(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8), (2,2),(2,3),(2,4),(2,5),(2,6),(2,7),(2,8), (3,2),(3,3),(3,4),(3,5),(3,6),(3,7),(3,8),…
I have always liked how frameworks such as Rails can autoload Classes. I wanted to provide similar behavior in Ronin and other frameworks, so I created the OpenNamespace library. OpenNamespace allows namespaces to require and find classes and modules from RubyGems. Using OpenNamespace you can make a Plugins module able to load plugin modules/classes from other gems. More specifically,…
uri-query_params is a new library which allows accessing the individual parameters in the query string of a HTTP URI in Ruby. The library monkey-patches the URI::HTTP class to provide similar behavior to PHPs famous $_GET hash. $ gem install uri-query_params Using uri-query_params you can, inspect the URI query_params: require 'uri/query_params' url =…