Remove Duplicates From Array in Postgres 9.5+ JSONB Column

Recently needed to clean up some data that looked like this:

in a jsonb column. The result I need is:

Took me a while to figure this out but here’s the query in case anyone needs it.

The above query would update a single record, but how do you update every record with the corresponding row?

Simple AJAX and Rails Tutorial

It’s been a while since I’ve posted anything but I’ve been extremely busy coding my face off. The upside of that is I’ve been learning a ton of new stuff and I have a lot of things I want to write about.

Today I’m just going to go over a quick tutorial on how to use AJAX to send requests to functions in your Rails backend. The problem I kept running into was calling a function that is in a different controller than the view I’m calling it from.
Continue reading

Background Tasks & Rails – A Sidekiq Example

This post involves a little bit of everything–queuing (Sidekiq), JSON, API calls, redis, database manipulation. Enjoy!

The latest feature I am pushing to Dotawithme is listing the players by who is currently online. This is an oft requested feature (with good reason – DOTA players are impatient) but I wasn’t entirely sure what the best way to go about this was.

Of course I couldn’t just hammer Valve’s Steam API or I would quickly hit my daily limit. This means I need to create a background process to run at set intervals and update the database accordingly. There are many different gems to help your Rails app out with this and I settled on Sidekiq (‘Sidekick’) because it’s fast and (supposedly) simple to use.

Continue reading

On Scope, Lambdas, & SQL Queries

Adding MMR (match making ranking) filtering to Dotawithme has been an oft requested feature on Reddit so I finally decided to tackle the issue. I wasn’t exactly sure the best way to go about it but in the end I decided I wanted to put rankings in a range of 500. I thought the best way to do this was to use a dropdown menu with a variety of ranges to select from (ie: 1001-1500 or 1501-2000).

Continue reading

Tweet Random Quotes with Ruby

I recently started using Buffer with my Twitter account in the hopes that I would be more active by queuing up my tweets in advance.  One of the great things about Buffer is that it offers suggestions on things you might want to post.  Often times they have quotes in their suggestions and since I am a big fan of quotes I decided to write my own tool to just publish quotes.

Continue reading

Adding Private Messages in Rails Apps

I keep adding features to The latest and probably largest feature yet has been private messages. I looked around and there are quite a few gems out there that will do this for you, but they haven’t seemed to be updated in a while. After trying one out (and failing to get it to work properly) I decided it would be a good challenge for me to write my own.

Continue reading

Use Google Fonts in Rails Apps

I wanted to use a Google Font for a logo and no where else in the site. It took me a fair amount of googling to figure out something that is relatively simple. One of those annoying problems of syntax differences again. Anyways, this is just a quick post with the answer in case anyone else follows in my footsteps.

Continue reading