Skip to content

Instantly share code, notes, and snippets.

View bipashant's full-sized avatar

Bibek Sharma Chapagain bipashant

  • Sydney, NSW, Australia
View GitHub Profile
@edisonywh
edisonywh / pre-commit
Last active April 15, 2024 22:58
Run Rubocop in Git's pre-commit hook
```
#!/bin/sh
echo "\nRunning rubocop 🚓 💨 💨 💨\n"
declare -a ERRORS=()
for file in $(git diff --cached --name-only | grep -E '.rb')
do
ERRORS+=("$(rubocop $file | grep -e 'C:' -e 'E:')")
done
@tomysmile
tomysmile / mac-setup-redis.md
Last active May 23, 2024 03:17
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@abhinavmsra
abhinavmsra / money_best_practices.md
Last active November 12, 2023 13:00
Tips for Money Related Arithmetic in Ruby

Tips for Money Related Arithmetic in Ruby

  1. Never use float for performing arithmetic calculations relating to money.

    Floating numbers can sometimes show funky behaviour. It is not Ruby’s fault but the very implementation of floating numbers raises precision issues.

Examples of odd behaviour:

tables = [] # or ActiveRecord::Base.connection.tables
collation = "utf8_unicode_ci"
char_set = "utf8"
db = "your_database_name"
# write out
puts "USE #{db};"
puts "ALTER DATABASE #{db} CHARACTER SET #{char_set} COLLATE #{collation};"
tables.each do |t|
puts "ALTER TABLE #{t} CHARACTER SET #{char_set} COLLATE #{collation};" # changes for new records
puts "ALTER TABLE #{t} CONVERT TO CHARACTER SET #{char_set} COLLATE #{collation};" # migrates old records
@sathishmanohar
sathishmanohar / install_passenger_nginx_digital_ocean.sh
Last active June 2, 2020 12:30
Steps to setup and install passenger nginx and rails on digital ocean
# Login as root
ssh root@domain
# Create deploy user
adduser <username> #Adds User with username given. Enter Password when Prompted. Other Details are Optional
# Add user to sudo group
usermod -g <groupname> <username>
# Add .ssh/authorized_keys for deploy user
@mustafaturan
mustafaturan / nginx
Created May 5, 2012 13:49
Nginx Init Script Centos 6
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
@cluePrints
cluePrints / gist:2521535
Created April 28, 2012 19:27
Installing Rails @ Amazon Linux

Steps

  • Build tools:

      sudo yum groupinstall "Development Tools"
    
  • Dependencies:

      yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel \
    

libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel

@robotmay
robotmay / gist:2479149
Created April 24, 2012 12:09
Find the closest date in an array of dates
# I have an array of dates (both past and present) and a single date ('needle' below),
# for which I want to find the closest date in either direction. Here's my solution;
# can you think of a better one?
dates.sort_by { |date| (date.to_time - needle.to_time).abs }.first
@re5et
re5et / dig.rb
Created March 2, 2012 01:29
ruby hash dig
class Hash
def dig(*path)
path.inject(self) do |location, key|
location.is_a?(Hash) ? location[key] : nil
end
end
end
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111