Skip to content

Instantly share code, notes, and snippets.

View mhw's full-sized avatar

Mark H. Wilkinson mhw

View GitHub Profile
@nsommer
nsommer / time_zone_validator.rb
Created February 7, 2018 17:28
ActiveModel Validator that checks whether the string value of an attribute is a valid ActiveSupport::TimeZone
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:
#
@0xdevalias
0xdevalias / jquery-release-notes.md
Last active July 18, 2022 08:01 — forked from teppeis/jquery-release-notes.md
jQuery Release Notes
@mdo
mdo / 00-intro.md
Last active March 4, 2025 19:03
Instructions for how to affix an Ikea Gerton table top to the Ikea Bekant sit-stand desk frame.

Ikea Bekant standing desk with Gerton table top

@chbrown
chbrown / _upgrade-pg9.4-to-pg9.5.md
Last active October 7, 2021 13:57
Upgrade PostgreSQL 9.4 to 9.5 on Mac OS X with Homebrew

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
@manigandham
manigandham / rich-text-html-editors.md
Last active April 16, 2025 18:28
Rich text / HTML editors and frameworks

Strictly Frameworks

Abstracted Editors

These use separate document structures instead of HTML, some are more modular libraries than full editors

@pixeltrix
pixeltrix / time_vs_datatime.md
Last active April 23, 2025 13:36
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

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
@tristanm
tristanm / README.md
Last active November 22, 2024 15:47
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.
@tenderlove
tenderlove / mt_complete.rb
Last active December 11, 2020 19:56
tab completion for minitest tests
#!/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)