Working with time zones in Rails sometimes requires a bit knowledge and persistence to get it right; I learned that this is something you can easily do wrong.

Ask a random Ruby developer to get today’s Date. He will most likely respond with Date.today. And what about the current time? He’ll probably say Time.now. Both are correct… for Ruby that is.
In Rails it may be correct as well until you need to handle different time zones. Most developers actually think they don’t need to (because they do not need to use a different time zone in their application) until they run into problems. For example, most applications do need to work with the transition of daylight saving (and thus requires a timezone setting in the configuration) or the database actually works with a different timezone then the application (usually UTC).

So what if you can’t use Date.today and Time.now, what do you need to use? Well Rails supplies the current method on Rails’s Date and Time classes to fix this issue. This method checks whether you’re using timezones (in your configuration) and if you are, it uses the Time.zone variant.

So a good rule of thumb is to always use Date.current, Time.current or DateTime.current (although Rubocop recommends not to use the latter) for getting the current time or date.

More information can be found in the following articles:

 

Check and clean git stashes with dates

Posted on: Tuesday, Jun 14, 2016

When working with git stashes, your stash list may get filled with old savepoints from the past. This surely happens when you do not pop the stashes when using them. At one point, you may want to clean this list of stashes and check how old the stashes actually are to make sure they can be deleted.

You can check the dates of each stash in the list using the following command
git stash list --date=local

Do you want to try other date formats? You can see other options here.

Have a specific stash you want to view the date and other details? Use the following command, specifying the stash number between the brackets:
git show stash@{0}

Once you are sure you can remove your saved stashes, use the following command to clear all or specific stashes:

All stashes at once (make sure that you want to do this!):
git stash clear

Specific stash:
git stash drop stash@{0}

More information can be found on https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning

Learning Rails – Routing

Posted on: Wednesday, May 21, 2014

Starting the second course, Rapid Prototyping with Ruby on Rails, over at the Tealeaf Academy, I’m starting to learn how to work with Rails.

One of the subjects in this lesson of study material is Rails’s Routing documentation.

In the Rails Routing guide the 7 different routes are explained that are automatically created when specifying a plural resource in routes.rb.

Read the rest of this entry »

Final Blackjack game

Posted on: Saturday, Mar 29, 2014

Blackjack board

The last lesson (week) of the Tealeaf Academy Ruby on Rails Online Bootcamp was to add betting and AJAXify the Blackjack game.

I’ve had the wildest ideas and grand schemes to make the Blackjack game a fun, flashing, exciting and grand game that even could compete with the Casinos.

Read the rest of this entry »

Blackjack on the web

Posted on: Monday, Mar 24, 2014

Blackjack cards and chipsIn week 3 of the Ruby on Rails online bootcamp I had to remake the Blackjack game using the web framework, Sinatra.

As this would be the third time making the Blackjack game, that game logic wasn’t that much of a problem anymore. However, getting used to Sinatra and suddenly making a web application proved to be a whole new learning experience.

Read the rest of this entry »

I’m working on the web version of the Blackjack game. This is done using the Sinatra framework for Ruby.

While running the development web server (Shotgun/Thin) and using sessions, you may get the following warning in the console:

SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.

Read the rest of this entry »

Blackjack console game (continued)

Posted on: Saturday, Mar 15, 2014

blackjack cardsIn the next week of the Ruby online bootcamp over at the Tealeaf Academy, you have to recreate the Blackjack game using  an object oriented approach. Having worked as a Java Software Engineer before, this isn’t much of a problem to me.

I’ve implemented the objects and spruced up the ASCII art even more then the previous version.

Read the rest of this entry »

Why use symbols as hash keys in Ruby?

Posted on: Wednesday, Mar 12, 2014

Question

A lot of times people use symbols as keys in a Ruby hash. What’s the advantage over using a string?

E.g.:  hash[:name]  vs.  hash[‘name’]

Answer

Using symbols not only saves time when doing comparisons, but also saves memory, because they are only stored once.

Symbols in Ruby are basically “immutable strings” .. that means that they can not be changed, and it implies that the same symbol when referenced many times throughout your source code, is always stored as the same entity, e.g. has the same object id.

Read the rest of this entry »

Maker’s Schedule, Manager’s Schedule

Posted on: Tuesday, Mar 11, 2014

As recommend by my TA, Chris Lee, in one of his previous live sessions, over at Tealeaf Academy, I read the article ‘Maker’s Schedule, Manager’s Schedule’ today.

I must say, it was a halleluja moment. Finally it all made sense how hard it is to concentrate on the development work now and then. As a developer you really need to be able concentrate on what you’re doing and try to ignore all of the distractions everywhere around you. Knowing how much distractions anyone has at their work nowadays, you can understand how hard this is.

Read the rest of this entry »

Blackjack console game

Posted on: Friday, Mar 7, 2014

blackjack cards

I’m attending the GoTealeaf Professional Grade Ruby on Rails Online Bootcamp. As an assignment you have to create a procedural Blackjack game that can be run in the console / terminal.

I’ve done this but I developed it a bit more then required: I created the Blackjack game with lots of ASCII art to make it fun.

Read the rest of this entry »