Skip to content

Instantly share code, notes, and snippets.

View zgchurch's full-sized avatar

Zach Church zgchurch

View GitHub Profile
@zgchurch
zgchurch / BridgingHeader.h
Created June 26, 2014 17:32
Using SQLite3 from Swift
// 1. Create this file in your Xcode project
// 2. Go to "Build Settings" and find "Objective-C Bridging Header." Use the search bar to find it quickly.
// 3. Double-click and type "BridgingHeader.c"
// If you get "Could not import Objective-C Header," try "my-project-name/BridgingHeader.h"
// 4. Go to "Build Phases," "Link Binary With Libraries," and add libsqlite3.0.dylib
#include <sqlite3.h>
@zgchurch
zgchurch / gist:4128152
Created November 21, 2012 22:02
(my new) failing ActiveRecord test
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 3f08f9e..fe0d2cc 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -1000,6 +1000,12 @@ class TestHasOneAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveRe
ShipPart.create!(:ship => @ship, :name => "Stern")
assert_no_queries { @pirate.valid? }
end
+
+ test "not sure yet" do
@zgchurch
zgchurch / form_builder_ext.rb
Created December 13, 2011 14:41
Adding little stars to the labels of required attributes
# Partially stolen from: http://davidsulc.com/blog/2011/05/01/self-marking-required-fields-in-rails-3/
class ActionView::Helpers::FormBuilder
alias :orig_label :label
# add a 'required' class to the field label if the field is required
def label(method, content_or_options = nil, options={}, &block)
if content_or_options && content_or_options.class == Hash
options = content_or_options
else
@zgchurch
zgchurch / pong.html
Created March 17, 2011 16:29
pong with HTML5 Canvas: left player uses keyboard, right player uses mouse
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var canvas = $('canvas#pong');
var context = canvas[0].getContext('2d');
var players = [{position: {x: 10, y: 30}}, {position: {x: 900, y: 00}}];
var config = {player: {width: 30, height: 150}};
var ball = {position: {x: 100, y: 100}, velocity: {x: 3, y: 0}, width: 15, height: 15};
var angle_coefficient = -1/50;
@zgchurch
zgchurch / Countdown
Created March 17, 2011 16:27
countdown timer; display fullscreen for speakers at conferences
<style>
body {
background-color: black;
color: white;
font-family: sans-serif;
text-align: center;
}
#minutes {
font-size: 500px;
}
@zgchurch
zgchurch / gist:438621
Created June 15, 2010 02:30
Google maps geolocation API with activerecord
require 'json'
require 'cgi'
require 'httparty'
module GMap
module Location
def latitude
read_attribute(:latitude) || fetch_coordinates_from_address.latitude
end