Build Silly Apps for your Friends

A friend of mine runs a Horror podcast called Nite Shift Video, Horror Movie Reviews, Scary Stories, and Interviews with other people in the Spooky Community. One of the interview ice breakers he does is a scary version of MASH. No, not the old tv show about soldiers in the Korean war. The future telling paper and pen game from grade school.

Mash was a game where you picked some categories and filled them in with choices then people would pick a magic number through various means. Then you would count through and cross off every Nth choice until you were left with one choice in each category. Then that was supposed to be your future.

The host, Nite Shift Jay, would run a custom one they made in pen and paper and have the guest guess a number to decide their horror movie future. However, to cut down on the dead air time as he followed the algorithm of moving through the choices crossing out numbers, Jay asked me to make a website version, so he could just take the number and get the result to keep things running smooth.


With this request in mind, The Mash Website was built. This was a simple project, took me maybe a day to build and deploy once I sat down and did it. However, I did get to learn things even during a small project like this.

  • Utilize Docker to deploy on digital ocean
  • Use LetsEncrypt to secure a subdomain of my root domain.
  • Build a Dynamic Form builder, to allow users to decide how many categories and choices they want.
  • Automate log rotation, docker health checks and automated restarts.

All these things are simple in the grand scheme of things but very valuable to have done yourself. Most jobs you get hired at likely already have a lot of this done, or have someone who manages the DevOp side of things. So it feels good to take something and put it out for the world to use. Obviously, it could use a lot more cleanup and design, however, it served the purpose for Jay. Through the magic of google analytics as well, it seems as at least 24 other people have used it as well. While it’s not changing the world or making me millions, I hope it made someone smile.


Mash Website: https://mash.p3rishable.com/games

Nite Shift Video: https://www.instagram.com/niteshiftvideo/

Run Rake tasks on a server with Capistrano and Rake

I ran into the issue the other day of getting my Jenkins to be able to
run rake tasks on a remote server. So I decided to write a rake task
that allowed it to offload the connection to the remote box onto
Capistrano. This nifty little Rake task will allow you to run Rake tasks
in a production environment on a remote server using the Dynamic Duo of
Capistrano 3 and Rake.

desc "Easily Run rake task on a remote server"
  task :server_side_rake do
    on roles(:app), in: :sequence, wait: 5 do
      within release_path do
      with rails_env: :production do
      execute :rake, ENV['task'], "RAILS_ENV=production"
      end
    end
  end
end

Then you can run your one off rake task with the following command:

cap production server_side_rake task=one_time_rake_task --trace

Easy as that!

Check for Compiled Assets Existence.

Have you ever run into a situation where you wanted to check if an asset exists in Rails. Then when you deploy to production, it doesn’t work. That is because Rails by default compiles assets which changes the path and file name.

We found this out the hard way, luckily it was just the first deploy so
it didn’t affect any customers. So I thought I would share the solution we found.

Inside of a helper add the following code:

def asset_exist?(path)
  if Rails.configuration.assets.compile
    Rails.application.precompiled_assets.include? path
  else
    Rails.application.assets_manifest.assets[path].present?
  end
end

Then in your view or controller:

if asset_exist?('test.png')
  puts "Asset found!"
else
  puts "Asset not found!"
end

There you have it!

Mobile Testing on Rails

If you have worked on making a website, in this mobile age you have probably run into the issue of testing local code on external devices, such as your cell phone or tablet. I’ll show you a really quick way to all your Rails server to be exposed to other devices on your network.

– Ensure Both Devices are on the same network.
– Then start your rails server using the following command:

rails s -b 0.0.0.0

Next find your local ip:

Mac
This can be found in your System Preferences -> Network and will be shown in tiny print under the status of your connection.

Linux
Use ifconfig to find your address

ifconfig

If you’re lazy you can use this command to just give you back what you want.

ifconfig | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`

Finally on your mobile browser and go to the url YOUR_IP:PORT

Easy Blogging with Rake and Jekyll

Fresh out of College, I read everything on how to make yourself more marketable. Several places suggested, write a blog to get your name out there. However, as a graduate, I was not looking to drop money on a hosted blog or pay for a server to run my own. Also there is something awkward about dot wordpress dot com sites, that just makes people run away from them.

In walks GitHub pages. A useful tool for you to make a simple site for a project, but as you can work on yourself, You could argue that you are your biggest project. So while building this blog I decided to use Jekyll since GitHub will allow me to host it for free on their servers.

In order to make the process easier I created a Rake file too easily create new Posts.

# Ask for title
def ask message
  print message
  STDIN.gets.chomp
end
title = ask('Title: ')

#Create new a post
desc "Default 'rake' command creates a new post"
task :default do
  filename = "#{Time.now.strftime('%Y-%m-%d')}-#{title.gsub(/\s/, '_').downcase}.markdown"
  path = File.join("_posts", filename)
  if File.exist? path; raise RuntimeError.new("File exists #{path}"); end
  File.open(path, 'w') do |file|
    file.write <<-EOS
---
layout: post
title: #{title}
date: #{Time.now.strftime('%Y-%m-%d %k:%M:%S')}
---

Content goes here
    EOS
  end

  # open the file in vim
  sh "vim #{path}"

end

Then to create a new blog post you just run:

rake