Skip to content

Instantly share code, notes, and snippets.

View jasonelston's full-sized avatar

Jason Elston jasonelston

  • Sydney, Australia
View GitHub Profile
@jasonelston
jasonelston / Arel joins problem
Created February 21, 2011 23:19
Problem with using joins with Arel tables and Rails queries
Because of the way I've structure the requests model and it's relationship with ads, I need to be able to do ORs in my query.
Anyway I've found my way to Arel and it looks like it should do the goods for me but I can't get a join working
The existing named scope in the Request class is
scope :responder, lambda { |user| joins(:ad).where(:ads => { :user_id => user }) }
The above works as I expect it to.
@jasonelston
jasonelston / tester_generator.rb
Created February 19, 2012 23:51
Test rails generator (rails g generator tester)
#./lib/generators/tester
# shows in generator list as
class TesterGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
end
# $ rails g
# Usage: rails generate GENERATOR [args] [options]
#
@jasonelston
jasonelston / gist:4516825
Last active December 11, 2015 00:28
problem getting Math.acos working
# paste this into the console to see the results are sometimes good and then sometimes the error
# Math::DomainError: Numerical argument is out of domain - "acos"
# Error ref - http://www.ruby-doc.org/core-1.9.3/Math/DomainError.html
@loc1 = FactoryGirl.create(:location)
Location.all.each do |location|
location.nearby?(@loc1)
end
@jasonelston
jasonelston / gist:4721540
Last active December 12, 2015 05:28
Problems with Authority, RocketPants and exceptions rendered in HTML, not JSON
# Controller
class BagsController < ApiController
# ....
def index
authorize_action_for(Bag)
end
# ....
@jasonelston
jasonelston / launch.json
Created May 5, 2019 08:35
.vscode/launch.json for golang project
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",