Skip to content

Instantly share code, notes, and snippets.

View garyharan's full-sized avatar
🎯
Focusing

Gary Haran garyharan

🎯
Focusing
View GitHub Profile
@garyharan
garyharan / story_time_classy_switch_cases.rb
Last active May 12, 2022 16:05
Using a class comparison in a switch case condition
# Story time: Classy Switch Classes
# Say you have a bunch of messages coming in Slack and you'd like to add an automatic emoji
# of course your team is multicultural and you may want to cater to the diverse crowd you have.
# For the purpose of this exercise we will treat `message#emojis` and `message#replies` as arrays we can push to.
# You could write your code like this:
if message.text.include?("Good morning!")
@garyharan
garyharan / install_ruby_debug_1.9.3.sh
Created March 15, 2012 23:23
Installing ruby-debug with ruby 1.9.3
# After installing ruby-debug19, run this file.
#
# References:
# http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
# http://stackoverflow.com/questions/8087610/ruby-debug-with-ruby-1-9-3
echo "Installing ruby-debug with $MY_RUBY_HOME ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@garyharan
garyharan / colorize.rb
Last active October 12, 2021 13:12
Simple rails logging output colorize
#!/usr/bin/env ruby -w
# SETUP:
# (assumes ~/bin/ is in your path)
# cp colorize.rb ~/bin/colorize
# chmod +x ~/bin/colorize
# USAGE:
# tail -f log/development.log | colorize
class String
@garyharan
garyharan / experience.txt
Last active June 7, 2021 14:05
Experience and diversity have value
A friend of mine, approaching 50, works as a programmer in a medium sized consultancy. In a recent conversation he told me how he felt like he was feeling older now that they had hired many 20-somethings in his company. The younger developers, he said, would do things faster than he would and it started to look like he was just a slower developer than the more youthful new hires. He was wondering if his days were numbered.
He was resigning himself to the idea that he was experiencing some kind of decline of his faculties if he compared himself to the more youthful years of his career. However this wasn’t the only conversation I had about the work at his company. The conversation before that one had him put the finger on something crucial.
So I had a conversation with him about it and we connected the dots.
Me: What was the password story they tackled?
Him: A password reset.
Me: And what was wrong with how they implemented it.
Him: Well the user typed their email in and then if they click the “forgot passw
@garyharan
garyharan / split_pushed_commits.sh
Created February 24, 2020 17:52
Workflow for splitting commits already pushed
# initiate the change with an interactive rebase from the point you want
git rebase -i SHA^
git reset HEAD^
# do this as many times as you need.
git add -p
git commit -v
# once all your changes are committed
git rebase --continue
@garyharan
garyharan / fix_mac_audio.sh
Created March 17, 2020 20:02
Restart all core audio when airpods do not work
# Instead of rebooting system
# If audio has half going through speakers and half going through headphones.
ps aux | grep 'coreaudio[d]' | awk '{print $2}' | xargs sudo kill
@garyharan
garyharan / dot_pryrc
Created June 18, 2012 14:23
Awesome Print + Pry == Awesome Pry
require "rubygems"
require "awesome_print"
Pry.print = proc { |output, value| output.puts value.ai }
@garyharan
garyharan / threads_maximum.rb
Created September 27, 2018 17:25
Reaching maximum threads in ruby
loop { Thread.new { sleep } rescue puts "Borked at #{Thread.list.count} threads." }
@garyharan
garyharan / grants.sql
Created November 27, 2016 01:31
How to setup postgresql properly for phoenix defaults
# run psql command to get to this
# Replace APP_NAME with application name
grant all privileges on database APP_NAME_dev to postgres;
grant all privileges on database APP_NAME_test to postgres;
@garyharan
garyharan / rails_helper.rb
Last active March 15, 2017 17:06
Speed up tests marginally
# ...
config.before(:suite) do
connection = ActiveRecord::Base.connection
query = connection.tables.map { |t| "ALTER TABLE #{t} SET UNLOGGED;" }.join("\n")
# one line for each foreign_key at the end of your schema.rb
ActiveRecord::Migration.remove_foreign_key "reports", "users"
connection.execute(query)
end