$ rails g model User
belongs_to
has_one
| # NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776 | |
| $ cd /usr/src | |
| $ wget http://nginx.org/download/nginx-1.2.1.tar.gz | |
| $ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz | |
| $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz | |
| $ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz | |
| $ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz |
| literally always have to look up the meaning of :limit in migrations when it comes to integer values. Here's an overview. Now let's memorise it (oh, this works for MySQL, other databases may work differently): | |
| :limit Numeric Type Column Size Max value | |
| 1 tinyint 1 byte 127 | |
| 2 smallint 2 bytes 32767 | |
| 3 mediumint 3 byte 8388607 | |
| nil, 4, 11 int(11) 4 byte 2147483647 | |
| 5..8 bigint 8 byte 9223372036854775807 | |
| Note: by default MySQL uses signed integers and Rails has no way (that I know of) to change this behaviour. Subsequently, the max. values noted are for signed integers. |
| # Don't need passwords in test DB to be secure, but we would like 'em to be | |
| # fast -- and the stretches mechanism is intended to make passwords | |
| # computationally expensive. | |
| module Devise | |
| module Models | |
| module DatabaseAuthenticatable | |
| def valid_password?(password) | |
| return false if encrypted_password.blank? |
| # Log kernel generated UFW log messages to file | |
| :msg,contains,"[UFW " /var/log/ufw.log | |
| # Uncomment the following to stop logging anything that matches the last rule. | |
| # Doing this will stop logging kernel generated UFW log messages to the file | |
| # normally containing kern.* messages (eg, /var/log/kern.log) | |
| #& ~ |
| module MyApp | |
| class Application < Rails::Application | |
| if Rails.env == 'test' | |
| require 'diagnostic' | |
| config.middleware.use(MyApp::DiagnosticMiddleware) | |
| end | |
| end | |
| end |
| # Rails 4 | |
| require 'action_view/helpers/asset_url_helper' | |
| module ActionView | |
| module Helpers | |
| module AssetUrlHelper | |
| def accept_encoding?(encoding) | |
| request = self.request if respond_to?(:request) | |
| return false unless request |
| # This is an example resource file for rTorrent. Copy to | |
| # ~/.rtorrent.rc and enable/modify the options as needed. Remember to | |
| # uncomment the options you wish to enable. | |
| # Maximum and minimum number of peers to connect to per torrent. | |
| min_peers = 1 | |
| max_peers = 100 | |
| # Same as above but for seeding completed torrents (-1 = same as downloading) |
| Get the Heroku db as detailed here: | |
| http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup | |
| 1. heroku pgbackups:capture | |
| 2. heroku pgbackups:url <backup_num> #=>backup_url | |
| - get backup_num with cmd "heroku pgbackups" | |
| 3. curl -o latest.dump <backup_url> | |
| Then locally do: | |
| $ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump |
| # Adapted from a C# example here: | |
| # http://stackoverflow.com/questions/43224/how-do-i-calculate-a-trendline-for-a-graph | |
| # And thanks to John Esser for helping figure out how to | |
| # calculate the targets to stabilize a negative slope! | |
| class LinearRegression | |
| attr_accessor :slope, :intercept | |
| # Pass in an array of values to get the regression on |