cd /path/to/dir
shopt -s nullglob
for file in *.{avi,rmvb,mkv}
do
directory="${file%.*}" # remove file extension
directory="${directory//_/ }" # replace underscores with spaces
darr=( $directory )
darr="${darr[@]^}" # capitalize the directory name
echo mkdir -p -- "$darr" # create the directory;
echo mv -b -- "$file" "$darr" # move the file to the directory
echo
done
Month: November 2016
Duplicity bash script to restore data from S3
Restore your S3 duplicity backup
#!/bin/bash
if [ $# -lt 3 ] || [ $# -gt 3 ]; then
echo 'invalid number of parameters passed'
echo 'Usage: s3-restore <bucket-name> <folder-name> <output-folder>'
else
echo 'restoring backup'
export PASSPHRASE=your_passphrase
export AWS_ACCESS_KEY_ID=your_aws_access_key
export AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
duplicity s3://s3.amazonaws.com/$1/$2 $3
fi
Backup to S3 using duplicity
Backup a directory to S3. The script make full backups every 30 days and incremental backups the rest of the time.
#!/bin/bash
if [ $# -lt 3] || [ $# -gt 3]; then
echo 'invalid number of parameters'
echo 'Usage: backup <folder-to-backup> <bucket-name> <folder-name>'
else
echo 'starting backup'
export PASSPHRASE=your_passphrase
export AWS_ACCESS_KEY_ID=your_aws_access_key
export AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
duplicity --extra-clean --full-if-older-than 1M $1 s3://s3.amazonaws.com/$1/$2
fi
JavaScript boilerplate file
var App = function() {
var debug = true;
var self = this;
/**
* Initializing app on document ready
* or device ready in case of PhoneGap
*
* @returns {App}
*/
this.init = function() {
self.settings();
self.events();
return this;
};
/**
* Setting various variables and making
* some DOM changes
*/
this.settings = function() {
};
/**
* Binding events
*/
this.events = function() {
};
return this;
};
Image under text in an HTML email
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body style="font-family: 'Myriad Pro', sans-serif;font-size: 16px;font-weight: 400;color: #252525;"> <table style="width: 100%;max-width: 600px;margin: 0 auto;"> <tr style="width: 100%;height: 0;"> <td></td> <td rowspan="2"> <img src="http://images5.fanpop.com/image/photos/30800000/-Random-random-30843841-1920-1080.jpg" alt="Background"> </td> </tr> <tr> <td colspan="2" style="vertical-align: top;padding-top: 27px;"> <table style="width: 100%;"> <tr> <td>Some purely random text</td> </tr> </table> </td> </tr> </table> </body> </html>
Styling a radio box with CSS
the CSS:
label { display: inline-block; cursor: pointer; position: relative; padding-left: 25px; margin-right: 15px; font-size: 13px; } input[type=radio] { display: none; } label:before { content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 10px; position: absolute; left: 0; bottombottom: 1px; background-color: #aaa; box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8); } input[type=radio]:checked + label:before { content: "\2022"; color: #f3f3f3; font-size: 30px; text-align: center; line-height: 18px; } .radio label:before { border-radius: 8px; }
the HTML
<div class="radio"> <input id="male" type="radio" name="gender" value="male"> <label for="male">Male</label> <input id="female" type="radio" name="gender" value="female"> <label for="female">Female</label> </div>
JavaScript Preload Images
var images = []; var images_to_preload = [ 'path/to/image/one', 'path/to/image/two' ]; function preload(images_list) { for (var i = 0; i < images_list.length; i++) { images[i] = new Image(); images[i].src = images_list[i]; } } preload(images_to_preload);
My bashrc file
# Bash colouring PS1="\[\033[0;33m\]\u\[\033[0m\]\[\033[0;32m\]@\h\[\033[0m\] \[\033[0;35m\]\w\[\033[0m\]\[\033[0;31m\]>\[\033[0m\] " # Start tmux if it's screen : ) if [[ ! $TERM =~ screen ]]; then exec tmux fi # Aliases alias v="vim" alias art="php artisan" alias gita="git add -A" alias gits="git status" alias gitc="git commit -m "
My bash_profile file
# include the .bashrc file if [ -f ~/.bashrc ]; then . ~/.bashrc # read ~/.bashrc, if present. fi
Deleting a file permanently from a git branch
git filter-branch --tree-filter 'rm -rf /path/to/file/or/folder' HEAD