Skip to content

Instantly share code, notes, and snippets.

View mmozuras's full-sized avatar

Mindaugas Mozūras mmozuras

View GitHub Profile
@mmozuras
mmozuras / by_year.sh
Created November 8, 2019 09:53
Lines of code in a git repository by year
git ls-files |
while read f; do
echo $f > /dev/tty; git blame $f |
grep -o "\d\{4\}-";
done |
sort -f |
uniq -ic |
sort -n
@mmozuras
mmozuras / rename_to_date.sh
Created November 11, 2016 09:25
Rename JPG files to their creation dates
for i in *.jpg
do
jhead -n"%Y-%m-%d %H.%M.%S" $i
done
@mmozuras
mmozuras / benchmark_hash_access.rb
Created November 7, 2014 21:40
Benchmark hash access in Ruby: symbol versus string
require 'benchmark/ips'
string_hash = { 'aaa' => 1, 'bbb' => 2, 'ccc' => 3 }
symbol_hash = { aaa: 1, bbb: 2, ccc: 3 }
Benchmark.ips do |x|
x.report('string') { string_hash['bbb'] }
x.report('symbol') { symbol_hash[:bbb] }
x.compare!
@mmozuras
mmozuras / benchmark_includes.rb
Last active August 29, 2015 14:01
Benchmark various ways to write ==.*|| in Ruby
require 'benchmark/ips'
require 'set'
ARRAY = [:integer, :float, :decimal]
SET = ARRAY.to_set
type = :decimal
Benchmark.ips do |x|
x.report('array') { [:integer, :float, :decimal].include?(type) }
x.report('or') { type == :integer || type == :float || type == :decimal }
@mmozuras
mmozuras / largest_tables.sql
Created May 16, 2014 11:19
Largest tables in the database (change SCHEMA to your database name)
SELECT table_name, round(((data_length + index_length) / 1024 / 1024), 2) AS size
FROM information_schema.TABLES
WHERE table_schema = "SCHEMA"
ORDER BY size DESC LIMIT 20;
@mmozuras
mmozuras / git-trend.sh
Created May 14, 2014 18:48
Bash script to see how fixes are trending in current repo (per committer)
#!/bin/bash
for i in {0..24}
do
ii=$(($i + 1))
fixes=`git log --since="${ii} months ago" --until="${i} months ago" | grep -i fix | wc -l`
committers=`git log --since="${ii} months ago" --until="${i} months ago" --pretty=format:"%an" | sort -u | wc -l`
echo `bc -l <<< "${fixes} / ${committers}"`
@mmozuras
mmozuras / gist:6436306
Created September 4, 2013 12:32
irssi-xmpp instructions for Mac OSX

Installation

brew install irssi    
brew install loudmouth
git clone git@github.com:weiss/irssi-xmpp.git
cd irssi-xmpp
LDFLAGS='-flat_namespace -undefined warning -fPIC'; export LDFLAGS
make PREDIX=/usr/local/Cellar/irssi/0.8.15
make user-install
@mmozuras
mmozuras / gist:5972871
Created July 11, 2013 05:57
Bash function to convert a video to a gif
gifit() {
if [[ -n "$1" ]]; then
ffmpeg -i $1 -s 600x375 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=5 > $1.gif
else
echo "proper usage: gifit <input_movie.mov>"
fi
}
@mmozuras
mmozuras / gist:5597484
Last active December 17, 2015 10:49 — forked from spajus/gist:5213420
Delete all git tags locally and remotely based on their name length
for t in `git tag`
do
if [[ ${#t} -lt 20 ]]; then
echo keeping $t
else
git push origin :$t
git tag -d $t
fi
done
@mmozuras
mmozuras / gist:5476751
Created April 28, 2013 12:30
Filter VilniusJS attendees emails
lines = File.readlines('vilniusjs_emails')
result = []
remove = false
lines.each do |line|
if line.strip.empty?
remove = true
end