Skip to content

Instantly share code, notes, and snippets.

Jerome Dalbert jeromedalbert

View GitHub Profile
@jeromedalbert
jeromedalbert / .gitattributes
Last active Mar 3, 2019
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (now works with Rails 5 and recent versions of Git). The following files should be in your home ~ directory. Inspired by https://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html
View .gitattributes
db/schema.rb merge=railsschema
View new-rails-app
#!/bin/bash
set -e
PROJECT_NAME=$1
main() {
display_logo
init_project
choose_branch
View spring.rb
class Spring::Watcher::Listen
def base_directories
%w(app config lib spec)
.map { |path| Pathname.new(File.join(root, path)) }
end
end
%w(
.ruby-version
.rbenv-vars
@jeromedalbert
jeromedalbert / .zshrc
Last active Jul 19, 2018
Remove branches just like git rebase --interactive
View .zshrc
gbDi() {
git branch --sort=-committerdate | remove-colors | egrep -v "master|\*" | cut -c3- > /tmp/branches && \
cp /tmp/branches /tmp/branches-to-keep && \
vim /tmp/branches-to-keep && \
comm -23 <(sort /tmp/branches) <(sort /tmp/branches-to-keep) | xargs 2> /dev/null git branch -D
}
remove-colors() {
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
}
@jeromedalbert
jeromedalbert / mixpanel_async_tracker.rb
Last active Jan 30, 2018
Make the Mixpanel gem work with Rails Active Job. Should work with any background job backend.
View mixpanel_async_tracker.rb
# Make Mixpanel work with Rails Active Job.
# Should work with any background job backend.
class MixpanelAsyncTracker < Mixpanel::Tracker
def initialize
super(ENV['MIXPANEL_TOKEN']) do |*message|
SendMessage.perform_later(message.to_json)
end
end
@jeromedalbert
jeromedalbert / gist:7476f445b7538b488c6ec34b5c4f3da4
Created May 28, 2016
Installing the Docker Toolbox on OS X with brew
View gist:7476f445b7538b488c6ec34b5c4f3da4
brew cask install dockertoolbox
docker-machine create --driver virtualbox default
docker-machine ls
eval $(docker-machine env default)
Put the exports in this eval in your .zshrc or .bashrc if you use bash
@jeromedalbert
jeromedalbert / .zshrc
Last active Apr 27, 2016
Ctrl-z In n Out
View .zshrc
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
View .eslintrc.js
module.exports = {
"env": {
"browser": true,
"es6": true,
"jquery": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
2,
@jeromedalbert
jeromedalbert / configure_osx.sh
Last active Feb 8, 2016
Configure OSX Yosemite with sensible defaults
View configure_osx.sh
# Disable the "Are you sure you want to open this application?" dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Disable press-and-hold for keys in favor of key repeat
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Set a fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 2
# Decrease the initial time before a keyboard repeat
@jeromedalbert
jeromedalbert / gist:5382169
Last active Apr 7, 2019
Different ways to return in Ruby
View gist:5382169
# Return statements are useless in snippets below, but they can help readability (highlight "end cases" of recursion)
# Order of preference : 3, 2/1, 4
# 1) Extra returns make it more obvious what is happening. Maybe a bit verbose
def decompose(n)
if n == 0
return []
elsif n == 1
return [1]
else
You can’t perform that action at this time.