Skip to content

Instantly share code, notes, and snippets.

View bandogora's full-sized avatar

bandogora

View GitHub Profile
@bandogora
bandogora / rails_length_to_size.sh
Last active April 25, 2022 21:03
Replace all Rails instances of `.length` with `.size`
find ./app -type f -not -path './db/*' -iregex '.*.\(rb\|haml\|erb\)' -exec sed -ri 's/\.length([^_])/\.size\1/g' {} \;
@bandogora
bandogora / rails_count_to_size.sh
Created April 25, 2022 17:09
Replace all Rails instances of `.count` with `.size`
find . -type f -not -path './db/*' -iregex '.*.\(rb\|haml\|erb\)' -exec sed -ri 's/(\.count)/\.size/g' {} \;
@bandogora
bandogora / try_harder.sh
Last active December 8, 2021 23:44
Replace all Rails instances of `.try` with `&.`
# .try :method -> &.method
find ./ -type f -exec sed -ri 's/(.try\s*:)/\&./g' {} \;
# .try(:method) -> &.method
find ./ -type f -exec sed -ri 's/(.try\(?:)([^),]*)(\))/\&.\2/g' {} \;
@bandogora
bandogora / start-mysql.sh
Last active December 8, 2021 21:43
WSL2: Add to bashrc to check if MySQL server is running and start it if it's not.
#!/bin/sh
# Start mysql if its not running
mysql_daemon='mysqld'
pgrep='/usr/bin/pgrep'
$pgrep $mysql_daemon > /dev/null
if [ $? -ne 0 ]; then
sudo /usr/sbin/service mysql start
fi
@bandogora
bandogora / make-resolve-conf.sh
Last active December 8, 2021 21:43
Script to recreate resolve.conf in WSL2
#!/bin/sh
# First create /etc/wsl.conf as sudo if it doesn't exist. Then add the following lines and restart wsl.
# [network]
# generateResolvConf = false
# Next run `sudo rm /etc/resolv.conf` then execute this script.
# Finally run `sudo ln -s $HOME/.resolv.conf /etc/resolv.conf`
nameservers=$(powershell.exe -Command "Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses")
echo -e nameserver $nameservers | sed -z 's/\r/\nnameserver/g' | head -n -1 > $HOME/.resolv.conf
@bandogora
bandogora / parallel-spec-loop-until-fail.sh
Last active December 8, 2021 21:44
Run ruby parallel_tests with rspec in a loop until a test fails
#!/bin/sh
echo -e "\033[0;31mRunning parallel:spec recursively until a failure occurs\033[0m"
: > rspec_error.txt #clear file in case last run failed
pushd $1
while [[ $(tail -n 1 ~/rspec_error.txt) != "Tests Failed" ]]
do
rake parallel:spec 1>~/rspec_out.txt 2>~/rspec_error.txt
echo -ne "\033[1;34m.\033[0m"
done