Skip to content

Instantly share code, notes, and snippets.

View DylanLacey's full-sized avatar

The Gentlehacker DylanLacey

View GitHub Profile
def submit
@job = Job.find(params[:id], :include => [:pickup_addresses, :setdown_addresses])
@publish_success = false
AMQP.connect(:host => "localhost") do |connection|
logger.debug ("#{DateTime.now} | DISPATCH | Dispatching submission for Job #{@job.id}")
channel = AMQP::Channel.new(connection)
exchange = channel.direct("dispatch")
@publish_success = exchange.publish ActiveSupport::JSON.encode(@job, :include => [:pickup_addresses, :setdown_addresses]), :routing_key => "#{@job.city}"
def submit
@job = Job.find(params[:id], :include => [:pickup_addresses, :setdown_addresses])
@dispatch_result = false
AMQP.start("amqp://guest:guest@localhost:5672") do |connection, open_ok|
puts "BLOCK"
AMQP::Channel.new(connection) do |channel, open_c_ok|
class Job < ActiveRecord::Base
has_many :waypoints
has_many :pickup_addresses, :class_name => "Waypoint", :conditions => {:purpose => "PICK UP"}
has_many :setdown_addresses, :class_name => "Waypoint", :conditions => {:purpose => "SET DOWN"}
accepts_nested_attributes_for :waypoints
accepts_nested_attributes_for :pickup_addresses
accepts_nested_attributes_for :pickup_addresses
end
module ApplicationHelper
def link_to_remove_fields(name, f)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end
def link_to_add_fields(name, f, association, options)
render_object = options[:partial] || association.to_s.singularize + "_fields"
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
<tr>
@using (Ajax.BeginForm("Create", new AjaxOptions{HttpMethod = "Post",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "BlacklistGrid tbody"
})){
<td>@Html.HiddenFor(b => Model.shift_id)
@Html.EditorFor(b => Model.car)</td>
<td>@Html.EditorFor(b => Model.reason)</td>
<td><input type="submit" value="Add New"/> </td>
@DylanLacey
DylanLacey / gist:1139045
Created August 11, 2011 06:53
Broken LINQing
var returnShift =
All().Aggregate(
(x, y) =>
(x.start.Ticks - desiredStartTime.Ticks) < (y.start.Ticks - desiredStartTime.Ticks) ? x : y);
Error message:
Expression of type 'System.Collections.Generic.IEnumerable`1[ShiftyEyes.Model.Shift]' cannot be used for parameter of type 'System.Linq.IQueryable`1[ShiftyEyes.Model.Shift]' of method 'ShiftyEyes.Model.Shift Aggregate[Shift](System.Linq.IQueryable`1[ShiftyEyes.Model.Shift], System.Linq.Expressions.Expression`1[System.Func`3[ShiftyEyes.Model.Shift,ShiftyEyes.Model.Shift,ShiftyEyes.Model.Shift]])'
@DylanLacey
DylanLacey / gist:1182745
Created August 31, 2011 03:23
EM & AMQP
class Main
t = Thread.new do
EventMachine.run
end
sleep(5)
puts "Asimov: Attempting Connection"
@DylanLacey
DylanLacey / about.md
Created September 7, 2011 01:31 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
<html>
<head>
<title>Slide Example</title>
<style>
.viewport {
position: relative;
overflow: hidden;
width: 150px;
height: 200px;
border: 1px solid maroon;
<!DOCTYPE html>
<html>
<head>
<title>Qube</title>
<link href="/stylesheets/application.css?1315459903" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/scaffold.css?1302678261" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/jquery.js?1315279008" type="text/javascript"></script>
<script src="/javascripts/jquery-ui.js?1316755609" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1315279008" type="text/javascript"></script>
<script src="/javascripts/application.js?1315371344" type="text/javascript"></script>