Skip to content

Instantly share code, notes, and snippets.

View MyklClason's full-sized avatar

Mykl Clason MyklClason

  • Wisconsin, United States
View GitHub Profile
@MyklClason
MyklClason / cronjob.rb
Last active May 29, 2016 17:03
A trivial Rails cron job made using the Que gem
# app/jobs/cron_job.rb
class CronJob < Que::Job
# To minimize log clutter from unavailable jobs,
# @run_at should be a bit less than Que.wake_interval
@run_at = proc { 59.seconds.from_now }
def run
# Do stuff here
@MyklClason
MyklClason / 0.rails-repo-setup.md
Last active October 15, 2016 05:26
Reminder for how to setup my typical rails app to ensure nothing gets forgotten. Includes a number of useful files. Uses Devise, Bootstrap, Rspec, Capybara, and Guard.

Instructions:

  1. Setup rails:
    • rails new app-name
    • rails new app-name -T (if going to use rSpec)
  2. UpdateGemfile
  3. Run Bundle install --without production
  4. Create Guardfile
  5. Run rails generate rspec:install
  6. Update spec/rails_helper.rb
@MyklClason
MyklClason / gist:4868769b6deec9deac7b4236896241fc
Created July 8, 2017 00:35
S3 IAM Template. Update the date and replace BUCKET_NAME with correct S3 bucket
{
"Version": "YYYY-MM-DD",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::BUCKET_NAME",
"arn:aws:s3:::BUCKET_NAME/*"
]
@MyklClason
MyklClason / gist:08bf67d13220e5ee44dc2a3118bf08c1
Last active July 12, 2017 04:04
Import from heroku MySQL database
Connection String
mysql://USERNAME:PASSWORD@HOST/DATABASE
Command line where FILENAME is file with data to be imported (filename.sql).
mysql -u USERNAME -pPASSWORD -h HOST DATABASE < FILENAME > import.log
@MyklClason
MyklClason / _footer.html.erb
Last active August 4, 2017 03:15
Bootstrap Rails Application.html layout with separated nav and footer
@MyklClason
MyklClason / c9_backup_download_restore_db_heroku.txt
Last active August 17, 2017 18:46
Cloud9: Pull database from Heroku via backup, download and restore.
heroku pg:backups:capture
heroku pg:backups:download
pg_restore --verbose --clean --no-acl --no-owner -U ubuntu -d app_development latest.dump
# 1. Delete everything except the hidden .c9 folder
# 2. Setup aliases
# Setup Postgres database
sudo service postgresql start
sudo sudo -u postgres psql
CREATE USER username SUPERUSER PASSWORD 'password';
\q
echo "export USERNAME=username" >> ~/.profile
echo "export PASSWORD=password" >> ~/.profile
. ~/.profile
@MyklClason
MyklClason / useful_rails_gems.md
Last active September 12, 2017 07:37
List of useful gems and related articles I've come across.

Notes for those who are reading this:

  • Blocks are generally used together.
  • Feel free to suggest addition gems or articles to be added.
  • I may eventually make this into a repo.
  • At the bottom is a list of things pending review that others may find useful.
@MyklClason
MyklClason / ajax.js.erb
Last active November 7, 2017 01:48
Simple way to handle Bootstrap flash messages when using AJAX and the twitter-bootstrap-rails gem.
// The below must be included somewhere in in .js.erb file.
...
$('#bootstrap-flash').html("<%= j (bootstrap_flash) %>");
...
@MyklClason
MyklClason / version1b.rb
Last active January 30, 2018 05:50
Reset all RoR Postgres ID counters via rails console
Rails.application.eager_load!
ActiveRecord::Base.descendants.map { |m| ActiveRecord::Base.connection.reset_pk_sequence!(m.table_nam‌​e) }