Skip to content

Instantly share code, notes, and snippets.

View jgn's full-sized avatar
☂️
Messing around.

John Norman jgn

☂️
Messing around.
View GitHub Profile
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Try ember-set-helper';
}
@jgn
jgn / opendns.rb
Created April 27, 2018 19:49
Block via OpenDNS
require 'mechanize'
require 'set'
require 'pry'
ACCOUNT = ENV['OPENDNS_ACCOUNT']
USERNAME = ENV['OPENDNS_USERNAME']
PASSWORD = ENV['OPENDNS_PASSWORD']
BLOCK_LIMIT = 25
AGENT_NAME = 'Mac Safari'
#!/usr/bin/env ruby
# from https://stackoverflow.com/posts/24458934/revisions
require 'digest/sha1'
def git_hash(filename)
data = File.read(filename)
Digest::SHA1.hexdigest("blob #{data.bytesize.to_s}\0#{data}")
end
@jgn
jgn / session.irb
Last active February 3, 2016 17:50
Getting access to a view in AR
irb
irb(main):001:0> require 'active_record'
=> true
irb(main):002:0> ActiveRecord::Base.establish_connection(adapter: :postgresql, database: :view_demo)
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007ffc83b088d0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007ffc83b099d8>, @spec=#<ActiveRecord::ConnectionAdapters::ConnectionSpecification:0x007ffc84134d08 @config={:adapter=>:postgresql, :database=>:view_demo}, @adapter_method="postgresql_connection">, @checkout_timeout=5, @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x007ffc83b09c58 @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007ffc83b088d0 ...>, @frequency=nil>, @size=5, @reserved_connections=#<ThreadSafe::Cache:0x007ffc83b0b440 @backend={}, @default_proc=nil>, @connections=[], @automatic_reconnect=true, @available=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Queue:0x007ffc83b03f10 @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007ffc83b088d0 ...>, @cond=#<MonitorMixin::ConditionVariab
require 'active_record'
spec = { adapter: :postgresql, database: :jgn }
ActiveRecord::Base.establish_connection(spec)
if ActiveRecord::Base.connection.table_exists?(:members)
ActiveRecord::Base.connection.drop_table :members
puts 'Dropped table'
end
require 'active_record'
blacklist = {
icis_production: [ 'patient_versions', 'patients' ],
snowflake_production: [ 'persons' ]
}
blacklist.each_pair do |database, blacklisted_tables|
spec = {
adapter: :postgresql,
@jgn
jgn / get_metadata.rb
Last active January 20, 2016 14:20
Get table, column data
# this is how you bring in a gem (a module). The gem should previous be
# installed with: gem install activerecord (yes, the gem name and what
# "require" are different.)
require 'active_record'
# This is a hash, like a dictionary in Python.
# The classic syntax looks like this:
# spec = { 'adapter' => 'postgresql', 'database' => 'icis_production' }
# However, the tokens preceded with the colon are actually symbols, where
# are like strings but they can't be changed. So, the following hash
class UnexpectedOutputError < StandardError; end
class MockLogger
def initialize(expected_indirect_outputs)
@eio = Array(expected_indirect_outputs)
end
def info(s)
expected = @eio.shift
if expected != s
raise UnexpectedOutputError.new("Fail: got #{s}; expected #{expected}")
end
require 'logger'
def get_logger
logger = Logger.new(STDOUT)
def logger.info(s)
@log_output ||= ""
@log_output << s << "\n"
end
def logger.log_output
@log_output
end
class Logger
attr_reader :log_output
def info(s)
@log_output ||= ""
@log_output << s << "\n"
end
end
examples.each do |example|
a, b, c, s = example