Skip to content

Instantly share code, notes, and snippets.

View cyberfox's full-sized avatar

Morgan Schweers cyberfox

View GitHub Profile
@cyberfox
cyberfox / whazzup.rb
Created January 5, 2011 01:43
Asks for status every 15-25 minutes to track where time goes. Traps USR2 to wake and prompt for status. Designed for Linux, works on OS X, needs tweaks for Windows. Uses JRuby, since it's the only easy-to-get cross-platform UI toolkit for Ruby.
require "java"
java_import javax.swing.JOptionPane
class Whazzup
def initialize(file = "#{ENV['HOME']}/snippets.txt")
@snippets ||= open(file, 'ab')
log('[Starting up (ruby)]')
thread_loop = Thread.current
@cyberfox
cyberfox / stable_sort_example.rb
Created January 31, 2011 09:56
Showing unstable and stable sorting in Ruby.
# This example is flawed, but hopefully useful for demonstration purposes.
def test_stable_sorting
ary = (1..100).to_a.shuffle + (1..100).to_a.shuffle
# This associates an ordering with the randomized numbers
idx = 0
paired = ary.collect {|value| [value, idx += 1]}
puts "Now the numbers are paired; the first is the random number 1-100,"
puts "the second is its sequence within the 200 entries."
puts paired.inspect
@cyberfox
cyberfox / drag_drop.rb
Created February 4, 2011 02:41
Drag and drop destination setup using MacRuby
class TableViewDataSource
def awakeFromNib
view.registerForDraggedTypes(
NSArray.arrayWithObjects("BookmarkDictionaryListPboardType", "MozURLType",
NSFilenamesPboardType, NSURLPboardType, NSStringPboardType, nil))
end
def tableView(aView, validateDrop:info, proposedRow:row, proposedDropOperation:op)
NSDragOperationEvery
end
@cyberfox
cyberfox / auction_table_datasource.rb
Created February 9, 2011 08:55
MacRuby example of using Core Data to search for Category objects
class AuctionTableDatasource
attr_writer :app_delegate
attr_accessor :view
.
.
.
def set_selected_category(category_name)
context = @app_delegate.managedObjectContext
@current_category = Category.find_first(context, by_name:category_name)
@cyberfox
cyberfox / Category.h
Created February 9, 2011 09:00
All the code necessary to find a Category object by name in Objective C
#import <CoreData/CoreData.h>
#import "FindableData.h"
@interface Category : FindableData
{
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSSet *auctions;
@property (nonatomic, retain) NSNumber *auctionCount;
require 'inheritable_attrs'
class Entity < NSManagedObject
class_inheritable_accessor :entity_name
self.entity_name = 'Entity'
def self.inherited(sub)
sub.entity_name = sub.to_s
end
# Based off of Rails, by way of http://www.raulparolari.com/Rails/class_inheritable
class Class
def class_inheritable_reader(*syms)
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}
read_inheritable_attr(:#{sym})
end
EOS
@cyberfox
cyberfox / Gemfile
Created February 23, 2011 01:16
Gemfile from my project that is having NewRelic RPM/DelayedJob issues
source 'http://rubygems.org'
gem 'rails', '3.0.3'
# Edit this Gemfile to bundle your application's dependencies.
# This preamble is the current preamble for Rails 3 apps; edit as needed.
gem 'mysql'
gem 'delayed_job'
gem 'unicorn'
@cyberfox
cyberfox / TableDelegate.rb
Created February 27, 2011 09:22
An NSTableView delegate with a yellow flash effect
# TableDelegate.rb
#
# An example of capturing double-clicks and a yellow-fade technique in MacRuby.
# The yellow fade technique implementation is a ruby-ized translation
# of http://www.bdunagan.com/2009/04/26/core-animation-on-the-mac/
# Created by Morgan Schweers on February 26, 2011.
framework 'Cocoa'
class TableDelegate
@cyberfox
cyberfox / Move JBidwatcher files around.sh
Created April 11, 2011 22:16
Copy and paste these commands one at a time into Terminal.app (while JBidwatcher is NOT running!) and then relaunch 2.1.5.
mv ~/Library/Preferences/JBidwatcher/jbdb ~/Library/Preferences/JBidwatcher/jbdb.save
mv ~/.jbidwatcher/jbdb ~/Library/Preferences/JBidwatcher/jbdb