Skip to content

Instantly share code, notes, and snippets.

@mike1011
mike1011 / Ruby and Rails Interview Cheat Sheet.md
Created June 12, 2020 08:21 — forked from ahmadhasankhan/Ruby and Rails Interview Cheat Sheet.md
This is my Ruby interview cheat sheet. Feel free to fork it, Use it, Share it, or do whatever you want with it. PLEASE let me know if there is any error or if anything crucial is missing. I will keep updating...

Ruby and Rails Interview Questions

Ruby

  • What is a class?
  • What is an object?
  • What is a module? Can you tell me the difference between classes and modules?
  • Can you tell me the three levels of method access control for classes and modules? What do they imply about the method?
  • There are three ways to invoke a method in ruby. Can you give me at least two?
  • Explain this ruby idiom: a ||= b
###################################### UBUNTU ###############################################
==== to search by port ======
lsof -wni tcp:3000
==== to kill by port ========
sudo kill -9 `sudo lsof -t -i:3000`
==== another way to search and kill a process using port ===
sudo lsof -i -P -n | grep 6379
sudo kill -9 <process_id>
@mike1011
mike1011 / rails-jsonb-queries
Created April 26, 2020 17:18 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@mike1011
mike1011 / setup to make non-user model confirmable using rails devise
Last active January 28, 2024 13:02
Adding Rails Devise Confirmable module to a non-user model so that it can be confirmed
Use Case - Use Devise Confirmable module to confirm newly added organization(org) using email(association)
We want Three things to work -
Use confirmable - send_confirmation_instructions to send email when new org is added
Define Routes - organization_confirmation_url, so that user can use this route to confirm the org
Add confirmable columns inside existing organizations table, update token,timestamps on db
====== HERE WE START =========
- `organization.rb`
has_one :contact_detail ##contains email
@mike1011
mike1011 / cygwin-rvm.md
Created September 4, 2019 12:35 — forked from kirkelifson/cygwin-rvm.md
RVM Install on Windows

Do you have spaces in your Windows username?

  1. Create a new account on Windows without a space.

#Installation

  1. Download cygwin from http://cygwin.com
  2. Run setup-(x86|x86_64).exe
  3. Click next until selecting repo to download packages
  4. Choose http://cs.vt.edu (gotta go fast), click next
First, setup and install monit on Ubuntu server
###get the latest
sudo apt-get update
##install monit
sudo apt-get install monit
##edit monit and add the below custom scripts
sudo vim /etc/monit/monitrc
##reload and verify
sudo monit reload
sudo monit
@mike1011
mike1011 / puma.monitrc
Created June 8, 2019 00:48 — forked from sudara/puma.monitrc
Example config needed to use monit with puma, monitoring workers for mem.
# this monit config goes in /etc/monit/conf.d
check process puma_master
with pidfile /data/myapp/current/tmp/puma.pid
start program = "/etc/monit/scripts/puma start"
stop program = "/etc/monit/scripts/puma stop"
group myapp
check process puma_worker_0
with pidfile /data/myapp/current/tmp/puma_worker_0.pid
@mike1011
mike1011 / sidekiq_monitoring
Created April 10, 2019 22:56 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@mike1011
mike1011 / gist:50c0209c4183302e71735197977b64be
Created March 10, 2019 19:19 — forked from mrilikecoding/gist:9520502
RVM Workflow for creating a new Rails Project with Postgres, ready for Heroku
#Make sure heroku toolbelt and rvm are installed
#heroku toolbelt available to download on their site, rvm available via curl
\curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm use "2.1.1"
rvm use --create 2.1.1@project
gem install rails
#if using postgres (good for heroku) pass argument to 'rails new'
rails new project --database=postgresql
@mike1011
mike1011 / verify_s3_file.rb
Created February 7, 2019 23:11 — forked from hartfordfive/verify_s3_file.rb
Check if file exists in S3 bucket with Ruby aws-sdk gem
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
credentials: Aws::InstanceProfileCredentials.new()
)
bucket = s3.bucket('my-daily-backups')
file = (DateTime.now).strftime("%Y.%m.%d-backup")
if bucket.object(file).exists?