Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / remote_debug_android_chrome_on_linux.md
Last active August 29, 2015 14:13
remote debug mobile web page on linux through chrome
chrome://inspect/#devices
localhost:8999

chrome://flags/#enable-devtools-experiments

http://www.html5rocks.com/en/tutorials/developertools/revolutions2013/?redirect_from_locale=zh
adb forward tcp:8999 localabstract:chrome_devtools_remote

http://stackoverflow.com/questions/3877027/jquery-callback-on-image-load-even-when-the-image-is-cached
@jhjguxin
jhjguxin / elasticsearch_cn.md
Last active August 29, 2015 14:08
config zh-cn elasticsearch plugin
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 / gitlab.md
Last active August 29, 2015 14:07
gitlab deploy tips
@jhjguxin
jhjguxin / production.rb
Created September 19, 2014 03:59
how to config log level within production env rails + unicorn
# 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 September 4, 2014 03:35
active record timezone without rails

这次应该搞定了

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 August 26, 2014 09:45
Preload, Eagerload, Includes and Joins
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 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"

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 August 29, 2015 13:59 — forked from kares/jquery.parseparams.js
This function is meant to be used with an URL like the window.location
// 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