# e.g.
# <table>
# <tbody>
# <tr>
# <td><input name="foo" type="text" /></td>
# <td><input name="bar" type="text" /></td>
#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'sqlite3', '~> 1.4' | |
gem 'activerecord', '7.1.3.4' | |
end | |
require 'sqlite3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- this groups by 5 to keep the length down | |
select length(username) as length, | |
count(*) as count, | |
repeat('*'::text, (COUNT(length(username))::int / 5) + 1) AS histogram | |
from users | |
where username is not null | |
group by length(username) | |
order by length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initialers/generators.rb | |
# This config will not generate the following: | |
# - per model view helpers, or stylesheets | |
# - scaffold.scss | |
# - jbuilder templates, which I only occasionally use | |
# - controller tests, which I don't really use. I do system tests instead. | |
Rails.application.config.generators do |g| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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.
- Replace
mysql2
gem withpg
inGemfile
. - Update
config/database.yml
for PostgreSQL. I used [Rails' template][2] as a starting point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder