Skip to content

Instantly share code, notes, and snippets.

View cyberfox's full-sized avatar

Morgan Schweers cyberfox

View GitHub Profile
@cyberfox
cyberfox / oauth_sinatra_client.rb
Created August 28, 2015 06:18
Simple Salesforce & Twitter OAuth2 Sinatra client
require 'sinatra'
require 'omniauth-twitter'
require 'omniauth-salesforce'
configure do
enable :sessions
end
helpers do
def h(text)
@cyberfox
cyberfox / entity_weirdness.rb
Last active August 29, 2015 13:59
RubyMotion entity name weirdness
# 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
@cyberfox
cyberfox / binary.html
Created June 3, 2015 07:50
Binary entry HTML+CSS+JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Binary Entry JavaScript</title>
<style type="text/css">
.box {
border: 1px solid black;
height: 32px;
width: 32px;
font-size: 24px;
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Growl notification</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<base href="%baseurl%" />
<style type="text/css">
@import URL("default.css");
#top,#middle,#bottom {
@cyberfox
cyberfox / growl command.sh
Created September 5, 2008 20:39
undefined
growl -H myhost -n myapp --priority 0 -m '<div id="override"><img src="http://somehost/start_ok.png" alt="icon"></div>Application running...' -t "Started"
#!/bin/sh
svn mkdir svn://svn/test_branching svn://svn/test_branching/trunk svn://svn/test_branching/branches -m"Create a test repository for branching."
mkdir branch_tmp
cd branch_tmp
svn co svn://svn/test_branching/trunk test/
cd test
echo "This is a test." > testme.txt
svn add testme.txt
svn commit testme.txt -m"Add a test file."
svn cp svn://svn/test_branching/trunk svn://svn/test_branching/branches/new_branch -m"Create a new branch with the test file in it."
@cyberfox
cyberfox / gist:137231
Created June 28, 2009 10:31
A cool little, super-simple, shell script for doing calculations.
# Tried to twitter this; FAIL.
$ cat > calc
#!/bin/env ruby
p eval(ARGV[0])
^D
$ chmod a+x calc
$ ./calc 4*Math::PI
$ ./calc "Math::sqrt(15241578750190521)"
$ ./calc 24*7
@cyberfox
cyberfox / gist:139419
Created July 2, 2009 11:01
501 http response error log for JBidwatcher
Tue Jun 30 19:43:31 CEST 2009: JBidwatcher 2.0.1-825
Tue Jun 30 19:43:32 CEST 2009: Sun Microsystems Inc. Java, version 1.6.0_13 on Linux
Tue Jun 30 19:43:35 CEST 2009: Error setting up scripting: java.lang.NoClassDefFoundError: org/jruby/runtime/builtin/IRubyObject
Tue Jun 30 19:43:36 CEST 2009: Loading listings from the database (1/6/6 entries, 6/6 auctions)
Tue Jun 30 19:43:36 CEST 2009: Done with the initial load (got 1 active entries)
Tue Jun 30 19:43:41 CEST 2009: Couldn’t sign in!
Server returned HTTP response code: 501 for URL: http://cgi1.ebay.com/aw-cgi/eBayISAPI.dll?Adult…
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
@cyberfox
cyberfox / Modules can access instance variables of the included-to class
Created October 29, 2009 19:25
Modules can access instance variables of the included-to class
>> module Foo
>> def bar
>> puts @quux
>> end
>> end
=> nil
>> class Baz
>> attr_accessor :quux
>> def xyzzy
@cyberfox
cyberfox / resource_factory.rb
Created November 9, 2009 23:35
Make ActiveResource able to handle authentication w/o acting like a global variable.
# This is a gross hack to make it possible to access the same
# resource from the context of different users at the same time.
# I'm quite positive this is wasteful and bad, but it's the only
# way to 'de-global' subclasses of ActiveResource::Base. :( It's
# also possible it leaks memory if the GC doesn't collect Class
# objects. -- Morgan Schweers, 09-Nov-2009
class ResourceFactory
def self.get(klass)
Class.new(klass) do |resource|