Signing and Encrypting data with Rails

Rails provides abstractions for signing and encrypting data. If a Rails app needs to authenticate some data, (let’s say, to generate a magic link sent by email) Rails.application.message_verifier provides a convenient solution. This application-level interface was added in Rails 4.1, so it is already a mature Rails feature. The examples below wrap an opaque login token that is associated with a user in the payload. login_token = SecureRandom.urlsafe_base64(32) # => "2LfzCleMQtoNLYij4Ah_y5M80LwXbj3yPqeojsVvRBY" verifier = Rails.application.message_verifier(:magic_link) signed_message = verifier.generate( { token: login_token }, expires_in: 30.minutes, purpose: :login ) # => "eyJfcmFpbHMiOnsiZGF0YSI6eyJ0b2tlbiI6IjJMZnpDbGVNUXRvTkxZaWo0QWhfeTVNODBMd1hiajN5UHFlb2pzVnZSQlkifSwiZXhwIjoiMjAyNi0wNy0yNlQxMjowODozNS42ODBaIiwicHVyIjoibG9naW4ifX0=--3f9948547736a1650e31c35c6c7b38f518785380" payload = verifier.verify(signed_message, purpose: :login) # => {"token" => "2LfzCleMQtoNLYij4Ah_y5M80LwXbj3yPqeojsVvRBY"} Rails.application.message_verifier is a turnkey solution for signing and verifying application data with a MAC-based mechanism. It supports expiration and purpose scoping outside of the data itself. The secret is derived from secret_key_base.

Read more →

MOC: Map of Content

What is an MOC An MOC (Map of Content) is a curated cluster of related information around some area of interest. At a glance, it may look like just an index of notes. But an MOC is not only for organizing scattered notes, but also provides an opportunity to think, deepen your understanding, discover connections, and distill ideas. Building and maintaining an MOC is therefore part of the value it provides.

Read more →

Astrolabe: A Tool to Explore Relationships Between Similar Words

I am creating a tiny tool to explore relationships between two words utilizing WordNet: Astrolabe. It is intended to help ESL learners like me to grasp a clearer picture of a particular sense by recognizing the relationships between two words that have something in common. Motivation I have been trying to extend my vocabulary with Anki for years, little by little. It is an awesome tool to learn new words. I have learned about 6,000 words with it. Thanks to that, now it is much easier to read books and discuss diverse topics in English.

Read more →

Synset Representation in The WordNet Library

In the WordNet library, a synset is represented by a struct called Synset. There are 26 members in this struct. While playing with tracing the WordNet graph, I had a chance to use half of them. Let me introduce them. Basic Information About The Synset Itself char* defn is a short description of the synset (a.k.a. gloss). It often includes a couple of short example sentences, too. int* pos is the part of speech of the synset. It is a character like “n” as in “noun” and “v” as in “verb”. In many cases, a pos is represented by an integer, and here’s not the case for some reason. You can get the integer representation of the corresponding character with the utility function int getpos(char*).

Read more →

WordNet Provides Morphological Processing Functions

WordNet library has handy functions to deal with irregular inflections like morphstr(). It tries to find the base form of the given word and the pos (part of speech) in the database. When it comes to looking up a word with WordNet, the word is often unfamiliar for the person. You can guess whether the word is singular or plural form, present or past tense from the context of the sentence. However, you cannot be 100% sure about the base form because there is a possibility that the word morphs in an unexpected way. If you are not sure about the base form of a given word, morphstr() would help.

Read more →

Gentaro "hibariya" Terada

Otakanomori, Nagareyama, Chiba, Japan
Email me

Likes Ruby, Internet, and Programming.