Skip to content

Instantly share code, notes, and snippets.

View cyberfox's full-sized avatar

Morgan Schweers cyberfox

View GitHub Profile
@cyberfox
cyberfox / keychain.rb
Created September 18, 2011 06:03
Convert OS X Keychain exported entries into logins for 1Password import
#!/usr/bin/env ruby
#
# Usage:
# security dump-keychain -d login.keychain > keychain_logins.txt
# # Lots of clicking 'Always Allow', or just 'Allow', until it's done...
@cyberfox
cyberfox / champagne.rb
Created January 27, 2012 09:14
Champagne Solution
if ARGV[0].nil?
puts "Usage:\n\truby #{__FILE__} {bad bottle#|test}"
exit
end
def guess_bottle(bad_bottle, silent=false)
waiters = []
(0..9).each do |waiter_number|
waiters[waiter_number] = []
(0..999).each do |bottle|
@cyberfox
cyberfox / canvas_test.html
Created May 4, 2011 00:11
A simple <canvas> element test
<!DOCTYPE html>
<html>
<head>
<title>Testing HTML5 Canvas element</title>
<script src="jquery.min.js" type="text/javascript"></script>
</head>
<body>
This is a test of the HTML5 Canvas element.
<canvas id="drawing_canvas" width="800" height="600" style="position: absolute; top: 0; left: 0;">
</canvas>
require 'rubygems'
require 'sqlite3'
require 'sequel'
# Adding this monkey-patch makes it work on MacRuby.
module Sequel
class Dataset
def single_record
record = nil
clone(:limit=>1).each{|r| record = r; return r}
@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
@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 / 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'
# 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 / 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)
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