View post_test.rb
require 'test_helper'
# ActiveRecord::Schema.define(version: 20170310085807) do
# create_table "forums", force: :cascade do |t|
# t.string "title"
# t.integer "posts_count"
# t.datetime "created_at", null: false
# t.datetime "updated_at", null: false
# end
View oauth_sinatra_client.rb
require 'sinatra'
require 'omniauth-twitter'
require 'omniauth-salesforce'
configure do
enable :sessions
helpers do
def h(text)
View binary.html
<!DOCTYPE html>
<title>Binary Entry JavaScript</title>
<style type="text/css">
.box {
border: 1px solid black;
height: 32px;
width: 32px;
font-size: 24px;
View entity_weirdness.rb
# This shows the list of entities, and that they look like String objects to RubyMotion.
(main)> mapping = App.delegate.managedObjectContext.persistentStoreCoordinator.managedObjectModel.entitiesByName.keys.each_with_object({}) { |key, map| map[key.to_s] = key}
=> {"Auction"=>"Auction", "Category"=>"Category", "Entry"=>"Entry", "Host"=>"Host"}
# This is an example lookup for the Category entity, by name. It fails.
(main)> App.delegate.managedObjectContext.persistentStoreCoordinator.managedObjectModel.entitiesByName['Category']
=> nil
# Here we try to insert a new object for an entity by name, using 'Category' as a raw string. It fails, unable to locate it.
(main)> begin
View champagne.rb
if ARGV[0].nil?
puts "Usage:\n\truby #{__FILE__} {bad bottle#|test}"
def guess_bottle(bad_bottle, silent=false)
waiters = []
(0..9).each do |waiter_number|
waiters[waiter_number] = []
(0..999).each do |bottle|
View string_permutations.rb
require 'set'
# First I wanted to get an idea of the timing of the various approaches
def time
start =
puts - start.to_f
# This optimizes for redundant strings of values, front-loading them to maximize duplicates
View humanize.js
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
View keychain.rb
#!/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...
View canvas_test.html
<!DOCTYPE html>
<title>Testing HTML5 Canvas element</title>
<script src="jquery.min.js" type="text/javascript"></script>
This is a test of the HTML5 Canvas element.
<canvas id="drawing_canvas" width="800" height="600" style="position: absolute; top: 0; left: 0;">
View database.rb
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}