Skip to content

Instantly share code, notes, and snippets.

@jspooner
jspooner / time.rb
Created March 31, 2011 15:56
Extend the Ruby Time object with a method that will find the next weekday.
class Time
class << self
def next(day, from = nil)
day = [:sunday,:monday,:tuesday,:wednesday,:thursday,:friday,:saturday].find_index(day) if day.class == Symbol
one_day = 60 * 60 * 24
original_date = from || now
result = original_date
result += one_day until result > original_date && result.wday == day
result
end
@coffeencoke
coffeencoke / README.md
Last active May 19, 2017 08:02
Use a sub directory as a rails application's url root rails 3, nginx, unicorn

Symlink for static files

Among applying the changes in the other files in this gist, you need to symlink the directory you are serving the app with in the root app's public directory so that NGINX can serve the static files in the sub-app.

For example, if you have an app at /home/coffeencoke/apps/app.coffeencoke.com/current/public as your root app, and you have the sub app served at http://app.coffeencoke.com/admin, then you need to symlink /home/coffeencoke/apps/admin-app.coffeencoke.com/current/public to /home/coffeencoke/apps/app.coffeencoke.com/current/public/admin like so:

ln -s /home/coffeencoke/apps/admin-app.coffeencoke.com/current/public /home/coffeencoke/apps/app.coffeencoke.com/current/public/admin
@maxivak
maxivak / __readme.md
Last active October 7, 2017 11:15
Deploying Rails app using Docker and Capistrano

Deploying Rails app using Docker and Capistrano

Concept

Remote server:

  • Docker container with Passenger

  • Data volume (directory on the remote host) to store files for the app

  • Directory structure in data volume (directory /data/apps/app1):

@amicming
amicming / rails-5-new-options
Last active January 4, 2018 15:23
Command line options for rails _5.0.0.1_ new --help. Easy to handy when you create rails application
$ rails _5.0.0.1_ new --help
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/apandya/.rvm/rubies/ruby-2.3.3/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
@seyhunak
seyhunak / sidekiq_faye.rb
Created December 17, 2013 08:48
Rails - Sidekiq Middleware to publish to Faye for real time batch status updates
module Sidekiq
module Middleware
module Server
class PublishBatchWorkerCompleted
def call(worker, job, queue)
yield
ensure
begin
unless worker.bid.nil?
@karloku
karloku / README.md
Last active March 30, 2018 07:28
Rails Template using GraphQL

This template is supposed to be applied to rails 5.

run with:

rails new <application_name> --template=https://gist.githubusercontent.com/karloku/edd6a158e275fdefa334/raw/b56175bee5b45d32310aeb620e23be44e3c2a56d/graphql_template.rb -T

using gems:

  • graphql
  • graphql-mutable_type
@os6sense
os6sense / gist:35b9e37eb8f23bdb4a81cde1cc23aa03
Created May 12, 2017 13:26
Using memory_profiler with rails
add to gemfile :
gem 'memory_profiler', require: true, github: 'SamSaffron/memory_profiler'
Add a config/initializer/memory_profiler.rb as follows:
MemoryProfiler.start
at_exit do
report = MemoryProfiler.stop
report.pretty_print
@NullVoxPopuli
NullVoxPopuli / deserialization.md
Last active October 9, 2019 20:30
ActiveModelSerializers vs jsonapi-rb Benchmarks

How to disable page caching with create-react-app

If you currently not using a service worker resulting in old production caches being used and users not getting new versions of the app.

src/index.js

Use:

import { unregister as unregisterServiceWorker } from './registerServiceWorker'