Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / __init__.py
Created May 24, 2012 15:17 — forked from dongyi/__init__.py
OAuth包,实现了sina,QQ,网易,搜狐的OAuth认证
# -*- Encoding: utf-8 -*-
import base64
import binascii
import cgi
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
@jhjguxin
jhjguxin / profile.rb
Created May 26, 2012 08:48
Paperclip skip no img file
has_attached_file :face,
:default_style => :s120,
:styles => {
:normal => "180x180#",
:s120 => "120x120#",
:s48 => "48x48#",
:s32 => "32x32#",
:s16 => "16x16#"
},
:url => Askjane::MetaCache.get_config_data("profile_face_url"),
@jhjguxin
jhjguxin / find_city.rb
Created May 26, 2012 08:52
FindCity by sina city
#require 'iconv'
class IpSearch
#initialize(file='qqwry.dat')
def initialize(file="#{Rails.root}/lib/iplocation/qqwry.dat")
filename = file
@file = File.open(filename,"r")
@index_first,@index_last = @file.read(8).unpack('L2')
@index_total = (@index_last - @index_first)/7 + 1
@location = {}
@jhjguxin
jhjguxin / render_and_redirect.markdown
Created May 30, 2012 03:05 — forked from jcasimir/render_and_redirect.markdown
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@jhjguxin
jhjguxin / user.zh-CN.yml
Created May 30, 2012 06:15
user.zh-CN.yml(base on devise user model)
zh-CN:
activerecord:
models:
user: "用户"
attributes:
user:
name: "姓氏"
email: "电子邮箱"
encrypted_password: "加密密码"
reset_password_token: "重置密码令牌"
@jhjguxin
jhjguxin / oauth_user_skip_confirmation.rb
Created May 30, 2012 11:21
skipping email confirmation for omniauth users using devise
#I have a bit of code here where users can login via their twitter account. the problem here is, how can i skip email confirmation for user the sign up from external services like twitter. i am using devise and i do not know how to skip the email confirmation for this type of users. my code sample is as follows
#authentications_controller.rb
class AuthenticationsController < ApplicationController
# GET /authentications
# GET /authentications.json
def index
@authentications = current_user.authentications if current_user
end
###############################################################################
#操作系统CentOS 5
#1:#yum –y install monit
#2:修改主配置文件
#vi /etc/monit.conf
#################################################################### ##########
#黄色部分是上次修改过的,根据实际情况配置
###############################################################################
## Monit control file
###############################################################################
@jhjguxin
jhjguxin / po.js
Created June 4, 2012 05:18
javascript return the method or value of Object
function po(obj, property, func) {
// eval(obj.functionname);
var str = '';
for (prop in obj) {
if (typeof(obj[prop]) != 'function') {
if (property != false) {
str += prop + ':' + obj[prop] + '\n';
}
} else if (func != false) {
str += prop + ':' + typeof(obj[prop]) + '\n';
@jhjguxin
jhjguxin / kindeditor_config.js
Created June 5, 2012 14:16
Kindeditor for Ruby on Rails
//kindeditor setting base on bbtang.com
KindEditor.options.items=["emoticons", "|", "forecolor", "hilitecolor", "fontsize", "bold", "strikethrough", "justifyleft", "justifycenter", "justifyright", "|", "image", "multiimage", "table", "link", "unlink"]
KindEditor.options.pasteType=1
KindEditor.options.htmlTags = {
font : ['color', 'size', 'face', '.background-color'],
span : [
'.color', '.background-color', '.font-size', '.font-family', '.background',
'.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
@jhjguxin
jhjguxin / paperclip_3_how_to.markdown
Created June 5, 2012 14:42
paperclip (3.0.4) paperclip (3.0.4)

Paperclip

Build Status Dependency Status

Paperclip is intended as an easy file attachment library for Active Record. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their final locations on disk, nor are they deleted if set to nil, until ActiveRecord::Base#save is called. It manages validations based on size and