If you need to use Postgis 2.0 with the Rails 3.x series and aren't willing to make the jump to activerecord-postgis-adapter then there are some configuration changes and a little monkeypatching that is necessary. This is my attempt at packaging the config and patches that you'll need for schema dumping, test prep and Travis support.
This file contains hidden or 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 'active_support/json' | |
| require 'benchmark/ips' | |
| require 'dalli' | |
| client = Dalli::Client.new('localhost', namespace: 'json-bm', compress: true) | |
| object = { | |
| id: 1000, | |
| published: false, | |
| posts: [ |
This file contains hidden or 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
| # Two separate multi blocks are used, the first leveraging `get_multi` | |
| Calculating ------------------------------------- | |
| fetch 19 i/100ms | |
| fetch_multi 78 i/100ms | |
| ------------------------------------------------- | |
| fetch 192.2 (±2.1%) i/s - 969 in 5.044695s | |
| fetch_multi 759.7 (±2.5%) i/s - 3822 in 5.034430s |
This file contains hidden or 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
| DATABASE_URL="postgres://username:password@host/database" |
This file contains hidden or 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 'json' | |
| namespace :slack do | |
| def post_to_slack(payload) | |
| slack_subdomain = fetch(:slack_subdomain) | |
| slack_token = fetch(:slack_token) | |
| uri = URI.parse("https://#{slack_subdomain}.slack.com/services/hooks/incoming-webhook?token=#{slack_token}") | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = true |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| backup_dir=/var/backups | |
| database=dscout_production | |
| mkdir -p "$backup_dir" || exit 1 | |
| filename="$database-$(date +%Y-%m-%d).dump" | |
| echo "Backing up $database ..." | |
| pg_dump -Fc -f "$backup_dir/$filename" $database |
This file contains hidden or 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
| DELETE FROM tablename WHERE id NOT IN (SELECT MAX(dup.id) FROM tablename AS dup GROUP BY dup.field1, dup.field2); |
This file contains hidden or 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
| The first pass writes and the second pass reads. | |
| 10_000 Objects: | |
| user system total real | |
| memory-1 1.240000 0.010000 1.250000 ( 1.252629) | |
| memory-2 0.110000 0.000000 0.110000 ( 0.114169) | |
| redis-1 1.930000 0.230000 2.160000 ( 2.300067) | |
| redis-2 0.210000 0.010000 0.220000 ( 0.222959) | |
| dalli-1 1.470000 0.090000 1.560000 ( 1.574031) |
This file contains hidden or 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
| WITH linked AS ( | |
| SELECT id, | |
| lead(id) OVER(ORDER BY id DESC) AS next_id, | |
| lag(id) OVER(ORDER BY id ASC) AS prev_id | |
| FROM snippets | |
| WHERE snippets.mission_id = $1 | |
| ) | |
| SELECT snippets.* FROM snippets, linked WHERE linked.id = $2 AND snippets.id = linked.next_id; |
This file contains hidden or 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
| class CORSHeaders | |
| ACCESS_CONTROL_HEADERS = { | |
| 'Access-Control-Allow-Origin' => '*', | |
| 'Access-Control-Allow-Methods' => 'OPTIONS,GET,PATCH,PUT,POST,DELETE', | |
| 'Access-Control-Expose-Headers' => '', | |
| 'Access-Control-Max-Age' => '1728000', | |
| 'Content-Type' => 'text/plain' | |
| }.freeze | |
| def initialize(app) |