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 / mac-randomize.sh
Last active August 29, 2015 13:55
Randomize MAC address (e.g. unlimited wifi access on airports)
#!/bin/bash
set -e
current_mac() {
ifconfig en0 ether | awk '/ether / { print $2 }'
}
current_mac_wifi() {
networksetup -getmacaddress Wi-Fi | awk '{ print $3 }'
}
@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 / .gitconfig
Created January 30, 2015 22:06
My pristine git config
[user]
name = Mislav Marohnić
email = mislav.marohnic@gmail.com
[color]
ui = true
[push]
default = simple
@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"