Skip to content

Instantly share code, notes, and snippets.

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 / 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
@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 / 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")
###################################### 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 / 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
@mike1011
mike1011 / Add existing repo to a fresh new Repo
Last active August 1, 2020 01:25
Push existing code to new fresh repo
To begin with, firstly create a new repository on github WITHOUT INITIALIZING it.
## clean up existing repo
rm -rf .git
## re-initialize it with new .git settings
git init
## firstly, dont commit any code, just create/add new sample/readme file and push it to new repo/master
git add README.md
## add newly created fresh repo
git remote add origin [email protected]:username/my-new-master-repo.git
@mike1011
mike1011 / Ruby on Rails - Questions
Last active March 3, 2022 12:29
Ruby on Rails - Interview questions
========== ONLY RUBY ==========
array vs hash - ordered indexed collection
convert hash to array = h.to_a
get even/odd entries from array -> select.each_with_index { |_, i| i.even? }
get hash keys in reverse order -> Hash[h.to_a.reverse] OR hash_array.keys.reverse
---replace strings --
value = "cat"
# Replace string at with ote.
value.sub!("at", "ote") // just first instance - cote
value = value.gsub("cat", "---") //all instances globally ---
@mike1011
mike1011 / FrontEnd Interview questions
Last active July 17, 2023 19:46
Interview questions for nodejs/javascript.
What is Circular Dependency?
Shallow vs Deep Copy.
Array.sort() - with numbers and strings.
PUT vs PATCH
What is package-lock.json?
---ref - https://medium.com/iquii/good-practices-for-high-performance-and-scalable-node-js-applications-part-1-3-bb06b6204197
What is this? How arrow functions using it to help the binding?
Session Management in Nodejs
API Authentication in Nodejs
Default memory size in NOdejs
@mike1011
mike1011 / readme.md
Last active October 22, 2021 15:17 — forked from yosukehasumi/readme.md
DigitalOcean Rails/Ubuntu/NGINX (16.04) Setup

DigitalOcean Rails/Ubuntu/NGINX (16.04) Setup

  1. Setup
  2. Swapfile
  3. NGINX
  4. ElasticSearch
  5. RVM
  6. Rails
  7. Redis
  8. Postgres