Skip to content

Instantly share code, notes, and snippets.

View darktef's full-sized avatar
🐳
Hacking

Lin Yang darktef

🐳
Hacking
View GitHub Profile
@darktef
darktef / get-all-az.bash
Created August 16, 2022 15:17
AWS - Get all AZs for the subnet
typeset -A newmap
newmap[111111111111]="IAD-Alpha"
newmap[222222222222]="IAD-Beta"
# echo ${newmap[111111111111]}
# for key ("${(@k)newmap}") printf 'key=%s value=%s\n' "$key" "$newmap[$key]"
for key ("${(@k)newmap}")
@darktef
darktef / run_rake_tasks_console.md
Created February 21, 2019 20:51
RoR - How to run rake tasks from console
@darktef
darktef / benchmark.rb
Created February 20, 2019 14:09
RoR - benchmark ActiveRecord Query
require 'benchmark'
n = 5 # Use any n you like
Benchmark.bmbm do |x|
x.report("find by") {
n.times { User.find_by_name("Joe").id }
}
x.report("select") {
n.times { User.find(:first, :select => :id, :conditions => ["name = ?","Joe"]).id }
}
find . -type d -not -empty -exec echo mv \{\}/README.md \{\}.md \;
# This is to preview the command first with echo
find . -type d -empty -print # to show the folder to be deleted
find . -type d -empty -delete # to delete the empty folder
# https://unix.stackexchange.com/questions/46322/how-can-i-recursively-delete-empty-directories-in-my-home-directory
mv myfolder/* .
# move the folder content one level up
@darktef
darktef / commit_history.rb
Last active September 20, 2018 20:23
Ruby - Grab the commit history of all related files
results = []
file_names = `find . -print | grep '.*referral.*'`.split("\n");nil
file_names.each do |name|
output = `git log --follow --pretty=format:'{"commit": "%H","author": "%aN <%aE>","date": "%ad","message": "%f"},' -- #{name}`
results.concat(JSON.parse('[' + output.gsub("\n", '')[0..-2] + ']'))
end
mapping = {}
results.each do |res|
@darktef
darktef / gist:d985a0452d774aa6702f3bae43e5ccab
Created August 8, 2018 17:08
Bash - Open multiple files from previous git log history
mvim -p $(git log --pretty="" --name-only -1 | tr -s '\n' ' ')
@darktef
darktef / gist:4f0fae5edf41764c7eff34ff5e71c47f
Created April 16, 2018 03:05
Convert pdf to image with ImageMagick
convert -density 300 bujo_MondayStart_Duplex_marriedtotheearth.pdf bullet_journal.png
/* ref: http://stackoverflow.com/questions/3331353/transitions-on-the-display-property */
div > ul {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
div:hover > ul {
visibility: visible;
opacity: 1;
@darktef
darktef / gist:5aa7a9261e15470eb0cf83693a06ee93
Last active December 31, 2016 04:02
Fish - fetch all git branches
for remote in (git branch -r | grep -v HEAD)
// remove the origin/
set bran (string replace -r 'origin\/' '' $remote)
// remove the left trailing white spaces
set br (string trim -l $bran)
set r (string trim -l $remote)
// create branch local to track the origin/branch
git branch --track $br $r
end
@darktef
darktef / gist:21ff4890089631db91649ea1c24a7ed1
Created November 7, 2016 04:56
Fish - move files in parent folder to child folder
find . -maxdepth 1 -type f -exec mv '{}' ./wk1/ \;
// it seems like no -t available in fish Shell and Mac...