Skip to content

Instantly share code, notes, and snippets.

@amit
amit / db.rake
Last active May 7, 2024 04:11 — forked from hopsoft/db.rake
Update for rails 7.0.X and handle postgres password
# apt install postgresql-client
# apt-get -y install bash-completion wget
# wget --no-check-certificate --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
# echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
# apt-get update
# apt-get -y install postgresql-client-12
namespace :db do
desc "Dumps the database to backups"
@amit
amit / MailinatorAliases
Created April 29, 2020 02:46 — forked from nocturnalgeek/MailinatorAliases
A list of alternate domains that point to @mailinator.com
@binkmail.com
@bobmail.info
@chammy.info
@devnullmail.com
@letthemeatspam.com
@mailinater.com
@mailinator.net
@mailinator2.com
@notmailinator.com
@reallymymail.com
@amit
amit / MailinatorAliases
Created April 29, 2020 02:46 — forked from nocturnalgeek/MailinatorAliases
A list of alternate domains that point to @mailinator.com
@binkmail.com
@bobmail.info
@chammy.info
@devnullmail.com
@letthemeatspam.com
@mailinater.com
@mailinator.net
@mailinator2.com
@notmailinator.com
@reallymymail.com
@amit
amit / README.md
Created November 8, 2019 15:10 — forked from tristanm/README.md
Migrating a Rails project from MySQL to PostgreSQL

Migrating a Rails project from MySQL to PostgreSQL

This brief guide is written from my own experience with migrating a large (~5GB) MySQL database to PostgreSQL for a Rails project.

No warranties, guarantees, support etc. Use at your own risk and, as always, ENSURE YOU MAKE BACKUPS FIRST!

I chose [pgloader][1] because it's extremely fast. YMMV.

  1. Replace mysql2 gem with pg in Gemfile.
  2. Update config/database.yml for PostgreSQL. I used [Rails' template][2] as a starting point.
@amit
amit / harshad.rb
Created February 23, 2018 20:14
Find Harshad Numbers
# Harshad numbers are divisible by sum of their digits. e.g. 1729 (1+7+2+9=19 and 19*91=1729
# https://en.wikipedia.org/wiki/Harshad_number
# Sum of digits of a (positive) number: q
q = 987654321
puts q.to_s.split('').reduce{|sum, n| sum.to_i + n.to_i}.to_i
# Find Harshad number between 1 and 1000:
puts (1..1000).select{|q| q % q.to_s.split('').reduce{|sum, n| sum.to_i + n.to_i}.to_i == 0}
@amit
amit / ac_stream.rb
Created February 15, 2018 22:49 — forked from dansimpson/ac_stream.rb
Aircraft position streaming
require 'socket'
require 'json'
class AircraftPositionStream
def initialize host, port
@host = host
@port = port
end
@amit
amit / check_sshd_root_login.sh
Created September 15, 2017 18:24
Check SSHD Configuration for Root User Login
#!/bin/bash
# This script checks if the root user can access SSH server on this machine
FILE="/etc/ssh/sshd_config"
if ! [[ -r $FILE ]]
then
echo "Unable to read $FILE"
exit 1
fi

Keybase proof

I hereby claim:

  • I am amit on github.
  • I am journeyer (https://keybase.io/journeyer) on keybase.
  • I have a public key ASB5OdF37yxSMnNG3m_BEpAydHdK2bhVspSMkW0_k3V8TAo

To claim this, I am signing this object:

@amit
amit / serializer.rb
Last active August 25, 2016 17:34
Activerecord test of simulteneous access serialization
threads = []
(0..4).each do
threads << Thread.new {
row = XAuth::Variable.where(name: "current_member_id").first_or_create
row.with_lock do
sleep(2)
oldvalue = row.value.to_i
newvalue = oldvalue + 1
row.value = newvalue
row.save!
@amit
amit / saavn.js
Last active August 29, 2015 14:15 — forked from vtomiris/saavn.js
/**
* Chrome-Last.fm-Scrobbler - Saavn.com Connector
*
* Author: Vikas Kumar [vikas@cs.umn.edu]
* Derived from Sitesh Shrivastava code on gaana.js
*/
// DOM Nodes to keep track for song details
var SONG_TRACK_DOM = '#player-track-name';
var SONG_ALBUM_DOM = '#player-album-name';