Skip to content

Instantly share code, notes, and snippets.

View martinx's full-sized avatar

Martin Xu martinx

View GitHub Profile
require 'rubygems'
require 'coderay'
tokens = CodeRay.scan <<-'CODE', :ruby
puts %[Hello, world!]
puts "Here\'s some #@@weird #{ { :code => "for you" } }"
CODE
print tokens.div(:line_numbers => :table, :css => :class)
class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :login, :password, :password_confirmation, :remember_me
attr_accessor :login
@martinx
martinx / Cache Logs
Created March 14, 2013 20:53
nginx purge cache logs
GET /data/attachment/audioimg/8/143410hpzqo0oo5o2oimxm.jpg HTTP/1.1 - 15/Mar/2013:04:48:03 +0800 200 0.000 21863 21863 58.33.250.146 - - - - - iListen/1.5.01290 CFNetwork/609.1.4 Darwin/13.0.0sendfileon
GET /data/attachment/audioimg/0/141236mm3tlwv1wxrwhswr.jpg HTTP/1.1 - 15/Mar/2013:04:48:03 +0800 200 0.000 16130 16130 58.33.250.146 - - - - - iListen/1.5.01290 CFNetwork/609.1.4 Darwin/13.0.0sendfileon
GET /data/attachment/audioimg/0/142535uk7ee7uuuv6f7mh7.jpg HTTP/1.1 - 15/Mar/2013:04:48:03 +0800 200 0.000 26645 26645 58.33.250.146 - - - - - iListen/1.5.01290 CFNetwork/609.1.4 Darwin/13.0.0sendfileon
GET /data/attachment/audioimg/7/1705281f9seimc95gz544d.jpg HTTP/1.1 - 15/Mar/2013:04:48:04 +0800 200 1.440 24675 24675 112.78.65.211 - - - - - Dalvik/1.6.0 (Linux; U; Android 4.1.1; MI 2 MIUI/JLB12.0)sendfileon
GET /data/attachment/audio/0/143734o88bfyydy9aka5d8.audio HTTP/1.1 - 15/Mar/2013:04:48:04 +0800 206 44.649 1240599 1240599 87.0.131.142 - - - - - \xE6\x95\x85\xE4\xBA\x8B\xE5\x8F\xA3\xE8\xA2\x8B\xE5\x90\x
@martinx
martinx / SearchSuggestion.rb
Created March 15, 2013 23:23
基于redis的SearchSuggestion
class SearchSuggestion
def self.terms_for(prefix)
return if prefix.blank?
puts "prefix:#{prefix}"
prefix_array = prefix.split
puts prefix_array
unless prefix_array.empty?
$redis.zinterstore "$tmp",prefix_array
terms = $redis.zrevrange "$tmp", 0, 4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Vincent Ting'
import cookielib
import urllib2
import urllib
import json
import hashlib
@martinx
martinx / qiniu_console
Created May 16, 2013 07:00
Qiniu upload error
226/2996
2013-05-16 14:54:48 slug_audio_url:a/7/ywpqjh7l.audio
2013-05-16 14:54:48 uploading file:/w/apsqwezpre/www/a/7/ywpqjh7l.audio
2013-05-16 14:54:48 gen token
2013-05-16 14:54:48 uploading
D, [2013-05-16T14:54:48.713159 #10128] DEBUG -- : Initializing tmpfile: /tmp/Qiniu-RS-Ruby-SDK/a/7/ywpqjh7l.audio/progresses
D, [2013-05-16T14:54:48.713433 #10128] DEBUG -- : Initializing tmpfile: /tmp/Qiniu-RS-Ruby-SDK/a/7/ywpqjh7l.audio/ctxes
D, [2013-05-16T14:54:49.470966 #10128] DEBUG -- : Updating tmpfile: /tmp/Qiniu-RS-Ruby-SDK/a/7/ywpqjh7l.audio/progresses
D, [2013-05-16T14:54:49.471189 #10128] DEBUG -- : chunk 1 in block 0 successfully uploaded.
{:ctx=>"xmHnhZRx_-o7wrEr1pMSQgEG6oIJ0zFLXZcUN2xeLa-C3gtSjKksVQcQCFqSarOy1RAKBGmaw1HkKGiIMOJToEQUCJAsKZOIwEJbEGcIbDRax0vJpojL2IrsVsH6HGEJABKJHgAAAAAAAAQAAAAAAGkHAAC-BYlRAABAAAAABAACAAAABAD_____", :offset=>262144, :restsize=>3932160, :status_code=>200, :host=>"http://up-bj-3.qbox.me"}
2013-05-16 15:20:13 gen token
2013-05-16 15:20:13 uploading
W, [2013-05-16T15:21:14.059880 #23366] WARN -- : Request Timeout => Utils.http_request('http://up-bj-3.qbox.me/bput/likpaUITl60cqeYeiZRMLrIrYNuUfVeiZN1csSIKhqxi97SRgTHkSQGLC1KBAFC3YirCIAZQKZoEZhMY9yYEEX5LJiAOa3gEgiqGKBiuwCFAAsRj0zVtgomIjg0uXy76KDTw4wAAAAAAACAAAAAAAGkHAAC-BYlRAABAAAAAIAACAAAABAD_____/2097152')
W, [2013-05-16T15:21:14.259095 #23366] WARN -- : HTTP status code 701 => Utils.http_request('http://up-bj-3.qbox.me/bput/likpaUITl60cqeYeiZRMLrIrYNuUfVeiZN1csSIKhqxi97SRgTHkSQGLC1KBAFC3YirCIAZQKZoEZhMY9yYEEX5LJiAOa3gEgiqGKBiuwCFAAsRj0zVtgomIjg0uXy76KDTw4wAAAAAAACAAAAAAAGkHAAC-BYlRAABAAAAAIAACAAAABAD_____/2097152')
W, [2013-05-16T15:21:14.530586 #23366] WARN -- : HTTP status code 701 => Utils.http_request('http://up-bj-3.qbox.me/bput/likpaUITl60cqeYeiZRMLrIrYNuUfVeiZN1csSIKhqxi97SRgTHkSQGLC1KBAFC3YirCIAZQKZoEZhMY9yYEEX5LJiAOa3gEgiqGKBiuwCFAAsRj0zVtgomIjg0uXy76KDTw4wAAAAAAACAAAAAAAGkHAAC-BYlRAABAAAAAIAACAAAABAD_____/2097152')
W, [2013-05-16T15:
2013-05-22 11:12:42 audio_filename:a/7/ywpqjh7l.audio
2013-05-22 11:12:42 uploading file:/w/apsqwezpre/www/a/7/ywpqjh7l.audio
W, [2013-05-22T11:12:42.775132 #25685] WARN -- : HTTP status code 612 => Utils.http_request('http://rs.qbox.me/stat/YXBzMjphLzcveXdwcWpoN2wuYXVkaW8=')
2013-05-22 11:12:42 false
2013-05-22 11:12:42 gen token
2013-05-22 11:12:42 uploading
W, [2013-05-22T11:13:43.390193 #25685] WARN -- : Request Timeout => Utils.http_request('http://up-bj-3.qbox.me/bput/likpaUITl60cqeYeiZRMLrIrYNuUfVeiZN1csSIKhqxi97SRgTHkSQGLC1KBAFC3YirCIAZQKZoEZhMY9yYEEX5LJiAOa3gEgiqGKBiuwCFAAsRj0zVtgomIjg0uXy76KDTw4wAAAAAAACAAAAAAAGkHAAC-BYlRAABAAAAAIAACAAAABAD_____/2097152')
W, [2013-05-22T11:13:43.547051 #25685] WARN -- : HTTP status code 701 => Utils.http_request('http://up-bj-3.qbox.me/bput/likpaUITl60cqeYeiZRMLrIrYNuUfVeiZN1csSIKhqxi97SRgTHkSQGLC1KBAFC3YirCIAZQKZoEZhMY9yYEEX5LJiAOa3gEgiqGKBiuwCFAAsRj0zVtgomIjg0uXy76KDTw4wAAAAAAACAAAAAAAGkHAAC-BYlRAABAAAAAIAACAAAABAD_____/2097152')
W, [2013-05-22T11:13:43.764412
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Float Label Pattern</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css" media="screen">
.row {
/*position: relative;*/
padding-top: 24px;