Skip to content

Instantly share code, notes, and snippets.

require 'logger'
class String
LOGGER = Logger.new($stderr)
def -@; LOGGER.info self; end
end
# Extracted earlier, hardcoded for speed
ENTITIES = %w(I-ORG O I-MISC I-PER I-LOC B-LOC B-MISC MO B-ORG)
#!/usr/bin/env macruby
framework 'cocoa'
loop do
puts NSWorkspace.sharedWorkspace.activeApplication['NSApplicationPath']
sleep 1
end
#!/usr/bin/env ruby
# gem install colored
require 'colored'
features = []
Dir['{rec.sport.hockey,talk.politics.guns}/*'].each do |filename|
puts "Extracting features for #{filename.blue.bold}"
begin
# I'm just working on a quick script...
true_positives = ...
false_negatives = ...
# Using printf debugging I'd normally do this
p true_positives
p false_negatives
@chrislloyd
chrislloyd / control.coffee
Created March 19, 2011 12:37
Watch out for all the code BTW, this is a hack job.
delay = (ms, fn) ->
setTimeout fn, ms
Array::max = ->
max = @[0];
for elm in @ when elm > max
max = elm
max
class NSResponder
def acceptsFirstResponder= val
(@acceptsFirstResponder = val).tap do
instance_eval do
def acceptsFirstResponder
@acceptsFirstResponder
end
self
end
# Kup. A small all-coffee template language with a syntax like css
#
# Based on:
# * CoffeeKup - https://github.com/mauricemach/coffeekup
# * jQuery Builder - https://github.com/quackingduck/jquery.builder.js
# TODO:
# * stricter regex for tags
# The compiler, takes your template and returns a compiled one
@chrislloyd
chrislloyd / core_ext.rb
Created February 23, 2011 13:51
A few handy snippets when working with MacRuby.
class Symbol
def to_selector
"#{self}:".to_sym
end
end
class NSObject
require 'rake/clean'
CLOBBER.add *File.read('.gitignore').split
require 'parslet'
tree = {:multi=>
[{:tag=>{:name=>"Foo"}},
{:block=>{:name=>"Foo", :multi=>[{:static=>"Bar"}]}}]}
transformer = Parslet::Transform.new do
rule :static => simple(:text) do
'STATIC'