Skip to content

Instantly share code, notes, and snippets.

View cokara's full-sized avatar

Charles Okara cokara

  • Arcadia Power
  • Washington, DC
View GitHub Profile
@cokara
cokara / gist:3ab02b4f59a950868ee4e696d2b70807
Created July 19, 2022 19:33
Host File Ingestion spike
class HostConfig
def details
{
format: 'xlsx',
mappings: {
project_name: { source_field: 'DEVELOPER' },
date_reading_from: { source_field: 'GEN_PD_BEG_DATE' },
date_reading_to: { source_field: 'GEN_PD_END_DATE' },
kwh: { source_field: 'ALLOC_KWH' },
utility_account_number: { source_field: 'SUBSCRIBER' },
Received a webhook with data:
[0] {
[0] type: 'utility_credential_verified',
[0] created_at: '2021-09-29T13:11:20.353-04:00',
[0] data: {
[0] id: 1820,
[0] username: 'co-75189935@a.arcadiapower.com',
[0] created_at: '2021-09-29T13:11:01.029-04:00',
[0] updated_at: '2021-09-29T13:11:18.735-04:00',
[0] utility_name: 'Pepco',
@cokara
cokara / sample_recording.rb
Last active January 18, 2016 18:48
GL Recording thoughts
class DebitEntry
def initialize(gl_account, amount_cents)
end
def create_record(je)
::AccountEntry.create(
amount_cents: amount_cents
gl_account_id: gl_account_id,
journal_entry_id: je.id
)
end
@cokara
cokara / gist:bc21cf7040bc49be5978
Created June 13, 2014 13:15
Unique number of failed queues.
(function() { var fails = {}; $('tr').each(function(ind, row) { var last = +row.children[4].innerText, name = row.children[0].innerText; if(last && name != 'Total'){ fails[name] = last; } } ); console.log(fails); console.log(Object.keys(fails).length); }())
@cokara
cokara / .irbrc
Created May 29, 2014 21:32
My .irbrc file. Put this in your home folder.
IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I => "\e[0;33m%N(%m):%03n: > \e[m ",
:PROMPT_S => "\e[0;33m%N(%m):%03n:%l>>\e[m ",
:PROMPT_C => "\e[0;33m%N(%m):%03n:..\e[m ",
:PROMPT_N => "\e[0;33m%N(%m):%03n:..\e[m ",
:RETURN => "\e[1;31m=>\e[m %s\n"
}
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:AUTO_INDENT] = true

Assuming you have a Postgres table called maps, created by the following migration:

create_table :maps do |t|
  t.string :name
  t.string :grid, array: true, length: 3, default: Array.new(3,nil)
 end

And you have the following ActiveRecord class with a function that modifies the grid