Skip to content

Instantly share code, notes, and snippets.

View levicole's full-sized avatar

Levi Cole levicole

  • Kolide
  • Nashville, TN
View GitHub Profile
@levicole
levicole / image.rb
Created May 17, 2017 19:34 — forked from seancdavis/image.rb
Rails has_many :through Polymorphic Association (http://goo.gl/lxmehk)
# app/models/image.rb
class Image < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
</head>
<body>
<h1>My Awesome ToDo List</h1>
Then /^I should see element "([^"]*)" before element "([^"]*)"$/ do |first, second|
xpath = "//*[@id='#{first}']/following-sibling::*[@id='#{second}']"
response_body.should have_xpath(xpath)
end
puts "\n--- watchr initialized ---\n\n"
def cmd() 'script/spec '; end
def run_all_specs
system(cmd + 'spec/')
end
def run_spec(spec)
puts "Running #{spec}"
@levicole
levicole / hack
Created September 14, 2009 03:22 — forked from ymendel/hack
#!/bin/sh
BRANCHES=`git branch`
if [ $? != 0 ]; then
exit
fi
GIT_SVN=0
git branch -r | grep 'git-svn' > /dev/null
if [ $? = 0 ]; then
GIT_SVN=1
def hexlify(msg)
msg.split("").collect { |c| c[0].to_s(16) }.join
end
def unhexlify(msg)
msg.scan(/../).collect { |c| c.to_i(16).chr }.join
end
puts hexlify("Hello World")