Skip to content

Instantly share code, notes, and snippets.

View lwoodson's full-sized avatar

Lance Woodson lwoodson

View GitHub Profile
# Playing with java topology suite in jruby
require 'java'
require 'rubygems'
require 'mvn:com.vividsolutions:jts'
java_import "com.vividsolutions.jts.geom.PrecisionModel"
java_import "com.vividsolutions.jts.geom.GeometryFactory"
java_import "com.vividsolutions.jts.geom.Coordinate"
java_import "com.vividsolutions.jts.geom.Point"
java_import "com.vividsolutions.jts.geom.LineString"
@lwoodson
lwoodson / gist:3939459
Created October 23, 2012 15:29
Chord definitions DSL
module ChordDSL
def chord(file_path, &block)
chord = Chord.new
chord.file_path = file_path
chord_ctx = ChordContext.new chord
chord_ctx.instance_exec &block
chord.save!
end
class ChordContext
@lwoodson
lwoodson / sql_mapper_examples.rb
Created November 2, 2012 12:15
sql_mapper examples
require 'rubygems'
require 'sql_mapper'
# sql_mapper is built on top of ActiveRecord and is meant to augment it in this specific case: 1. You
# want fast read access for large data sets, 2. the data can be flat (denormalized) and 3. you don't
# need AR's magic. It also assumes the ability to comfortably craft raw sql. Sql is a data retrieval DSL
# after all ;)
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
conn = ActiveRecord::Base.connection
conn.execute 'create table foos (id serial, name string)'
@lwoodson
lwoodson / irb.rb
Created November 6, 2012 13:30
Ruby service locator proposal. The irb.rb file defines 2 services (first and second) and leverages them in the Domain class.
require 'service_locator'
# Declare our services
Services.instance.config do
service :first, "this is"
service :second, " a test"
end
# See that ServiceDependent has convenience methods defined to access services.
puts ServiceDependent.instance_methods
@lwoodson
lwoodson / context.rb
Created November 16, 2012 23:17
Supply chain DCI
class ManufacturingContext
def initialize(manufacturer, payor, item, quantity)
@manufacturer = manufacturer
@payor = payor
@item = item
@quantity = quantity
@manufacturer.extend Manufacturer
@payor.extend Payor
end
@lwoodson
lwoodson / ls_snip.sh
Created November 26, 2012 11:25
Simple bash script to list the snipMate snippets available to different filetypes in vim.
#! /bin/bash
list_snippets_for() {
egrep "^snippet|^#" ~/.vim/snippets/$1.snippets | awk '/^#/ {comment = comment $0} /^snippet/ {print $0 "\t\t" comment; comment=""}'
}
if [ "$1" == "" ]
then
echo "You must specify at least one file type as an argument to ls_snip"
exit
fi
AddendPerformanceProgramObjectives
AddendPerformanceProgramSchedule
ApplicantListWorker
ApplicationTransitionWorker
ChoreCreated
ChoresNotifications
EeoReportWorker
EmailWorker
EmployerStatsExportWorker
EmploymentTaskOpeningWorker
pools = ActiveRecord::Base.connection_handler.connection_pools.values
pools.each do |pool|
pool.connections.each{|connection| connection.reconnect!}
end
[48] pry(main)> reflection = HiringProposal.reflections[:job_application]
=> #<ActiveRecord::Reflection::AssociationReflection:0x007fd7c6e91420
@active_record=
Action(id: integer, action_definition_id: integer, created_at: datetime, updated_at: datetime, position_context_id: integer, job_application_id: integer, created_by_id: integer, position_description_id: integer, type: string, variances: text, workflow_state_id: integer, deleted_at: datetime, last_updated_at: datetime, hr_override: boolean, delta: boolean, version: integer, latest: boolean, position_type_id: integer, organizational_unit_id: integer, auto_number: string, workflow_state_definition_id: integer, workflow_owner_user_id: integer),
@association_foreign_key="job_application_id",
@class_name="JobApplication",
@collection=false,
@klass=
JobApplication(id: integer, posting_id: integer, form_id: integer, created_at: datetime, updated_at: datetime, user_id: integer, confirmation_number: string, submitted_at: datetime, certification_statemen
2.1.1 :001 > array = [1] * 100
=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
2.1.1 :002 > array.each_slice(array.size / 4).to_a
=> [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
2.1.1 :003 > arrays = array.each_slice(array.size / 4).to_a
=> [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1,