Skip to content

Instantly share code, notes, and snippets.

View sandyxu's full-sized avatar
Working from office

Sandy Xu sandyxu

Working from office
  • Shanghai, China
View GitHub Profile
@sandyxu
sandyxu / es.sh
Last active August 29, 2015 14:17 — forked from rajraj/es.sh
cd ~
sudo yum update
sudo yum install java-1.7.0-openjdk.i686 -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.9.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@sandyxu
sandyxu / nginx.conf
Last active August 29, 2015 14:19
config and redirect all http to https in nginx
upstream ikcrm_www_development_unicorn {
server unix:/tmp/unicorn.ikcrm_www_development.sock fail_timeout=0;
}
server {
listen 80;
server_name test.www.ikcrm.com;
return 301 https://$server_name$request_uri;
}
server {
@sandyxu
sandyxu / _form.html.erb
Created June 11, 2015 05:13
how to use carrierwave
<%= form_for Attachment.new do |f| %>
<%= f.label :file, '上传文档', class: 'btn btn-primary btn-sm' %>
<%= f.file_field :file %>
<span class="text-danger">文件大小不能超过20M</span>
<%= f.submit 'save', class: 'btn btn-primary btn-sm' %>
<% end %>
@sandyxu
sandyxu / seo-wiki.md
Created June 11, 2015 06:04
seo 优化细节

一、链接伪静态问题 1、分类链接,如:http://www.ikcrm.com/news?q%5Bnews_type_eq%5D=1应伪静态重写成http://www.ikcrm.com/news/type/1 2、标签链接,如:http://www.ikcrm.com/news?q%5Btags_blogs_tag_id_eq%5D=4应伪静态重写成http://www.ikcrm.com/news/tag/4 3、分页标签,如:http://www.ikcrm.com/news?page=2应为伪静态重写为http://www.ikcrm.com/news/page/2

二、标签使用问题 1、h1标签,每个页面有且仅可使用一次;h2标签每个页面可使用多次。(全站所有页面均须自从此规则) 2、首页h1标签重复使用 3、首页新闻列表页未使用h2标签,新闻标题使用h2标签 4、新闻中心(http://www.ikcrm.com/news)h2标签应分配给每条新闻标题

@sandyxu
sandyxu / gem-env-path
Last active October 28, 2015 03:07
Display information about the RubyGems environment
gem help environment
Arguments:
packageversion display the package version
gemdir display the path where gems are installed
gempath display path used to search for gems
version display the gem format version
remotesources display the remote gem servers
platform display the supported gem platforms
<omitted> display everything

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@sandyxu
sandyxu / omniauth.rb
Last active December 21, 2015 04:08
OmniAuth should set config.on_failure
# 在OmniAuth时触发异常被web server捕获直接返回500页面,如果想捕获并处理要做如下设置
# config/initializers/omniauth.rb
OmniAuth.config.on_failure = AuthenticationsController.action(:failure)
# log 输出
OmniAuth.config.logger = Rails.logger
@sandyxu
sandyxu / why-new-issue-github
Created August 20, 2013 01:37
Why star from 'New Issue' on GitHub
在GitHub里 Issue是我们的任务管理,代码跟踪,意见反馈的根源。通过对 Issue, 添加 Milestones进行进度管理;
及时调整Issue的状态,便于了解进度;添加Label,有助于区分Issue的性质。每次代码的提交最好都有对应的Issue,
便于浏览任务对应的代码,直接对每行代码评论,反馈。尤其是对程序员永远的沟通能力和思维定式,减少了沟通中的上下文。
这样一套下了,会减少很多沟通成本。
建议每个提交代码的人先在GihHub 添加或找到一个 Issue,充分利用这套系统带给我们的便利。
提交代码,从 New Issue 开始!!!
@sandyxu
sandyxu / safe_continue_redirect.rb
Last active December 21, 2015 11:59
防止浏览器存在url跳转漏洞被利用钓鱼
# 来自wooyun的白帽子安全 http://www.wooyun.org/bugs/subtype-65/page/1
# 通过params[:continue] 的安全url进行跳转
def safe_continue_redirect(continue = params[:continue])
if continue
redirect_to safe_continue_url(continue)
else
redirect_to(root_path)
end
end
@sandyxu
sandyxu / git-diary.txt
Last active December 21, 2015 14:08
git, skills, expertise, config, autocomplete command
# git 命令自动提示 blog:
http://code-worrier.com/blog/autocomplete-git/
# 安装git命令自动提示后很爽,但是删除后的branch由于缓存,仍然提示出来,导致提示过多且混乱。通过查看
$ git remote show origin
* remote origin
Fetch URL: git@github.com/sandyxu/xx.git
Push URL: git@github.com/sandyxu/xx.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
master
next