Skip to content

Instantly share code, notes, and snippets.

View sflinter's full-sized avatar

Steve Flinter sflinter

View GitHub Profile
@sflinter
sflinter / queue.rb
Last active December 12, 2015 07:49
class Queue
def initialize
@head = HeadNode.new
end
def size
find_size(@head)
end
def push(object)
require 'test/unit'
require './queue'
class TestQueue < Test::Unit::TestCase
def setup
@q = Queue.new
end
def test_should_create_a_new_queue
assert @q
@sflinter
sflinter / en-setdate.rb
Created November 24, 2012 19:39
Update the creation date on all Evernote notes to match the date in their title
#!/usr/local/bin/macruby
# Update the creation date on all Evernote notes to match the date in their title
# The date format in the title must be 'yyyymmdd'
# Requires macruby to run
require 'date'
require 'optparse'
framework "ScriptingBridge"
@sflinter
sflinter / Reset creation date
Created November 17, 2012 12:49
Reset the creation date a bunch of files (PDFs in this case) based on a spotlight comment (of the form 'yyyymmdd')
for f in *.pdf ; do new=$(mdls -name kMDItemFinderComment $f -raw) ; touch -t ${new}0000 $f; echo $f ; done
@sflinter
sflinter / en_script.rb
Created April 2, 2012 22:08
Update the creation date on Evernote notes based on their title
#!/usr/local/bin/macruby
# Update the creation date on all Evernote notes to match the date in their title
# The date format in the title must be 'yyyymmdd'
# Requires macruby to run
require 'date'
require 'optparse'
framework "ScriptingBridge"
@sflinter
sflinter / search-replace.rb
Created January 20, 2011 22:53
Perform an in-place (with backup) global search and replace on one or more files
# Perform an in-place (with backup) global search and replace on one or more files
$ ruby -i.bak -ple '$_.gsub!(/..../, "::::")' *
# Replace the ... with the regular expression that you're searching for,
# and the ::: with what you want to replace it with.
# Replace the file glob with whatever is appropriate.
@sflinter
sflinter / dos2unix.rb
Created January 20, 2011 22:47
A simple ruby command-line script to convert DOS ending files ('\r\n') to UNIX ending ones ('\n')
# Convert all files (*) from DOS endings to UNIX endings, and create a back-up of each
ruby -i.bak -ple '' *
@sflinter
sflinter / ack.rb
Created January 20, 2011 00:26
A ruby clone of ack (http://betterthangrep.com/) that uses Ruby multiline regexps.
#!/usr/bin/env ruby
require 'find'
usage = <<EOF
Usage: ack.rb <regexp> <directory or filename>
The regular expression can be across multiple lines, and is _not_ escaped by default.
For example:
ack.rb 'end\\nend' .
will find all files in the current directory that have two 'end' statements across two lines
@sflinter
sflinter / erblint.rb
Created January 20, 2011 00:01
This is a simple program that reads in a Ruby ERB file, and parses it as an XHTML file. Specifically, it makes a decent attempt at converting the ERB tags (<% %> and <%= %>) to XML tags (<erb-disp/> and <erb-eval/> respectively. Once the document has b
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
# This is a simple program that reads in a Ruby ERB file, and parses
# it as an XHTML file. Specifically, it makes a decent attempt at
# converting the ERB tags (<% %> and <%= %>) to XML tags (<erb-disp/>
# and <erb-eval/> respectively.
#