To find the command / more information associated with a specific process id (PID), do the following: cat /proc/[pid]/cmdline
Author: anthony
Rails: get Time object in specific time and time zone
To get a rails Time object in a specific time and time zone, do the following: Time.zone = “Hawaii” #for example Time.zone.parse(“2015/08/04 5:00 PM”) #for example
Gitignore not ignoring file
If after you’ve updated .gitignore to ignore a file and the changes are not being ignored, do the following: git rm /path/to/your/file –cached This will remove the file from the repository, but not from the file system.
Rails, Paperclip, Custom Interpolation
To allow custom interpolations in the PaperClip :path designation, add the following to your config/initializers/paperclip.rb file: Paperclip.interpolates :custom_field do |attachment, style| attachment.instance.custom_field end Where :custom_field is whatever field associated with your attachment model you’d like interpolated in your path.
Rails 4, AWS Elastic Beanstalk, and RDS
This guide shows you how to configure a Rails 4 app with AWS’s elastic beanstalk and RDS. First, install the elastic beanstalk command line tool on your local development box: $ sudo apt-get install git $ sudo apt-get install python-dev $ curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py” $ sudo python get-pip.py $ sudo pip install awsebcli […]
GIT: Find when a specific string was introduced to a branch
To find when a specific line of code was added to a branch with git, run the following: git log -S “your-string-here” –source –all –stat
Resolve Net::HTTPBadResponse: wrong status line
In Ruby/Rails, if you’re running into the following error: Net::HTTPBadResponse: wrong status line When attempting to post data to a secure (https) url, with something similar to: Net::HTTP::post_form(“https://www.example.com”,{}) Then you can rewrite your request to avoid the exception like this: url = URI.parse(“https://www.example.com”) http = Net::HTTP.new(url.host,url.port) http.use_ssl = true request = Net::HTTP::Post.new(url.path,{}) request = […]
Rails.cache.fetch not overwriting current value
If you notice a Rails cache call not overwriting the previously entered value, for instance: Rails.cache.fetch(“your_key”) do your_random_value end Try passing the force flag to fetch, like this: Rails.cache.fetch(“your_key”, :force=>true) do your_random_value end And it should work without a problem.
Cron Job: Run rails rake task in shell script
To run a rake task within a shell script using a cron job, do the following: First, specify the shell at the top of your .sh script #!/bin/sh Then, change your directory to your rails application in your .sh script cd /home/user/app/current Now, you need to manually define your PATH within the script: […]
Clear stale resque workers
To clear stale / stuck resque workers, run the following command within your Rails Console. Resque.workers.each {|w| w.unregister_worker}