Skip to content

Instantly share code, notes, and snippets.

@esebastian
esebastian / git-subdir
Created July 5, 2014 18:18
Move the current git working tree into a subfolder
#!/bin/sh
# Move the current working tree into a subfolder.
#
# This will rewite all branches and tags, so this should not
# be performed on a repo that has been shared with others, because it
# will force them to reset their history.
#
# Use at your own risk.
#
# Put the script in your path and invoke it this way:
@esebastian
esebastian / setenv
Last active August 29, 2015 14:04
Load environment variables from '.env' into the current shell session
# execute on the prompt or define it as a shell function
for i in `cat .env`; do
export $i
done
@esebastian
esebastian / unsetenv
Created July 26, 2014 10:17
Unload environment variables in '.env' from the current shell session
# execute on the prompt or define it as a shell function
for i in `cat .env`; do
unset `echo $i | cut -f 1 -d "="`
done
@esebastian
esebastian / list-extensions
Created September 3, 2014 11:24
Print the list of different extensions from the files in a folder and its subfolders
find . -type f -name '*.*' | sed 's|.*\.||' | sort -u
@esebastian
esebastian / find-xml
Created September 4, 2014 18:06
Find XML files, recursive
find . -print | grep -i '.*[.]xml'
@esebastian
esebastian / fix-srt-names
Last active March 6, 2019 19:37
Mass rename TV show SRT files to match the MKV ones
for i in `ls *.mkv`; do [[ $i =~ [sS]([0-9]{2})[eE]([0-9]{2}) ]] && mv *${BASH_REMATCH[1]}x${BASH_REMATCH[2]}*.srt ${i%????}.srt 2> /dev/null; done
@esebastian
esebastian / git_alias_complete()
Created September 9, 2014 07:44
Allow git completion for a custom alias
# see: https://askubuntu.com/questions/62095/how-to-alias-git-to-g-so-that-bash-completion-rules-are-preserved/62098#62098
git_alias_complete()
{
alias='g'
complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
|| complete -o default -o nospace -F _git $alias
}
@esebastian
esebastian / ocr.rb
Created January 11, 2016 21:12
WIP - Katayuno - Bank OCR
class OCR
OCR_MAP = {
" _ | ||_|" => 0,
" | |" => 1,
" _ _||_ " => 2,
" _ _| _|" => 3,
" |_| |" => 4,
" _ |_ _|" => 5,
" _ |_ |_|" => 6,
" _ | |" => 7,
@esebastian
esebastian / event_slug_generator.rb
Last active March 27, 2016 19:02
VLCTechHub: event collection `created_at` and `slug` generator
require 'dotenv'
require 'uri'
require 'mongo'
require 'active_support/inflector'
Dotenv.load
def format_uri(uri)
index = (uri =~ /@/)
index = (uri =~ /\/{2}/) + 1 unless index
@esebastian
esebastian / event_slug_printer.rb
Created March 27, 2016 11:01
VLCTechHub: event collection `created_at` and `slug` reporter
require 'dotenv'
require 'uri'
require 'mongo'
Dotenv.load
def format_uri(uri)
index = (uri =~ /@/)
index = (uri =~ /\/{2}/) + 1 unless index
uri[index+1..-1]