Skip to content

Instantly share code, notes, and snippets.

Avatar

jhjguxin jhjguxin

View GitHub Profile
@jhjguxin
jhjguxin / elasticsearch_cn.md
Last active Aug 29, 2015
config zh-cn elasticsearch plugin
View elasticsearch_cn.md
https://github.com/medcl/elasticsearch-analysis-ik/archive/v1.2.6.zip
unzip v1.2.6.zip


sudo -i

cd /usr/share/elasticsearch
cd plugins
bin/plugin -install medcl/elasticsearch-analysis-ik/1.2.6
@jhjguxin
jhjguxin / production.rb
Created Sep 19, 2014
how to config log level within production env rails + unicorn
View production.rb
# Set to :debug to see everything in the log.
config.log_level = ENV["LOG_LEVEL"].present? ? ENV["LOG_LEVEL"] : :info
@jhjguxin
jhjguxin / active_record_timezone.md
Created Sep 4, 2014
active record timezone without rails
View active_record_timezone.md

这次应该搞定了

Francis.J 2014-9-4 11:30:02

zone_default = Time.find_zone!("Asia/Shanghai")
Time.zone_default = zone_default

ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
@jhjguxin
jhjguxin / active_record_join_dup.md
Created Aug 26, 2014
Preload, Eagerload, Includes and Joins
View active_record_join_dup.md
user_id = 11

Task.joins("left JOIN ownerships ON ownerships.subject_id = tasks.id AND ownerships.subject_type = 'Task'").where("ownerships.subject_type" => "Task", user_id: 11).select("distinct '#{subject_klass.table_name}.id'").select("#{subject_klass.table_name}.*")

Task.joins("left JOIN ownerships ON ownerships.subject_id = tasks.id AND ownerships.subject_type = 'Task'").where("ownerships.subject_type" => "Task", user_id: 11).group("#{subject_klass.table_name}.id")
@jhjguxin
jhjguxin / sharing-a-devise-user-session-across-subdomains.md
Created Jul 21, 2014
sharing a devise user session across subdomains within rails 4 and devise 3
View sharing-a-devise-user-session-across-subdomains.md

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"
View each_slice.js
Array.prototype.each_slice = function (size, callback){
for (var i = 0, l = this.length; i < l; i += size){
callback.call(this, this.slice(i, i + size));
}
};
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each_slice(3, function (slice){
console.log(slice);
});
@jhjguxin
jhjguxin / jquery.parseparams.js
Last active Aug 29, 2015 — forked from kares/jquery.parseparams.js
This function is meant to be used with an URL like the window.location
View jquery.parseparams.js
// Add an URL parser to JQuery that returns an object
// This function is meant to be used with an URL like the window.location
// Use: $.parseParams('http://mysite.com/?var=string') or $.parseParams() to parse the window.location
// Simple variable: ?var=abc returns {var: "abc"}
// Simple object: ?var.length=2&var.scope=123 returns {var: {length: "2", scope: "123"}}
// Simple array: ?var[]=0&var[]=9 returns {var: ["0", "9"]}
// Array with index: ?var[0]=0&var[1]=9 returns {var: ["0", "9"]}
// Nested objects: ?my.var.is.here=5 returns {my: {var: {is: {here: "5"}}}}
// All together: ?var=a&my.var[]=b&my.cookie=no returns {var: "a", my: {var: ["b"], cookie: "no"}}
// You just cant have an object in an array, ?var[1].test=abc DOES NOT WORK
View wshop_api.markdown
# app/grape/api.rb
###
# http://intridea.github.io/grape/docs/index.html
# http://blog.brunoscopelliti.com/authentication-to-a-restful-web-service-in-an-angularjs-web-app
# http://stackoverflow.com/questions/21255203/angularjs-clientside-routing-and-token-authentication-with-webapi
###
class API < Grape::API
  # prefix "api"
  # version 'v1'