This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location / { | |
if ($request_method = POST) { | |
proxy_pass http://maclabs_backend; | |
break; | |
} | |
if (-f $document_root/$uri/index.html) { | |
rewrite (.*) /$1/index.html break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="http://v0.api.upyun.com/rbtest/" method="post" enctype="multipart/form-data"> | |
<%= upyun_form_input_tag(:return_url => new_post_path) %> | |
<input type="file" name="file" /> | |
<button type="submit">上传图片</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Render SSI | |
def render_ssi(path) | |
if Rails.env.development? | |
elid = "ssi_#{Digest::MD5.hexdigest(path)}" | |
raw %( | |
<div id="#{elid}"></div> | |
<script type="text/javascript"> | |
$.get("#{path}", function(re){ | |
$("##{elid}").html(re); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rails3Input < Fluent::TailInput | |
Fluent::Plugin.register_input('rails3', self) | |
IP_ADDRESS_REGEX = %r!\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}! | |
def configure_parser(conf) | |
@_time = Time.now.to_i | |
@_record = {} | |
end | |
def parse_line(line) | |
if line.start_with?("Started") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EasyCaptcha.setup do |config| | |
# Cache | |
config.cache = true | |
# Cache temp dir from Rails.root | |
config.cache_temp_dir = Rails.root + 'tmp' + 'captchas' | |
# Cache size | |
config.cache_size = 10 | |
# Cache expire | |
config.cache_expire = 10.seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "em-synchrony" | |
require "em-synchrony/em-http" | |
EM.synchrony do | |
concurrency = 10 | |
urls = %w(taobao.com 163.com ifanr.com ruby-china.org v2ex.com github.com google.com baidu.com).collect { |w| "http://#{w}" } | |
# iterator will execute async blocks until completion, .each, .inject also work! | |
EM::Synchrony::Iterator.new(urls, concurrency).map do |url, iter| | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Keyboard shortcuts for browsing pages of lists | |
(function($) { | |
$(document).keydown(handleKey); | |
function handleKey(e) { | |
var left_arrow = 37; | |
var right_arrow = 39; | |
if (e.target.nodeName == 'BODY' || e.target.nodeName == 'HTML') { | |
if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) { | |
var code = e.which; | |
if (code == left_arrow) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# This is a Rails init template with MongoDB projects | |
# | |
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin | |
# | |
# Usage | |
# | |
# $ rails new app_name -m https://raw.github.com/gist/2168014 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'carrierwave/processing/mini_magick' | |
class BaseUploader < CarrierWave::Uploader::Base | |
include CarrierWave::MiniMagick | |
# Override the directory where uploaded files will be stored. | |
# This is a sensible default for uploaders that are meant to be mounted: | |
def store_dir | |
"#{model.class.to_s.underscore}" | |
end |