Skip to content

Instantly share code, notes, and snippets.

View rastamhadi's full-sized avatar
🇲🇾

Rastam Hadi rastamhadi

🇲🇾
View GitHub Profile
@rastamhadi
rastamhadi / bookmarklet.js
Created November 15, 2023 08:25
Copy Link Bookmarklet
javascript: setTimeout(() => {
const url = location.href.replace(/#.+$/, "");
let title = document.title.replace(/^[0-9]+\. /, "");
if ("github.com" === location.host) {
title = title.replace(/ by .+?$/, "");
} else if ("docs.google.com" === location.host) {
title = title.replace(/ - Google .+?$/, "");
}
@rastamhadi
rastamhadi / freee.js
Last active February 2, 2023 10:14
How much longer do I have to work this month?
// ==UserScript==
// @name How much longer do I have to work this month?
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Calculates the number of hours you need to work for the rest of the month
// @author Rastam Hadi
// @match https://p.secure.freee.co.jp/
// @icon https://www.google.com/s2/favicons?sz=64&domain=freee.co.jp
// @grant none
// ==/UserScript==
@rastamhadi
rastamhadi / user.rb
Created November 16, 2018 06:46
Null Objects
class User < ActiveRecord::Base
# Inner classes FTW!
class Null
def name
nil
end
end
# If you have a more meaningful class name then by all means!
class Guest
@rastamhadi
rastamhadi / initializer.rb
Last active November 16, 2018 06:45
Hacking ActiveModelSerializers to serialize Null Objects
ActiveModelSerializers.config.serializer_lookup_chain.unshift(
lambda do |resource_class, serializer_class, namespace|
# Maps Foo::Bar to FooSerializer
parent_module_name = resource_class.name.deconstantize
[serializer_class, namespace].map do |m|
"#{m}::#{parent_module_name}Serializer"
end
end
)
@rastamhadi
rastamhadi / .bash_profile
Last active August 16, 2023 08:07
My .bash_profile
eval "$(rbenv init -)"
export EDITOR="/usr/local/bin/sublime -n -w"
# The next line updates PATH for the Google Cloud SDK.
source '/Users/rastam/google-cloud-sdk/path.bash.inc'
# The next line enables bash completion for gcloud.
source '/Users/rastam/google-cloud-sdk/completion.bash.inc'
# SSH host selector
@rastamhadi
rastamhadi / .gitconfig
Last active February 27, 2024 08:34
Git configurations
[alias]
padd = "!f() { git add $(git status -s | grep -v '^M' | cut -c4- | peco); }; f"
pdiff = "!f() { git diff $(git status -s | grep -v '^M' | cut -c4- | peco); }; f"
peach = "!f() { ~/bin/peach.sh }; f"
undo = "!f() { git checkout -- $(git status -s | grep '^ ' | cut -c4- | peco); }; f"
unstage = "!f() { git reset HEAD $(git status -s | grep -v '^[ ?]' | cut -c4- | peco); }; f"
localprune = "!f() { ~/bin/localprune.sh; }; f"
pr = "!f() { ~/bin/pr.sh; }; f"