Skip to content

Instantly share code, notes, and snippets.

View ajsharp's full-sized avatar

Alex Sharp ajsharp

View GitHub Profile
CREATE TABLE IF NOT EXISTS Timelines(
name text,
parent_id text,
event_id uuid,
PRIMARY KEY((parent_id, name), event_id)
) WITH CLUSTERING ORDER BY (event_id DESC)
@ajsharp
ajsharp / email_example.rb
Last active August 29, 2015 14:01
This describes two potential API for running jobs in the future. One is a simple, abstract job, where the logic lives in your application, and is triggered via a webhook at the scheduled time. The other is a SMS notification that is due to fire at some point in the future.
# Often times we need to send emails on a delayed basis. We could make this really easy on the client
# side by automatically mounting an endpoint with rack middleware, and firing the mailer with the
# arguments supplied.
#
# Under the hood, this would use the same architecture as an abstract job, where a webhook is hit
# at the specified time, but by focusing on the email / action mailer use case the client doesn't need
# to write any boilerplate code.
Tick::EmailJob.create!(
:at => appointment.start_time - 1.hour,
:message => "Don't forget, your appointment starts in 1 hour!",
{
"steps": {
"original": {
"use": ":original",
"robot": "/image/resize"
},
"pdf": {
"use": ":original",
"robot": "/document/thumbs",
"page": 1
@ajsharp
ajsharp / heroku-env-to-opsworks
Created April 23, 2015 00:38
This handy little script makes it super easy to add all your heroku environment configuration to an AWS Opsworks app. Very handy if you're moving off Heroku and onto opsworks.
#!/usr/bin/env ruby
require 'json'
app_name = 'APP_NAME'
opsworks_app_id = 'APPID'
config = `heroku config -s --app #{app_name}`.strip
json = []
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Page</title>
<script type="text/javascript" src="js/prototype-1.6.0.3.js"></script>
<script type="text/javascript" src="js/livepipe/livepipe.js"></script>
<script type="text/javascript" src="js/livepipe/window.js"></script>
<script type="text/javascript">
def make_friends(user, target)
transaction do
begin
Friend.find(:first, :conditions => {:inviter_id => user.id, :invited_id => target.id, :status => PENDING}).update_attribute(:status, ACCEPTED)
Friend.create!(:inviter_id => target.id, :invited_id => user.id, :status => ACCEPTED)
rescue Exception
return make_friends( target, user) if user.followed_by? target
return add_follower(user, target)
end
end
include AASM
include AASM::Persistence
aasm_column :status
aasm_initial_state Proc.new { |task| task.assignments.empty? ? :not_started }
aasm_state :not_started
aasm_state :in_progress
aasm_state :completed
aasm_event :start_task do
require "autotest/growl"
require "autotest/fsevent"
require 'autotest/restart'
Autotest.add_hook :initialize do |at|
at.unit_diff = 'cat'
end
Autotest.add_hook :ran_command do |at|
Task.find(:all, :include => [{:assignments => :task}], :conditions => ["assignments.assignee_id = ? AND assignments.status = ?", u.id, "accepted"])
# visit.rb
Factory.define :visit do |f|
f.patient { |a| a.association(:patient) }
f.clinic { |a| a.association(:clinic) }
end
# patient.rb
# Defines a new sequence
Factory.sequence :email do |n|
"person#{n}@example.com"