Skip to content

Instantly share code, notes, and snippets.

View pobing's full-sized avatar

Jed pobing

View GitHub Profile
@pobing
pobing / gist:1369089
Last active July 12, 2018 09:34
Ubuntu下Git服务器安装与配置
Ubuntu下Git服务器安装与配置
1. 安装
1.1 安装Git-Core:
sudo apt-get install git-core
1.2 安装 Gitosis
sudo apt-get install python-setuptools
mkdir ~/src
cd ~/src
git clone git://eagain.net/gitosis
@pobing
pobing / gist:1369094
Last active September 28, 2015 02:18
Capybara 获取元素 支持JS &jquery
Scripting
一、In drivers which support it, you can easily execute JavaScript:
page.execute_script("$('body').empty()")
For simple expressions, you can return the result of the script. Note that this may break with more complicated expressions:
result = page.evaluate_script('4 + 4');
二、 page.execute_script("$('div:eq(0)').length")
page.execute_script("document.getElementById('wrapper')")
@pobing
pobing / gist:1369125
Last active September 28, 2015 02:18
Rspec+capybara get page Element
模拟浏览器,人工测试
1. 文本框:
直接填充 : fill_in("#{@user.id}_name",:with=>"jdo")
通过节点赋值 : find(:xpath,"//html/body/div[2]/div[2]/div/div/div[3]").set("123456")
获取文本框值: find(:xpath,"//html/body/div[2]/div[2]/div/div/div[3]").value.should=="expect value"
@pobing
pobing / rails deploying
Created December 9, 2011 10:22
Deploying a Ruby on Rails application Nginx & Apache
一 、Apache with passenger deploying rails project
1. 安装好 ror 环境
bundle exec rake RAILS_ENV=production db:create
bundle exec rake RAILS_ENV=production db:migrate
2. 安装apache
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
3.安装 passenger
sudo gem install passenger
sudo passenger-install-apache2-module
4. 按照提示 编辑 httpd.conf ,并添加如下配置
@pobing
pobing / nginx.conf
Created February 24, 2012 06:54 — forked from huacnlee/nginx.conf
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;
@pobing
pobing / gist:5537643
Created May 8, 2013 01:53
send email for many users
nletter = "...whatever..."
Newsletter.all.each do |user|
Mailer.deliver_letter(nletter, user)
end
# And your mailer function would look like:
def letter(nletter, user)
@nletter = nletter
mail(:to => user.email, :subject => @nletter.subject)
end
@pobing
pobing / gist:11238340
Last active July 4, 2018 10:16
ruby 使用HMAC算法得到加密字符串
#(1) 把timestamp和token联合;
# (2) 使用HMAC算法得到加密字符串(将appkey作为参数并使用SHA256 哈希方法);
# (3) 比较signature和得到的加密字符串。
timestamp = "1398236282767"
token = "THd78OwTxVGjTgCYSOxr4vkCPj3oIUg1TpZgkYpjerT2zNWdPQ"
signature = "df5fc888e86c8032f0c6b56e91ab91ebdfdae297e7a1dd4983e2e091042c151e"
data = timestamp + token
appkey = 'bl92t6tw-55zn-h14y-uzpd-y52k7jqe5s'
require "rubygems"
require "bundler/setup"
require "stringex"
## -- Rsync Deploy config -- ##
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user = "user@domain.com"
ssh_port = "22"
document_root = "~/website.com/"
rsync_delete = false
@pobing
pobing / gist:08e89527740124d4e77d
Created May 7, 2014 10:30
pony send mail demo
require 'pony'
mails = {:to=>"jidongdong@admaster.com.cn",
:subject=>"问答箱子找回密码",
:from=>"panel_sys@admaster.com.cn",
:html_body=>"html body",
:via=>"smtp",
:via_options=>{
:address => 'smtp.exmail.qq.com',
:port => '25',
:user_name => 'panel_sys@admaster.com.cn',
@pobing
pobing / gist:3bbbb1aec3a033a8c2e3
Created June 6, 2014 02:00
sinatra download file demo
# list
get '/' do
list = Dir.glob("./files/*.*").map{|f| f.split('/').last}
# render list here
end
# upload
post '/' do
tempfile = params['file'][:tempfile]
filename = params['file'][:filename]