Skip to content

Instantly share code, notes, and snippets.

View zhangyuan's full-sized avatar

Yuan Zhang zhangyuan

  • Xi'an, China
  • 22:49 (UTC +08:00)
View GitHub Profile
@zhangyuan
zhangyuan / renren_client.rb
Created October 3, 2012 18:06
a simple renren api client for posting status text
# encoding: utf-8
require 'digest/md5'
require "faraday"
module Renren
class Client
def self.sign(params)
str = params.map {|k, v| "#{k}=#{v}"}.sort.join
str << secret
@zhangyuan
zhangyuan / gist:3828719
Created October 3, 2012 18:13
Send douban text status by curl
curl -i -H "Authorization: Bearer {access_token}" -F source={api_key}-F text={text} https://api.douban.com/shuo/v2/statuses/
@zhangyuan
zhangyuan / gist:3828857
Created October 3, 2012 18:32
Taobao API parameters handler module.
# encoding: utf-8
# include Taobao::Parameters module, then call #params=() instance method to set more parameters ( method_name, etc.) and call
# #params_after_sign to get the full url query parameters after signing.
require 'digest/md5'
module Taobao
module Parameters
def self.included(base)
@zhangyuan
zhangyuan / gist:3883655
Created October 13, 2012 07:26
Generate favicon with ImageMagick
convert favicon.png -colors 256 -resize 32x32 -transparent white favicon.ico
@zhangyuan
zhangyuan / gist:4015104
Created November 5, 2012 03:07
bootstrap nav_list rendering helper
module ApplicationHelper
# render nav list for twitter bootstrap.
# define the nav list items.
def nav_list
[
[:a, 'A', 'http://example.com/a'],
[:b, 'B', 'http://example.com/b'],
[:c, 'C', 'http://example.com/c'],
[:d, 'D', 'http://example.com/d'],
@zhangyuan
zhangyuan / Rakefile
Created November 6, 2012 19:17
Generate html pages from Slim templates
require 'fileutils'
task :default => [:generate]
# put Slim templates under templates/ directory. run `rake generate` to generate html pages into public/ directory.
desc 'Generate html pages from Slim templates'
task :generate do
base_path = File.dirname(__FILE__)
templates_path = File.join(base_path, 'templates')
@zhangyuan
zhangyuan / editor.js.coffee
Created November 10, 2012 11:26
A pretty simple rich text editor sample.
window.Editor =
create : (text_area_id) ->
$("#" + text_area_id).hide()
editor_id = "editor_" + text_area_id
iframe_html = "<iframe id= " + editor_id + " style='width: 100%; height: 500px;'>
<!DOCTYPE html>
<html>
<head><meta charset='utf-8' /><title></title>
<body>
</body>
@zhangyuan
zhangyuan / environment.rb
Created December 3, 2012 07:34
use define_method to define class method
# via: http://stackoverflow.com/questions/752717/how-do-i-use-define-method-to-create-class-methods
class Environment
def self.current
ENV['APP_ENV'] ||= 'development'
end
%w(development product test).each do |environment|
(class << self; self; end).instance_eval do
define_method "#{environment}?" do
module Model
module Publishable
PUBLISHING_STATUSES = %w(published approved deleted).freeze
extend ActiveSupport::Concern
included do
PUBLISHING_STATUSES.each do |status|
define_method "is_#{status}?" do
self.publishing_status == status
end
@zhangyuan
zhangyuan / gist:5003372
Created February 21, 2013 09:05
QQ API Demo for Rails ( http://open.qq.com )
# Please add faraday, em-http-request, oj(optional) to Gemfile
CONFIG = {
qq: {
'appid' => 'your appid',
'appkey' => 'your appkey',
'host' => '119.147.19.43' # debug host. change it to openapi.tencentyun.com before release the app
}
}.freeze