class TimeZoneValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless ActiveSupport::TimeZone[value] | |
record.errors[attribute] << (options[:message] || 'is not a valid time zone!') | |
end | |
end | |
end | |
# Usage with rails: | |
# |
First, check your current config (example output in homebrew.mxcl.postgresql.plist.xml
lower down in this gist):
cat ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Most importantly, note the -D /usr/local/var/postgres
argument.
Second, shut down your current PostgreSQL.
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- Mobiledoc - github.com/bustle/mobiledoc-kit - framework to build editors with a standardized JSON structure
- ShareDB - github.com/share/sharedb - framework to sync any JSON document using operational transforms, add real-time collaborative editing to anything else
- Bangle.dev - github.com/bangle-io/bangle.dev - toolkit built for building editors, based on prosemirror
These use separate document structures instead of HTML, some are more modular libraries than full editors
It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time
class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime
steps in:
>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
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.
#!/usr/bin/env ruby --disable-gems | |
# Tab completion for minitest tests. | |
# | |
# INSTALLATION: | |
# | |
# 1. Put this file in a directory in your $PATH. Make sure it's executable | |
# 2. Run this: | |
# | |
# $ complete -o bashdefault -f -C /path/to/this/file.rb ruby |
#!/usr/bin/env bash | |
DATABASE_NAME=your_db_name | |
BACKUP_PATH=/home/you/backups/db | |
BACKUP_LIMIT=4 | |
pg_dump $DATABASE_NAME | gzip -c > "$BACKUP_PATH"/"$DATABASE_NAME"_`date +"%Y%m%d%H%M"`.sql.gz | |
BC=$(ls $BACKUP_PATH | wc -l) | |
if [ "$BC" -ge "$BACKUP_LIMIT" ]; then | |
ls -t $BACKUP_PATH | tail -$(($BC-$BACKUP_LIMIT)) | xargs -I{} rm $BACKUP_PATH/{} | |
fi |
class X.Example extends X.Object | |
@proxyMethod "attachmentManager.manageAttachment" | |
# Equivalent to: | |
# manageAttachment: -> | |
# @attachmentManager.manageAttachment.apply(@attachmentManager, arguments) | |
@proxyMethod "delegate?.compositionDidChangeDocument" | |
# Equivalent to: | |
# compositionDidChangeDocument: -> | |
# @delegate?.compositionDidChangeDocument?.apply(@delegate, arguments) |