Skip to content

Instantly share code, notes, and snippets.

View toddsiegel's full-sized avatar

Todd Siegel toddsiegel

  • Solera Software, Inc.
  • Denver, CO
  • 18:25 (UTC -06:00)
View GitHub Profile
@toddsiegel
toddsiegel / setup.md
Last active July 14, 2017 18:01
Setting up a sane Rails development environment on Mint Linux

Installing rebenv

Mint comes with a ruby package installed. It is installed as the root user and is not the latest version. We want the flexibility to install the latest version, to be able to easily upgrade and not have the hassles of installing gems as root.

To do this we need to use Ruby environment manager. This allows everyone on your team to be on the same version of Ruby, regardless of OS. This can be locked in with a .ruby-version in the root directory of your project.

I recommend rbenv to do this.

Dependencies

The software we're installing needs a few dependencies installed in order to work.

@toddsiegel
toddsiegel / mysql_admin.sql
Created February 14, 2018 18:43
MySQL Admin Queries
SELECT t.table_name, ccsa.character_set_name
FROM information_schema.tables t
JOIN information_schema.collation_character_set_applicability ccsa
ON ccsa.collation_name = t.table_collation
WHERE t.table_schema = '<schema_name>'
ORDER BY t.table_name
gem 'pg'
gem 'puma'
gem 'rack-attack'
gem 'rollbar'
gem_group :development, :test do
gem 'rubocop'
end
gem_group :test do
@toddsiegel
toddsiegel / file.sh
Created November 6, 2018 20:37
Useful bash stuff
# `read`
## Basic usage
$ read -p "Useful prompt goes here"
## Use readline
$ read -e -p "..."
@toddsiegel
toddsiegel / introspection.sql
Last active December 29, 2023 21:35
Helpful PostgreSQL Queries
-- List all Foreign Keys
select kcu.table_schema || '.' ||kcu.table_name as foreign_table,
'>-' as rel,
rel_tco.table_schema || '.' || rel_tco.table_name as primary_table,
string_agg(kcu.column_name, ', ') as fk_columns,
kcu.constraint_name
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu
on tco.constraint_schema = kcu.constraint_schema
and tco.constraint_name = kcu.constraint_name
@toddsiegel
toddsiegel / LogEntry.java
Last active August 21, 2019 21:29
Ingesting a CSV using OpenCSV
package com.solera.domain;
import com.opencsv.bean.CsvBindByName;
import java.util.Objects;
public class LogEntry {
@CsvBindByName(column = "insertId")
private String insertId;
@toddsiegel
toddsiegel / download_csv.js
Last active June 24, 2020 21:35
Client-side CSV Download
const exportRows = [
["Name", "Email"],
["Foo Bar", "[email protected]"]
];
const csvContent = "data:text/csv;charset=utf-8," + exportRows.map((e) => e.join(",")).join("\n");
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "export.csv"); // https://caniuse.com/#feat=download
@toddsiegel
toddsiegel / README.md
Created October 28, 2020 20:09 — forked from tristanm/README.md
Migrating a Rails project from MySQL to PostgreSQL

Migrating a Rails project from MySQL to PostgreSQL

This brief guide is written from my own experience with migrating a large (~5GB) MySQL database to PostgreSQL for a Rails project.

No warranties, guarantees, support etc. Use at your own risk and, as always, ENSURE YOU MAKE BACKUPS FIRST!

I chose [pgloader][1] because it's extremely fast. YMMV.

  1. Replace mysql2 gem with pg in Gemfile.
  2. Update config/database.yml for PostgreSQL. I used [Rails' template][2] as a starting point.
@toddsiegel
toddsiegel / uses_tempfile.rb
Created July 23, 2021 19:28
Ruby and Rails Utiilities
# frozen_string_literal: true
module UsesTempfile
def with_tempfile(name: 'temp-zip-file', temp_dir: Rails.root.join('tmp').to_s, binmode: false)
tempfile = Tempfile.new('temp-zip-file', temp_dir)
tempfile.binmode if binmode
yield tempfile
ensure
tempfile.close
@toddsiegel
toddsiegel / aws.md
Last active August 18, 2021 20:30
Cheatsheets

Get object count

$ aws s3 ls s3://<bucketname> --recursive | wc -l