Skip to content

Instantly share code, notes, and snippets.

View qichunren's full-sized avatar
🌈
Focusing contribute

Qichunren qichunren

🌈
Focusing contribute
View GitHub Profile
jruby 1.6.4或者ruby-1.9.2-p180
Rails 3.0.9
问题描述:
在rails初始化中声明HOST_NAME为一个String,然后在控制器中有这样的代码:
str = "## " + HOST_NAME + " ##"
启动程序的时候会出错(rails s):
然后我将上面的代码改一下子:
@qichunren
qichunren / nginx_config.text
Created August 30, 2011 06:23
nginx config
qichunren@qichunren-desktop:/opt/nginx-1.0.6$ ./configure --help
--help this message
--prefix=PATH set the installation prefix
--sbin-path=PATH set path to the nginx binary file
--conf-path=PATH set path to the nginx.conf file
--error-log-path=PATH set path to the error log
--pid-path=PATH set path to nginx.pid file
--lock-path=PATH set path to nginx.lock file
@qichunren
qichunren / ajax_history.js
Created July 20, 2011 02:33
mark url location history( ajax history)
// mark current location url
$("#nav_ticker").click(function(){
$("#nav ul li").removeClass("active");
$(this).addClass("active");
window.location.hash = "tickers/cp";
});
$("#nav_announce").click(function(){
$("#nav ul li").removeClass("active");
$(this).addClass("active");
@qichunren
qichunren / static_page_generator.rb
Created June 22, 2011 15:02
StaticPageGenerator
# encoding: utf-8
require File.expand_path("../../config/environment", __FILE__)
require File.expand_path("../../app/helpers/application_helper", __FILE__)
class StaticPageGenerator
attr_reader :source_dir, :output_dir
def initialize(output_dir=Rails.root.join("html"))
@source_dir = Rails.root.join("themes/default/views")
@output_dir = output_dir
@qichunren
qichunren / Readme.md
Created May 12, 2011 09:20
growlnotify
@qichunren
qichunren / auto_pull.sh
Created April 28, 2011 01:55
运用expect自动输入密码
qichunren@ubuntu:~/repos$ cat auto_pull.sh
#!/usr/bin/expect
set timeout 30
cd /home/qichunren/repos/web_backend
spawn git pull --rebase
expect "[email protected]'s password:"
send "secretpassword\r"
send "\r"
sleep 10
@qichunren
qichunren / Capybara_demo.rb
Created March 24, 2011 06:57
这个用来测试业务流程操作,以test_开头的public方法都会执行
# encoding: utf-8
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
# require 'capybara/rspec'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://cqrorx.com:3000'
Capybara.default_wait_time = 4
namespace :dev do
task :s do
sh "thin start -d -e production -p 5000"
end
task :stop do
sh "kill -9 `cat tmp/pids/thin.pid`"
end
@qichunren
qichunren / application_controller.rb
Created March 9, 2011 09:24
login from http basic authcation
class ApplicationController < ActionController::Base
USER_NAME, PASSWORD = "xx", "secret"
protect_from_forgery
before_filter :login_from_http_auth
protected
def login_from_http_auth
authenticate_or_request_with_http_basic do |user_name, password|
user_name == USER_NAME && password == PASSWORD
@qichunren
qichunren / new.html.erb
Created February 28, 2011 07:15
使用bbcode编辑器
<%= content_for :html_head do %>
<%= javascript_include_tag "jquery.bbcode.js" %>
<%= javascript_tag do %>
$(function(){
$("#web_message_content").bbcode({tag_bold:true,tag_italic:true,tag_underline:true,tag_link:true,tag_image:true,button_image:true,image_url:'/images/bbcode/'});
$("#bbcode_preview_btn").bind("click", function(){
var bbcode = $("#web_message_content").val();
$.get("/utils/parse_bbcode", {id:bbcode}, function(text){