Skip to content

Instantly share code, notes, and snippets.

@linyco
linyco / gist:e6ba01e360f68a768673eb39eede3550
Last active May 10, 2018 19:46
Shell - Recursively replace the text in files
sed -i '' 's/#2bc2dd/#2cc4ea/g' *.scss
find . -type f -name "*.html.erb" -exec sed -i '' 's/#2bc2dd/#2cc4ea/g' '{}' \;
# ref: https://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files
@linyco
linyco / gist:76009c8401c2d368e222e9ee1bb0425e
Created April 20, 2018 13:10
Shell - Delete all merged local branches
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
# https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
@linyco
linyco / log_rotate.sh
Created April 17, 2018 14:37
Shell - Log Rotate for Rails application or etc
# ref: https://www.digitalocean.com/community/tutorials/how-to-manage-log-files-with-logrotate-on-ubuntu-12-10
# for ROR application
/home/*/current/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
@linyco
linyco / mailer_spec.rb
Last active February 14, 2023 17:00
Rails - Mailer Spec
expect(mail.from).to include 'sender@example.com'
expect(mail.to).to include 'receiver@example.com'
expect(mail.subject)
.to eq 'Test Email Subject'
expect(mail.reply_to).to include 'reply_to@example.com'
expect(mail.attachments.size).to eq 1
attachment = mail.attachments[0]
expect(attachment).to be_a_kind_of Mail::Part
expect(attachment.content_type).to match %r(application/pdf)
@linyco
linyco / hover_menu.js
Last active January 23, 2018 14:45
Js - Slide down menu
// The simple version
// which only relies on the click on x to close
// the slide down menu
var ready;
ready = function() {
$('.hoveronthis')
.on("mouseenter", function() {
$('.hovercontents')
@linyco
linyco / chain_method_helper.rb
Last active July 18, 2022 12:08
Ruby - Send Chain Method Helper
# Ref: https://stackoverflow.com/questions/4099409/
# ruby-how-to-chain-multiple-method-calls-together-with-send?
# answertab=active#tab-top
#
# This helper is to create a custom method to send a chain
# of string to the active record
module ChainMethodHelper
def send_chain(arr)
arr.inject(self) {|o, a| o.send(:try, a) }
end
@linyco
linyco / your_app
Last active November 28, 2017 23:48
Nginx - two domain on one server
# ref: https://stackoverflow.com/questions/11773544/nginx-different-domains-on-same-ip
upstream your_app {
server unix:///home/your_app/shared/tmp/sockets/puma.sock fail_timeout=0;
}
# Redirect from http to https
server {
listen 80;
server_name domain1.com www.domain1.com;
@linyco
linyco / formatMoney.js
Last active January 16, 2018 22:44
Js - Intl.NumberFormat
var formatMoney = function(price) {
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
});
if (price > 999999) {
var roundedPrice = (price / 1000000).toFixed(1)
return formatter.format(roundedPrice) + 'mm';
@linyco
linyco / lets_encrypt.sh
Last active November 22, 2017 22:20
devop - change domain
cd ~
git clone https://github.com/letsencrypt/letsencrypt
cd ~/letsencrypt
sudo service nginx stop
./letsencrypt-auto certonly --standalone -d new_website.com
sudo service nginx start
@linyco
linyco / .powrc
Last active November 21, 2017 17:16
RoR - Pow Set Up
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then
source "$rvm_path/scripts/rvm"
source ".rvmrc"
fi