Skip to content

Instantly share code, notes, and snippets.

@bahelms
bahelms / git_clean.sh
Last active April 30, 2019 13:55
Clean yo git!
git branch --merged | grep -Ev "(^\*|master|dev)" | xargs git branch -d
git remote prune origin
@bahelms
bahelms / docker_cleanup_tasks.sh
Created January 8, 2016 14:00
Docker clean up tasks
# The grep regex determines what you actually remove
# Remove old containers
docker ps -a | grep "\(weeks\|hours\) ago" | awk '{print $1}' | xargs docker rm
# Remove images without tags
docker images | grep "^<none>" | awk '{print $3}' | xargs docker rmi
@bahelms
bahelms / reset_bluetooth.txt
Created February 20, 2015 18:30
Restart faulty bluetooth on MacBook Pro OSX 10.9.5
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@bahelms
bahelms / random_string
Created December 5, 2014 16:28
Random String generation
# Replace the variable 'size' with the desired string length
o = [('a'..'z'), ('A'..'Z'), (0..9)].map { |i| i.to_a }.flatten; string = (0...size).map { o[rand(o.length)] }.join
@bahelms
bahelms / resync.sh
Created October 3, 2014 21:11
Resync stupid ubuntu clock
# Re-sync clock on ubuntu
sudo /etc/init.d/ntp stop
sudo ntpdate ntp.ubuntu.com
sudo apt-get install ntp
@bahelms
bahelms / js_notes
Last active August 29, 2015 14:06
OOP JavaScript notes
// Reflection
typeof 100 => Number
object instanceof Object => true/false
Array.isArray(array_var) => true/false
// Detecting object properties
"property" in object => true/false // checks own and prototype
object.hasOwnProperty("property") => true/false
Object.keys(object) // returns own properties only
for (var property in object) {} // loops over enumerable own and prototype properties
@bahelms
bahelms / gist:befb2bd25e6e1cf1fb51
Created September 4, 2014 18:21
Alias bundle exec for common commands to avoid typing
In your .bashrc/.bash_profile paste the following (add any other commands to bundle_commands):
bundle_commands="sidekiq spring rake spec rspec cap rails rackup guard middleman"
function run_bundler_cmd () {
if [ -r ./Gemfile ]; then
bundle exec $@
else
$@
fi
}
@bahelms
bahelms / ds_store_banished
Last active April 17, 2018 00:42
Remove .DS_Store from git index
Remove existing files from repo:
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
Add .DS_Store to .gitignore
@bahelms
bahelms / check_local_storage.coffee
Last active August 29, 2015 14:04
Default to previous active tab after page reload
jQuery ->
checkLocalStorage = ->
lastTab = localStorage.getItem("name_of_saved_item")
if lastTab
# Set active tab to previous tab from before page reload
$("a[href='#{lastTab}']").tab("show")
localStorage.removeItem("name_of_saved_item")
# Execute every time page is loaded
checkLocalStorage()
@bahelms
bahelms / merge_csv.rb
Last active May 9, 2022 19:46
Merge multiple csv files into one in Ruby
require "csv"
def csv_headers
["Your", "Headers", "Here"]
end
files = Dir["file_names_*.csv"].sort_by { |f| "if you want to sort the files" }
file_contents = files.map { |f| CSV.read(f) }
csv_string = CSV.generate do |csv|