Skip to content

Instantly share code, notes, and snippets.

View cknoxrun's full-sized avatar

Craig Knox cknoxrun

View GitHub Profile
@cknoxrun
cknoxrun / generate_execute_commands.mysql
Last active September 20, 2022 18:25
Upgrading MariaDB (from broken utf8) to Modern Unicode in 2022
-- Reminder: Replace YOUR_DATABASE with your own database.
SELECT concat
(
'execute("ALTER TABLE ',
t1.table_name,
' MODIFY `',
t1.column_name,
'` ',
t1.column_type,
' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
SECTIONS = {
abuse: '34086-9',
accessories: '60555-0',
active_ingredient: '55106-9',
adverse_reactions: '34084-4',
alarms: '69761-5',
animal_pharmacology_and_or_toxicology: '34091-9',
ask_doctor: '50569-3',
ask_doctor_or_pharmacist: '50568-5',
assembly_or_installation_instructions: '60556-8',
li.nav-item.dropdown
a.nav-link.dropdown-toggle href="#" data-toggle="dropdown" Browse
.dropdown-menu
= link_to "#{c_icon(:drugs)} Drugs".html_safe, main_app.drugs_path, class: 'dropdown-item'
= link_to "#{c_icon(:categories)} Categories".html_safe, main_app.categories_path, class: 'dropdown-item'
= link_to "#{c_icon(:pathways)} Pathways".html_safe, main_app.pathways_path, class: 'dropdown-item'
= link_to "#{c_icon(:reactions)} Drug Reactions".html_safe, main_app.reactions_path, class: 'dropdown-item'
= link_to "#{c_icon(:classifications)} Drug Classification".html_safe, main_app.classyfication_path, class: 'dropdown-item'
/ = link_to "#{c_icon(:targets)} Drug Targets".html_safe, main_app.targets_path, class: 'dropdown-item'
namespace :update do
desc "Upload all Paperclip attachments to S3"
task s3: [:environment] do
models = {
documents: [Document, :file],
ms_ms_peak_assignments: [MsMsPeakAssignment, :assignment_view],
sops: [Sop, :file]
}
models.each do |name, (klass, attachment_method)|
Dir.glob("public/system/#{name}/#{attachment_method.to_s.pluralize}/**/*").reject { |f| File.directory?(f) }.each do |path|
client = Elasticsearch::Client.new(log: false, host: SMPDB_ES_URL)
hits = []
search = client.search(index: SMPDB_INDEX, scroll: '5m', body: json)
hits.concat(search['hits']['hits'].map { |hit| SmpdbPathway.new(Hashie::Mash.new(hit['_source'])) })
# Call the `scroll` API until empty results are returned
while search = client.scroll(scroll_id: search['_scroll_id'], scroll: '5m') and not search['hits']['hits'].blank? do
hits.concat(search['hits']['hits'].map { |hit| SmpdbPathway.new(Hashie::Mash.new(hit['_source'])) })
end
@cknoxrun
cknoxrun / a.rb
Created September 18, 2017 21:27
# Don't hide the navbar if it's collapsed i.e. we're on a phone
if $('.omx-site-navbar')
if $('.navbar-toggle').is(":visible")
$('.navbar').removeClass('transparent')
$('.navbar').addClass('visible')
$('.navbar-brand').show()
# Only toggle the navbar on the home page when it's not collapsed
$(window).scroll ->
if !$('.navbar-toggle').is(":visible")
# Set distance user needs to scroll before we the navbar switches
@cknoxrun
cknoxrun / a.rb
Created September 18, 2017 21:27
# Don't hide the navbar if it's collapsed i.e. we're on a phone
if $('.omx-site-navbar')
if $('.navbar-toggle').is(":visible")
$('.navbar').removeClass('transparent')
$('.navbar').addClass('visible')
$('.navbar-brand').show()
# Only toggle the navbar on the home page when it's not collapsed
$(window).scroll ->
if !$('.navbar-toggle').is(":visible")
# Set distance user needs to scroll before we the navbar switches
@cknoxrun
cknoxrun / a.rb
Created September 12, 2017 17:11
{
"height": "2.3",
"height_unit": "m",
"weight": "190",
"weight_unit": "lbs",
"current_address": "9044 92 St NW, Edmonton AB Canada",
"occupation": "Programmer",
"highest_education_level": "Undergraduate",
"backgrounds": [
"",
{
"auto_complete": true,
"auto_complete_commit_on_tab": true,
"auto_indent": true,
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"create_window_at_startup": false,
"default_encoding": "UTF-8",
"default_line_ending": "unix",
"font_size": 17,
"highlight_line": false,
brew install mariadb redis sl jq readline git wget chruby ruby-install sift gist bash-completion