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"

@jhjguxin
jhjguxin / deploy.rb
Last active May 10, 2019 03:37
use qiniu to speed up your site asset file load time
set :linked_files, %W{
... config/app.god config/qrsync.json
config/application.yml
}
# you should remove bin from linked_dirs config
# https://github.com/capistrano/bundler/issues/45
set :linked_dirs, %w{config/unicorn log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
@jhjguxin
jhjguxin / puppeteer.md
Created April 4, 2019 03:03
headless browser
@jhjguxin
jhjguxin / how_to_concerns.md
Last active November 28, 2018 17:16 — forked from dhh/gist:1014971
how to concerns with rails 3
@jhjguxin
jhjguxin / deploy.rb
Created August 31, 2012 10:38 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@jhjguxin
jhjguxin / hostapd-ubuntu.md
Last active November 9, 2018 18:44
make a Virtual Router (soft wifi host ap) on Ubuntu 13.04 Ubuntu 15
@jhjguxin
jhjguxin / ringbuffer.rb
Created October 29, 2018 12:00 — forked from eerohele/ringbuffer.rb
A simple ring buffer for Ruby.
class RingBuffer < Array
attr_reader :max_size
def initialize(max_size, enum = nil)
@max_size = max_size
enum.each { |e| self << e } if enum
end
def <<(el)
if self.size < @max_size || @max_size.nil?
@jhjguxin
jhjguxin / string_ext_lib.js
Created November 26, 2012 03:33
js字符串函数
/*JS自带函数
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
@jhjguxin
jhjguxin / rails-install-ubuntu.sh
Created July 19, 2012 14:15 — forked from paav-o/rails-install-ubuntu.sh
rails-install-ubuntu
echo "Updates packages. Asks for your password."
sudo apt-get update -y
echo "Installs packages. Give your password when asked."
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev -y
echo "Installs ImageMagick for image processing"
sudo apt-get install imagemagick --fix-missing -y
echo "Installs RVM (Ruby Version Manager) for handling Ruby installation"