Skip to content

Instantly share code, notes, and snippets.

View jeromedalbert's full-sized avatar
👨‍💻

Jerome Dalbert jeromedalbert

👨‍💻
View GitHub Profile
@jeromedalbert
jeromedalbert / configure_osx.sh
Last active February 8, 2016 00:04
Configure OSX Yosemite with sensible defaults
# 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
module.exports = {
"env": {
"browser": true,
"es6": true,
"jquery": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
2,
@jeromedalbert
jeromedalbert / .zshrc
Last active April 27, 2016 20:58
Ctrl-z In n Out
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
@jeromedalbert
jeromedalbert / .zshrc
Last active July 19, 2018 23:48
Remove branches just like git rebase --interactive
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 / spring.rb
Created September 27, 2018 18:48
config/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
#!/bin/bash
set -e
PROJECT_NAME=$1
main() {
display_logo
init_project
choose_branch
@jeromedalbert
jeromedalbert / gist:5332994
Created April 7, 2013 23:06
The different ways to define class methods in Ruby.
class MyClass
# All of these are equivalent
def self.myMethod
true
end
def MyClass.myMethod
true
end
@jeromedalbert
jeromedalbert / gist:5382169
Last active April 7, 2019 22:09
Different ways to return in Ruby
# 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
@jeromedalbert
jeromedalbert / mixpanel_async_tracker.rb
Last active March 1, 2020 13:18
Make the Mixpanel gem work with Rails Active Job. Should work with any background job backend.
# 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 / .rubocop.yml
Created November 3, 2020 03:56
Custom Rubocop rule to prevent unless with multiple conditions
require:
- ./.rubocop_custom_cops.rb
AllCops:
# ...