Skip to content

Instantly share code, notes, and snippets.

View songjiayang's full-sized avatar
🏃‍♂️
keep going

songjiayang songjiayang

🏃‍♂️
keep going
View GitHub Profile
@songjiayang
songjiayang / gist:5559542
Created May 11, 2013 10:25
mechanize cookie...
def get_cookie
buffer = StringIO.new
@agent.cookie_jar.dump_cookiestxt(buffer)
buffer.string
end
def set_cookie cookie
@agent.cookie_jar.load_cookiestxt(cookie) unless cookie.blank?
end
@songjiayang
songjiayang / gist:5567955
Last active December 17, 2015 06:48
cap deploy.rb
namespace :deploy do
desc "重启服务器"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
desc "在本地生成配置文件"
task :setup_local_configs do
@songjiayang
songjiayang / gist:5568731
Created May 13, 2013 14:33
pdf to image..
#方法一: Pdf To Images
# 将pdf 转化为image,主要用的Magick,找到两个方法,基本都相同
#function1
pdf =Magick::ImageList.new("test.pdf")
pdf.write("demo.jpg")
#function2
pdf= Magick::Image.read("test.pdf")
def parse_to_png(pdf_file)
pdf = Magick::ImageList.new(pdf_file)
pdf.each_with_index do |image,index|
thumb = image.scale(1024, 768)
thumb.write("pngs/#{index.to_s}.png")
end
end
@songjiayang
songjiayang / gist:5893318
Created June 30, 2013 00:55
A COMMON DATABASE CONFIG
# in order to DRY,we can use common config
# common config
common: &common
adapter: mysql2
encoding: utf8
pool: 10
username: root
password:
host: localhost
port: 3306
@songjiayang
songjiayang / infinitescroll.coffee
Last active December 20, 2015 09:49
a rails code for infinitescroll
coffee:
$wrapper = $('.js-infinitescroll-wrap')
$wrapper.find('.feed-paging nav.pagination').hide()
$wrapper.infinitescroll
navSelector: "nav.pagination"
nextSelector: "nav.pagination .next a"
itemSelector: ".js-infinitescroll-item"
bufferPx: 150
loading:
img: "/assets/spinner.gif"
@songjiayang
songjiayang / gist:6156446
Last active December 20, 2015 15:48
notify ..
before_save :set_material_should_change_field
after_save :change_material_attributes
def set_material_should_change_field
option_changed_attributes = self.changed_attributes
@change_field = {}
if self.new_record?
@change_field.merge!( { :price => true, :lead_time => true } )
elsif option_changed_attributes.include?('price_min') || option_changed_attributes.include?('price_max')
@songjiayang
songjiayang / gist:6290168
Created August 21, 2013 03:53
rails template..
# 更换源
comment_lines "Gemfile", /source .http.*/
add_source "http://ruby.taobao.org"
# HTML模板
gem 'slim'
# 单点登录
gem 'rubycas-client'
@songjiayang
songjiayang / infinitescroll_kaminari.coffee
Created August 23, 2013 04:02
a plugin for infinitescroll with kaminari to auto scroll load page
//= require jquery
//= require gigabase
$ ->
$('.infinitescroll_wrapper').each ->
$wrapper = $(this)
$wrapper.find('.feed-paging nav.pagination').hide()
$wrapper.infinitescroll
navSelector: "nav.pagination"
nextSelector: "nav.pagination .next a"
@songjiayang
songjiayang / active_slider.coffee
Last active December 22, 2015 08:39
使用js 添加 actived link ...
class MessageSidebar
constructor: (element) ->
$element = $(element)
compose_regex = "messages\/new"
inbox_regex = 'messages'
outbox_regex = "messages\/outbox"
archived_regex = "messages\/archived"
trash_regex = "messages\/trash"
if window.location.pathname.match(compose_regex)