Skip to content

Instantly share code, notes, and snippets.

View cyberfox's full-sized avatar

Morgan Schweers cyberfox

View GitHub Profile
@cyberfox
cyberfox / string_permutations.rb
Created January 7, 2012 09:11
Return all permutations of a string, without any duplicates.
require 'set'
# First I wanted to get an idea of the timing of the various approaches
def time
start = Time.now
yield
puts Time.now.to_f - start.to_f
end
# This optimizes for redundant strings of values, front-loading them to maximize duplicates
@cyberfox
cyberfox / humanize.js
Created October 20, 2011 18:43
JavaScript humanize method.
com = { cyberfox: {} };
/**
* Convert a property name into a human readable string by replacing _ with
* spaces, and upcasing the first letter of each word.
*
* @param {string} property The property name to convert into a readable name.
* @return {string} The property name converted to a friendly readable format.
* @private
*/
@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 / 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
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