Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / sharing-a-devise-user-session-across-subdomains.md
Created July 21, 2014 10:05
sharing a devise user session across subdomains within rails 4 and devise 3

sharing-a-devise-user-session-across-subdomains

two key words, sample cookie_store key and secret_key_base devise_secret_key

Rails.application.config.session_store :cookie_store, key: "vcooline_ikcrm#{Rails.env}_#{SESSION_DOMAIN.try(:underscore)}_session", :domain => :all, :expire_after => 86400*90, :tld_length => 2

You might get weird things like halfway Devise sessions sharing, but only allowing you to create and destroy the session on the root domain. Using :all works great if you’re using localhost, but when I started using lvh.me:3000 for testing I had those problems (lvh.me stands for local vhost me and is a domain that simply points to localhost which makes for zero-config subdomain development. It’s super handy.).

get 'crm_base_agent/', to: "crm_base_agent#index"

@runlevel5
runlevel5 / puma.sh
Last active July 18, 2022 17:37
pumactl is very broken, @nemshilov and @joneslee85 wrote this bash script replacement and it works so reliably on production server. So here it is, share with the world!
#!/usr/bin/env bash
# Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
# Please modify the CONSTANT variables to fit your configurations.
# The script will start with config set by $PUMA_CONFIG_FILE by default
PUMA_CONFIG_FILE=config/puma.rb
PUMA_PID_FILE=tmp/pids/puma.pid
PUMA_SOCKET=tmp/sockets/puma.sock
@seanlilmateus
seanlilmateus / evernote.rb
Last active January 25, 2016 19:24
ScriptingBridge with MacRuby or Rubymotion
#!/Library/RubyMotion/bin/ruby -wKUW0
# if your using MacRuby you might change this to
# => #!/usr/bin/env macruby -wKUW0
framework 'Foundation'
framework 'ScriptingBridge'
# the original is part of an arstechnica article by Ryan
# SOURCE: http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/
# this script with get your favourite songs and create a Evernote Note # German and English
@mariovisic
mariovisic / factory_girl.rb
Created March 22, 2013 04:56
Do not allow Factory Girl usage in unit tests.
# spec/support/factory_girl.rb
# This file is here to limit the use of factories to only integration tests and not unit tests.
#
# If you really want to use a factory you can add the tag :factories to a test
#
module FactoryGirlBlocker
mattr_accessor :disabled
def self.with_disabled
self.disabled = true
@branch14
branch14 / ruby-signaturepad-to-image.rb
Created December 11, 2012 14:15
convert json signatures captured by thomasjbradley's signature-pad to an image
# see https://github.com/thomasjbradley/signature-pad for more details
instructions = JSON.load(data).map { |h| "line #{h['mx']},#{h['my']} #{h['lx']},#{h['ly']}" } * ' '
system "convert -size 198x55 xc:transparent -stroke blue -draw '#{instructions}' signature.png"
@minhajuddin
minhajuddin / deploy.rake
Created August 23, 2012 05:59 — forked from njvitto/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
@stas
stas / config.ru
Created August 13, 2012 21:03
Rack app for serving static files (ex. on Heroku), handles haml if any, just drop it in compass project dir.
require 'haml'
# Do not buffer output
$stdout.sync = true
# Get working dir, fixes issues when rackup is called outside app's dir
root_path = Dir.pwd
use Rack::Static,
:urls => ['/stylesheets', '/images', '/javascripts', '/fonts'],
:root => root_path
@equivalent
equivalent / app-assets-javascript-datepicker.js.coffee
Created July 5, 2012 12:24
Simple Form custom input for "Datepicker for Twitter Bootstrap" running under Ruby on Rails with Ransack search
# install and make run basic bootstrap date-picker functionality described here http://www.eyecon.ro/bootstrap-datepicker/
# app/assets/javascript/datepicker.js.coffee
$(document).on 'pageChanged', ->
# datepicker for simple_form & Ransack
$(".custom_datepicker_selector").datepicker().on 'changeDate', (en) ->
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2) # date format yyyy-mm-dd
$(this).parent().find("input[type=hidden]").val(correct_format)
@chsh
chsh / app_delegate.rb
Created May 7, 2012 10:18
Example to use UIWebView for RubyMotion.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
@window.rootViewController = GoogleViewController.alloc.init
@window.makeKeyAndVisible
true
end
end
@kinopyo
kinopyo / gist:2343176
Created April 9, 2012 12:37
Override Devise RegistrationsController, override redirect path after updating user

Override Devise RegistrationsController

Overview

Here I'll show you

  • How to override devise registrations_controller(related to create/update user account)
  • How to change redirect path after updating user

Override RegistrationsController