Skip to content

Instantly share code, notes, and snippets.

@sck
sck / gist:3965569
Created October 27, 2012 18:15
Image character separation
i = Import["http://i.stack.imgur.com/Ta5wf.png"]
ws = WatershedComponents[i];
ColorCombine[{Image[ws, "Bit"], i, i}]
ImageTake[i, Sequence @@ Reverse@Transpose@Last[#]] & /@ ComponentMeasurements[ws, "BoundingBox"]
@sck
sck / autosshscreen.rb
Created September 13, 2012 09:25
Simple autossh + screen
#! /usr/bin/env ruby
# autosshscreen
# Simple autossh + screen
# USAGE: autosshscreen <SSH_OPTIONS> <user@host>
#
# Calculates the autossh ECHO port automatically for you (random number)
# and executes 'screen -x' on the host
#
# EXAMPLES
# autosshscreen name@host
@sck
sck / free.c
Created August 23, 2012 18:19
Show free memory on OS X
/*
* free.c - show free memory on OS X
* The api query code was extraced from Apple's vm_stat.c
* To compile: gcc -o free free.c
* Output: <byte count> <human readable bytecount>
*/
#include <stddef.h>
#include <stdlib.h>
@sck
sck / makeAnyPdfSearchable.rb
Created June 24, 2012 11:23
Use ScanSnap's 'Scan to Searchable PDF' even with PDFs not created by ScanSnap
#! /usr/bin/env ruby
require 'tmpdir'
def fixed?(fn) fn =~ /\.searchable\.pdf/; end
def searchable_fn(fn)
return fn if fixed?(fn)
"#{File.dirname(fn)}/#{File.basename(fn, File.extname(fn))}.searchable.pdf"
end
@sck
sck / convertPdfsToText.rb
Created May 31, 2012 20:15
Convert all pdfs to text
#! /usr/bin/env ruby
require 'fileutils.rb'
$home=ENV['HOME']
$documents="#{$home}/Documents"
$already_tried_index="#{$documents}/already_tried_files.txt"
def does_pdf_file_contain_text?(fn)
text=`pdftotext #{fn.inspect} /dev/stdout`
@sck
sck / fixAdobeCaseInsensitivePaths.rb
Created April 28, 2012 16:56
Reads DTrace output to fix Adobe's filenames on OS X with case-sensitive volumes
#! /usr/bin/env ruby
# About
#
# This program tries to fix Adobe's issues with case-sensitive volumes by
# using DTrace to log which files cannot be opened and then trying to
# generate a shell script which will rename the files to the names as
# Adobe wants them.
#
# USAGE: