Skip to content

Instantly share code, notes, and snippets.

View gmgent's full-sized avatar

Krister Axel gmgent

  • Ashland IO LLC
  • Ashland, OR
View GitHub Profile
def to_boolean(value, nil_value = false)
compare_value = value.class == String ? value.downcase : value
case compare_value
when "no","false",false, "0", 0
false
when "yes","true",true, "1", 1
true
when nil
nil_value
else
@gmgent
gmgent / ruby_find_dup_hash_on_key_in_array.rb
Created April 11, 2012 23:23
ruby_find_dup_hash_on_key_in_array
puts array_of_hashes.select{|i| array_of_hashes.select{|s|s[:key]==i[:key]}.count > 1}.map {|show| "#{show[:key]} #{show[:name]}"}
@gmgent
gmgent / mysql-split.sql
Created March 5, 2012 22:38
impersonating a split function in MySQL
select sum(amount) total
, ds item_date
, LEFT(ds, 4) item_year
, SUBSTRING_INDEX(ds,'-',-1) item_day
, LEFT(SUBSTRING(ds,INSTR(ds,'-')+1), 2) item_month
, created_at
, td
from temp_ps
group by ds
@gmgent
gmgent / fizzbuzz.rb
Created October 29, 2011 20:12
fizzbuzz.rb
for x in 1..100 do
if (x % 3 == 0) && (x % 5 == 0)
puts "fizzbuzz"
elsif (x % 3 == 0)
puts "fizz"
elsif (x % 5 == 0)
puts "buzz"
else
puts x
end
module DataGrid
class Section
attr_reader :care_area, :patient_population, :total_records, :data_section
def initialize(care_area, population, total_records, drug_records)
@care_area = care_area
@patient_population = population
@total_records = total_records
@data_section = drug_records
end
module DataGrid
class Page
attr_reader :page_no, :sections
def initialize(page_no, type)
@page_no = page_no
@sections = []
@type = type
end
require "rubygems"
require "prawn"
require "prawn/layout"
require "prawn/measurement_extensions"
module DataGrid
#colors
TEXT_COLOR = "000000"
DEFAULT_BG_COLOR = "ffffff"
@gmgent
gmgent / gist:938421
Created April 23, 2011 06:47
spreadsheet_row_enumerator.rb
class SpreadsheetRowEnumerator
include Enumerable
def initialize(file_name, sheet_name, starting_row = 2)
parsing_class = case File.extname(file_name)
when ".xls": Excel
when ".xlsm", ".xlsx": ExcelxNokogiri
end
@starting_row = starting_row
@gmgent
gmgent / gist:938419
Created April 23, 2011 06:46
data_grid_exporter.rb
class DataGridExporter
class << self
def export(data_grid)
returning(StringIO.new) do |buffer|
DataGridExporter.new(data_grid).build_workbook.write buffer
end.string
end
def quantity_unit_map
{"dosing_cumulative_max_quantity" => "dosing_cumulative_max_unit" }
@gmgent
gmgent / gist:938418
Created April 23, 2011 06:45
drug_record_data_grid_presenter.rb
class DrugRecordDataGridPresenter
extend Forwardable
attr_reader :data_grid, :view
def_delegators :data_grid, :each_row, :each_header_group, :configure_unit_field_formatters
def initialize(options = {})
@data_grid = options[:grid]
@view = options[:view]