Skip to content

Instantly share code, notes, and snippets.

View philsmy's full-sized avatar

Phil Smy philsmy

View GitHub Profile
@philsmy
philsmy / 00_create_deploy_user.sh
Last active October 14, 2024 14:49
Scripts for configuring an Ubuntu 22 machine (these don't work for 24). Use the first file to create the `deploy` user. Use the other files AS the deploy user to install all you need.
#!/bin/bash
set -euo pipefail
########################
### SCRIPT VARIABLES ###
########################
# Name of the user to create and grant sudo privileges
USERNAME=deploy
@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 / debug_rails.md
Created August 8, 2021 07:18
Debugging Ruby on Rails Cheatsheet
@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
@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