Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / rails_cache_snippet.md
Last active January 3, 2016 14:29
Rails cache (dalli) auto renew before cached entry was expired

Rails cache (dalli) snippet

base on guanxi.me
author: Francis Jiang

usual case

def smart_fetch(name, options, &blk)
  options = HashWithIndifferentAccess.new(options)
@jhjguxin
jhjguxin / prevent_unlimited_increase_of_space_usage_by_mongo_logdb.markdown
Created December 24, 2013 02:48
usually business log split store as per days, but may occupancy space more and more unlimited, so how about repeated use collection name

Prevent unlimited increse of space used by mongo logdb

through Repeated use collection name

6.months.ago.to_date.upto(Date.today)

def generate_syslog_collection_name(date = nil, mod_size = 60)
  date = date.try(:to_date)
  if date.is_a?(Date)
    mod_num = Date.new(2000).upto(date).count % mod_size
@jhjguxin
jhjguxin / Rakefile
Created December 16, 2013 11:09 — forked from vast/Rakefile
require 'my-sinatra-app'
require 'sinatra/activerecord/rake'
desc "run irb console"
task :console, :environment do |t, args|
ENV['RACK_ENV'] = args[:environment] || 'development'
exec "irb -r irb/completion -r my-sinatra-app"
end
@jhjguxin
jhjguxin / byobu-tmux.markdown
Last active December 29, 2015 12:29
byobu tmux

byobu-tmux

sudo apt-get install screen byobu

Byobu包装过的Tmux将其配置文件放在了「~/.byoburc.tmux」下面,因此编辑这个文件,写如以下内容:

set-window-option -g mode-keys vi bind C-h select-pane -L

@jhjguxin
jhjguxin / rails3_with_dalli.md
Created November 19, 2013 07:24
Config Rails 3 with dalli(memcahed)

Config Rails 3 with dalli(memcahed)

To install dalli in your Rails 3 app, simply add the following to your Gemfile and run bundle install.

# Gemfile
gem "dalli", "~> 2.6.4",   :platforms => :ruby

To setup Rails to use the Dalli client for production, add the following to config/environments/production.rb:

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' } 
@jhjguxin
jhjguxin / deploy_ghost_with_heroku.md
Last active December 26, 2015 23:49
ghost with heroku
@jhjguxin
jhjguxin / rails_generate_generate.md
Created October 28, 2013 07:16
Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.

http://guides.rubyonrails.org/generators.html#creating-generators-with-generators

rails generate generator --help
rails generate generator setup_config

First, notice that we are inheriting from Rails::Generators::NamedBase instead of Rails::Generators::Base. This means that our generator expects at least one argument, which will be the name of the initializer, and will be available in our code in the variable name.

@jhjguxin
jhjguxin / mysql-engines-myisam-vs-innodb.md
Last active December 26, 2015 07:09
MySQL Engines - MyISAM vs Innodb

MySQL Engines - MyISAM vs Innodb

When MyISAM tables are seen to be mostly useful?

There can be several other reasons that fit your requirement for choosing the MyISAM engine. For example reads can be faster on MyISAM vs Innodb despite what the general claims on the above two links when MyISAM table has fixed (not dynamic) row size i.e. when it uses more CHARs for example versus VARCHARs. Still there could be other reasons besides this why you choose or have chosen MyISAM over Innodb. Another reason why you may have chosen MyISAM over Innodb is perhaps due to the fact that Innodb must perform additional checks owing to its ACID compliant nature - so for example a FK check needs to be checked which could potentially cause an operational overhead. Unless you ha