Skip to content

Instantly share code, notes, and snippets.

View mislav's full-sized avatar

Mislav Marohnić mislav

View GitHub Profile
@mislav
mislav / detect_encoding.sh
Created January 31, 2014 00:29
Detect encoding of file contents (or STDIN) with charlock_holmes
ruby -r pp -r charlock_holmes -e '
contents = ARGF.read
detection = CharlockHolmes::EncodingDetector.detect(contents)
pp detection ' "$@"
@mislav
mislav / watch.rb
Created January 31, 2014 00:45
Track filesystem changes on a lower level with Guard
require 'guard'
listener = Guard::Listener.select_and_init '/',
:relativize_paths => false,
:ignore_paths => ['Caches', 'Saved Application State']
listener.on_change do |files|
p files
end
@mislav
mislav / h264.sh
Last active August 29, 2015 13:55
ffmpeg wrapper script to transcode select portions of original file as h264. WARNING: I have no idea what I'm doing [insert dog meme here]
#!/bin/bash
# Usage: h264 <infile> <HH:MM:SS-HH:MM:SS> [<outfile>]
set -e
infile="$1"
fromto="$2"
if [ -n "$3" ]; then
outfile="$3"
else
@mislav
mislav / backfill-releases.sh
Created February 5, 2014 17:37
Script to migrate releases from CHANGELOG.md to GitHub Releases
#!/bin/bash
# Usage: OAUTH_TOKEN="..." backfill-releases CHANGELOG.md [<project-title>]
set -e
log="${1?}"
project_name="${2}"
repo="$(git config remote.origin.url | grep -oE 'github\.com[/:][^/]+/[^/]+' | sed 's/\.git$//' | cut -d/ -f2-3)"
[ -n "${project_name}" ] || project_name="${repo#*/}"
@mislav
mislav / diff-gems.rb
Created October 29, 2014 20:35
Script to diff contents of gems vendored in `vendor/cache` between branches
#!/bin/bash
# Usage: diff-gems <branch>
#
# Shows diff between unpacked cached gems that changed on a branch.
set -e
branch="${1?}"
base_branch="origin/master"
merge_base="$(git merge-base "$base_branch" "$branch")"
@mislav
mislav / port-finder.rb
Last active August 29, 2015 14:10
Check if TCPServer's port-finding ability is safe with parallelism via fork
# ruby port-finder.rb | cut -f1 -d: | sort -n | uniq -c
#
# Verdict: it seems to be safe on Mac OS X, but it's *not safe* on Linux,
# where causal testing confirms that two subprocesses could pick the same port.
require 'socket'
module PortFinder
def self.call
server = TCPServer.new('127.0.0.1', 0)
@mislav
mislav / index.html.erb
Created August 4, 2008 15:03
Group paginated messages by day
<h1>Last activity</h1>
<% for day, messages in @messages_by_day -%>
<h2><%= day %></h2>
<ol>
<%- for message in messages -%>
<li><%= link_to message.title, message %></li>
<%- end -%>
</ol>
<% end -%>
@mislav
mislav / Gemfile
Last active August 29, 2015 14:18 — forked from janko/benchmark.rb
source "https://rubygems.org"
gem "minitest"
gem "rspec"
@mislav
mislav / license-audit.sh
Created June 25, 2015 00:41
Simple tool to do rudimentary dependency license auditing using Licensee library.
#!/bin/bash
# Usage: license-audit [<project-dir>]
#
# Scans gems from the current project's bundle, Bower components and npm
# packages, and prints their license.
#
# Requires:
# - licensee >= 4.5.0
# - ruby with Bundler (for Gemfiles)
set -e
@mislav
mislav / gist:8920
Created September 5, 2008 04:08
a utility to execute commands entered in the console in several git repositories at once
#!/usr/bin/env ruby
# for each git repo in a subdirectory ...
dirs = Dir['**/.git'].map { |gd| File.dirname(gd) }
def prompt
print ">> "
gets
end
# ... execute a command given on STDIN