Skip to content

Instantly share code, notes, and snippets.

View philsmy's full-sized avatar

Phil Smy philsmy

View GitHub Profile
@philsmy
philsmy / debug_rails.md
Created August 8, 2021 07:18
Debugging Ruby on Rails Cheatsheet
@philsmy
philsmy / .env
Created January 30, 2022 12:01
The files needed for getting a rails app running with postgres and pulling in the data from your old mysql database. As per my video here: https://youtu.be/2SOfvPZJZoM
PORT=3000
# postgresql
POSTGRES_HOST=localhost
POSTGRES_PORT=54323
POSTGRES_DBUSER=postgres
POSTGRES_PASSWORD=philsmy123
# mysql
MYSQL_DBNAME=lotteryportal_development
@philsmy
philsmy / ontario_controller.rb
Created May 13, 2020 04:10
Getting the data for the Map
# frozen_string_literal: true
class OntarioController < ApplicationController
protect_from_forgery except: :map_data
def map_data
@patients = PatientDatum.where(region: 'ON').group(:reporter, :reporter_latitude, :reporter_longitude, :reporter_website).count
@patient_map = @patients.keys.map do |key|
{
'type': 'Feature',
@philsmy
philsmy / index.html.erb
Last active May 13, 2020 04:00
Some of the code for the Ontario index page of the Covid19 Visualization app
<% content_for :page_header do %>
<style>
#map {
height: 80%;
margin-top: 30px;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
@philsmy
philsmy / patient_datum.rb
Created May 11, 2020 06:06
Class to read in patient data
# frozen_string_literal: true
require 'csv'
class PatientDatum < ApplicationRecord
def self.import_from_csv
columns = %i[external_id episode_date age_group gender acquisition_info outcome reporter reporter_address reporter_city reporter_postal_code reporter_website reporter_latitude reporter_longitude country region]
upsert_columns = %i[episode_date age_group gender acquisition_info outcome reporter reporter_address reporter_city reporter_postal_code reporter_website reporter_latitude reporter_longitude]
values = CSV.read(Rails.root.join('data/conposcovidloc.csv'))[1..-1]
@philsmy
philsmy / filter_controller.js
Last active December 27, 2019 05:48
Select2 and Stimulus with events
import { Controller } from "stimulus"
import $ from 'jquery';
export default class extends Controller {
connect() {
console.log('connecting Filter controller');
$("#subscriber-tags-select").on('select2:select', function () {
@philsmy
philsmy / select2_controller.js
Last active December 27, 2019 05:40
Basics of Select2 and Stimulus
import { Controller } from "stimulus"
import $ from 'jquery';
require("select2/dist/css/select2")
require("select2-bootstrap-theme/dist/select2-bootstrap")
import Select2 from "select2"
export default class extends Controller {
@philsmy
philsmy / homebrew_mysql_57.md
Created July 9, 2018 06:11
How to get homebrew to install and use mysql 5.7 instead of 8 under OSX

Find older mysql versions

brew search mysql

Install 5.7

brew install mysql@5.7

Link it

brew link mysql@5.7 --force --overwrite

mysql2 gem

@philsmy
philsmy / activejob_delayedjob
Created October 15, 2017 04:55
configuring ActiveJob and DelayedJob to have priority
# app/jobs/sample_job.rb
class SampleJob < ActiveJob::Base
queue_as :maintenance
attr_accessor :options
def enqueue(options = {})
self.options = options
super
end
@philsmy
philsmy / gmaps4rails_compare
Created December 11, 2013 23:25
Comparison of old and new calls to gmaps4rails (Google Maps For Rails - https://github.com/apneadiving/Google-Maps-for-Rails)
## gmaps4rails v1
## controller
@json = @shops.to_gmaps4rails do |shop, marker|
marker.infowindow render_to_string(partial: "/shops/map_info_window", locals: { object: shop})
icon_name = "wl_sm_icon"
unless shop.shop_group.nil?
if (shop.shop_group.name.downcase =~ /pen/) != nil