Skip to content

Instantly share code, notes, and snippets.

View markmcdonald51's full-sized avatar

Mark The Spot markmcdonald51

  • hdp
  • Portland, Oregon
View GitHub Profile
require 'udt_model'
class MetaMark::ActiveRecordModel
extend UdtModel
def self.active_record_model_as_file(udt)
# return if File.exist?(udt.path_to_udt_model)
# m = MetaMark::ActiveRecordModel.new(udt)
table_name = udt.db_table_name
new_class_name = udt.udt_class_name # m.udt_class_name(table_name, udt)
class Udt < ActiveRecord::Base
include AASM
has_paper_trail
belongs_to :project
has_one :organization, through: :project
has_one :workflow, dependent: :destroy
has_many :workflow_scripts, as: :aasm_scriptable, dependent: :destroy, class_name: 'AasmScript'
has_many :udt_table_fields, -> { order(position: :asc) }, dependent: :destroy
@markmcdonald51
markmcdonald51 / gist:19a891b8d38f67189cd5
Created January 9, 2016 12:44
Why not to use has_many association extension over has_many with conditions
Why not to use has_many association extension over has_many with conditions!
Has many is useful for adding in new functionality to the has_many association, however the problem with these entensions is
that Rails doesn't cache them. So every time you call object.members.requested it makes a call to the database.
has_many :organization_users
has_many :members, through: :organization_users, source: :user
has_many :members, through: :organization_users, source: :user do
def requested
@markmcdonald51
markmcdonald51 / gist:2ec948c542dcf97b2f56
Created May 13, 2015 12:39
Recreate a sqlite3 dev db from current pg_dump from production.
namespace :database_utilities do
desc "Recreate a sqlite3 dev db from current pg_dump from production."
# This task should only ever be run in a development environment.
task create_sqlite3_from_pg_dump: :environment do
# by Mark on Wed May 13 06:15:09 EDT 2015
# Based on the ideals from this webpage:
# http://manuel.manuelles.nl/blog/2012/01/18/convert-postgresql-to-sqlite/
@markmcdonald51
markmcdonald51 / gist:5feff60cd592f6063991
Created February 3, 2015 20:56
ActiveScaffoldStateMachine ... lib/as_aasm.rb
module ActiveScaffoldStateMachine
# add to controller
#config.action_links.member.add 'get_states', position: false
=begin
Then create a view called get_states.js.erb and put it in the view dir or
a common directory called active_scaffold_overrides which contains the following:
<%
# A must have function for thinking sphinx, eg:
#
#Location.search("taco", :geo => [33.653275.to_radian, -117.646854.to_radian ], #:order => "@geodist ASC").map(&:address).map(&:city)
class Numeric
def to_radian
self * Math::PI / 180
end
end
#!/usr/bin/ruby1.8
require 'tk'
require 'open3'
require 'net/telnet'
require 'fileutils'
require 'date'
DESTINATION_DIR = "/tmp"
sudo apt-get install postgresql
l;
1003 sudo apt-get install libproj-dev libxml2-dev postgresql-server-dev-8.4
1004 sudo apt-get install libproj-dev libxml2-dev postgresql-server-dev-8.4.4
1005 sudo apt-get install libproj-dev libxml2-dev postgresql-server-dev-8.4
1006 psql
Hey Ben,
if you add in the ' -limit memory 1 -limit map 1 ' to your transformation_command method it causes imagemagick to use file space instead of memory space. Now I dont have to buy more ram and it does the same thing!
-----------------------------------------------------------
"papermill_paperclip_processor.rb" 82L, 3241C written
def transformation_command
" -limit memory 1 -limit map 1 #{(crop_command ? super.sub(/ -crop \S+/, crop_command) : super)} #{copyright_command} #{watermark_command}".sub(%{-resize "0x" }, "")
module AasmAddons
def self.included(base_class)
base_class.class_eval do
def aasm_fire_event(*args)
line_items.each do |li|
#li.send("#{args.first.to_s}!")
li.update_attributes(:state => args.first.to_s)
end
state_logs.create!(:state => args.first.to_s, :user => current_user)
super(*args)