Skip to content

Instantly share code, notes, and snippets.

View petitJAM's full-sized avatar
🤖
beep boop Androids

Alex Petitjean petitJAM

🤖
beep boop Androids
View GitHub Profile
@petitJAM
petitJAM / Cheat Sheet.md
Last active March 11, 2019 19:26
Rails Migration Cheat Sheet

Rails Migration Cheat Sheet

rails generate migration

rails g migration add_x_column_to_y_table name:type name2:type2[:index]

rails g migration create_x_table name:type

Columns

@petitJAM
petitJAM / gradle_functions.md
Last active November 27, 2017 17:15
Gradle - Build Time / Git Hash

build.gradle

apply from: 'functions.gradle'

...

buildConfigField 'String', 'GIT_HASH', "\"${gitHash()}\""
buildConfigField 'String', 'BUILD_TIME', "\"${buildTime()}\""
@petitJAM
petitJAM / letelse.kt
Last active September 14, 2021 20:53
Kotlin `let` `else`
val foobar: Foobar? = ...
foobar?.let { /* foobar is not null */ } ?: run { /* foobar is null */ }
// this might be cool except for the back ticks `
fun <T, R> T.`else`(block: T.() -> R) = run(block)
foobar?.let { /* foobar is not null */ } ?: `else` { /* foobar is null */ }
# make CapsLock behave like Ctrl:
setxkbmap -option ctrl:nocaps
# make short-pressed Ctrl behave like Escape:
xcape -e 'Control_L=Escape'
@petitJAM
petitJAM / postman_update.sh
Last active February 21, 2018 16:00
Small script for updating Postman
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
rm postman.tar.gz
sudo ln -sf /opt/Postman/Postman /usr/bin/postman
cat > ~/.local/share/applications/postman.desktop <<EOL
[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=postman
@petitJAM
petitJAM / .tmux.conf
Created February 22, 2018 16:53
Reload tmux conf
bind R source-file ~/.tmux/reload.tmux
@petitJAM
petitJAM / linux+androidstudio.md
Created March 5, 2018 17:26
Linux + Android Studio

Adb

sudo apt remove adb

Add the following to ~/.bashrc

export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/tools
@petitJAM
petitJAM / rails_g_controller.md
Last active March 16, 2018 17:02
Rails generate api controller
rails g controller api/v6/controller_name create --no-helper --skip-template-engine --skip-routes
mkdir spec/requests/api/v6/controller_name
mv spec/controllers/api/v6/controller_name.rb spec/requests/api/v6/controller_name/
@petitJAM
petitJAM / .tmux.conf
Created March 19, 2018 18:06
tmux on Mac
# Enables mouse
set -g mouse
set-window-option -g mode-keys vi
# CPU Status
set -g status-interval 1 # second
set -g status-right "#{prefix_highlight} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M "
# Sync Panes Status
@petitJAM
petitJAM / with_active_support.rb
Created March 20, 2018 22:07 — forked from mbyczkowski/with_active_support.rb
session cookie decrypter for Rails 4.2+
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)[0, ActiveSupport::MessageEncryptor.key_len]