Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
#
# Put this script in your PATH and download from onemanga.com like this:
# onemanga_downloader.rb Bleach [chapter number]
#
# You will find the downloaded chapters under $HOME/Documents/OneManga/Bleach
#
# If you run this script without arguments, it will check your local manga downloads
# and check if there are any new chapters
#
@ggarnier
ggarnier / tga-to-jpg.sh
Created December 10, 2010 13:34
Batch conversion from tga to jpg
#!/bin/bash
# Batch conversion from tga to jpg
# Author: Guilherme Garnier - http://blog.guilhermegarnier.com
# Adapted from:
# http://linux.strangegamer.com/index.php?title=Converting_A_directory_of_TGA%27s_To_JPG
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
@ggarnier
ggarnier / gist:1158192
Created August 19, 2011 22:25
Remove undesired audio tracks from a video file
# extracted from http://superuser.com/questions/56093/remove-audio-stream-from-xvid-files
# replace -aid value with the audio track number you wish to keep
mencoder orig.avi -o new.avi -oac copy -ovc copy -aid 1
@ggarnier
ggarnier / check-git-status.sh
Created June 11, 2013 22:36
Checks the status for all my git projects
#!/bin/bash
# check-git-status.sh - Checks the status for all my git projects
# Usage: check-git-status.sh <main projects directory>
if [ -z "$1" ]; then
mainDir="$HOME/Projects"
else
mainDir="$1"
fi
@ggarnier
ggarnier / private.js
Last active December 25, 2015 16:39
Javascript private functions
// Reference: http://javascript.crockford.com/private.html
Test = function() {
function private() {
return "private";
}
return {
public: function() {
return private();
}
@ggarnier
ggarnier / ordering.rb
Created November 21, 2013 18:03
Ordering an array in Ruby using 2 sorting criterias
# Ordering a list by field1 in descending order. If two elements have the same value, order by field2 in ascending order
list.sort do |a, b|
comp = (b.field1 <=> a.field2)
comp.zero? ? (a.field2 <=> b.field2) : comp
end
@ggarnier
ggarnier / html2markdown.rb
Created December 18, 2013 14:46
html2markdown
text.gsub(/<a href="([^"]*)">([^<]*)<\/a>/, '[\2](\1)')
@ggarnier
ggarnier / add_date_to_posts.rb
Created February 4, 2014 21:30
Add date to Octopress posts
Dir.glob("source/_posts/*.markdown").each do |filename|
formatted_date = filename.split("/").last[0..9]
puts "Adding date #{formatted_date} to file #{filename}"
lines = []
IO.readlines(filename).map do |line|
lines << line
lines << "date: #{formatted_date}" if line =~ /^title: /
end
@ggarnier
ggarnier / class_variables.rb
Last active August 29, 2015 13:56
Class variables and class instance variables in Ruby
class Superclass
@@var1 = "var 1 Superclass"
@var2 = "var 2 Superclass"
def self.var1
@@var1
end
def self.var2
@var2
@ggarnier
ggarnier / sum_time_shares.rb
Last active August 29, 2015 13:57
Calculates sum of a list of time shares in format min:sec
# str = "1:42 + 07:48"
# output = "9:30"
def sum_time_shares(str)
values = str.gsub(" ", "").split("+")
total_seconds = values.reduce(0) do |sum, value|
minutes, seconds = value.split(":")
sum += (60 * minutes.to_i) + seconds.to_i
end