Skip to content

Instantly share code, notes, and snippets.

@HungYuHei
HungYuHei / by_tags.rb
Created July 19, 2017 05:34
Rails PostgreSQL jsonb query array
scope :by_tags, -> (tags) { where("meta->'tags' ?& ARRAY[:tags]::text[]", tags: tags) }
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by [email protected] http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>网站维护中...</title>
<style type="text/css">
ppstream://oepvrjsbd53zdaqziepx2lrzdzar63v4aizechz5tmdvyqi7.pps/5VVKX25LSJJ4F6AJ6NVDJSGKG2WITZKY?netmode=3
require "rubygems"
require "oauth"
TQQ_CONSUMER_KEY = "9b43a5afaca04afd8eb573e673fce3f9"
TQQ_CONSUMER_SECRET = "dd6b3cef9a6896e373085a83cd8b74f9"
# 1. 获取Request Token
consumer = OAuth::Consumer.new(TQQ_CONSUMER_KEY, TQQ_CONSUMER_SECRET, {
:site => "https://open.t.qq.com",
:request_token_path => "/cgi-bin/request_token",
fast: through middleware inserted at 0
slwr: through middleware inserted via @use@
rotr: through endpoint sent via the router
bare: through ActionController::Metal with self.response_body
cntr: through ActionController::Base with self.response_body
text: through ActionController::Base with render :text
tmpl: through ActionController::Base with simple render :template
layt: through ActionController::Base with render :template with layout
Note: These tests are being run without ActiveRecord, which currently
# coding: utf-8
def convert_path(path)
path.gsub('/uploads/', '')
end
directory_path = "#{Rails.root}/tmp/grid"
FileUtils.mkdir_p directory_path + "/uploads/images"
grid = Mongo::GridFileSystem.new(Mongoid.database)
var areasMap = {
"北京": null,
"天津": null,
"河北": ["石家庄", "唐山", "秦皇岛", "邯郸", "邢台", "保定", "张家口", "承德", "沧州", "廊坊", "衡水"],
"山西": ["太原", "大同", "阳泉", "长治", "晋城", "朔州", "晋中", "运城", "忻州", "临汾", "吕梁"],
"内蒙古": ["呼和浩特", "包头", "乌海", "赤峰", "通辽", "鄂尔多斯", "呼伦贝尔", "巴彦淖尔", "乌兰察布", "兴安盟", "锡林郭勒盟", "阿拉善盟"],
"辽宁": ["沈阳", "大连", "鞍山", "抚顺", "本溪", "丹东", "锦州", "营口", "阜新", "辽阳", "盘锦", "铁岭", "朝阳", "葫芦岛"],
"吉林": ["长春", "吉林", "四平", "辽源", "通化", "白山", "松原", "白城", "延边朝鲜族自治州"],
"黑龙江": ["哈尔滨", "齐齐哈尔", "鸡西", "鹤岗", "双鸭山", "大庆", "伊春", "佳木斯", "七台河", "牡丹江", "黑河", "绥化"],
"上海": null,
@HungYuHei
HungYuHei / batch-delete-documents.js
Created December 15, 2012 05:32
batch delete kindle's archived personal documents
items = document.getElementsByClassName('rowBodyCollapsed');
for(var i = 0; i < items.length; i++) {
Fion.deleteItem('deleteItem_' + items[i].getAttribute('asin'));
}
@HungYuHei
HungYuHei / gist:3935656
Created October 22, 2012 23:58
compile asset
# config/environments/production.rb
def compile_asset?(path)
if File.basename(path) =~ /^[^_].*\.\w+$/
puts "Compiling: #{path}"
true
else
puts "Ignoring: #{path}"
false
end
end