Skip to content

Instantly share code, notes, and snippets.

View bastengao's full-sized avatar
🏠
Working from home

Basten Gao bastengao

🏠
Working from home
View GitHub Profile
@bastengao
bastengao / jqplot_hex_colors
Created August 28, 2014 02:02
convert rgba color to hex color
require 'color'
jqplot_colors = [
"240, 192, 19, 1",
"217, 135, 20, 1",
" 16, 178, 199, 1",
" 15, 153, 168, 1",
"235, 155, 220, 1",
"247, 57, 197, 1",
"220, 237, 203, 1",
@bastengao
bastengao / verify_url_echostr.rb
Last active August 29, 2015 14:14
微信公众平台企业号验证URL (处理 echostr)
require 'openssl'
require 'base64'
# 参考 http://qydev.weixin.qq.com/wiki/index.php?title=加解密方案的详细说明
AES_KEY = 'aaaa'
encrypted_enchostr = 'bbbb'
def parse_msg(text)
random = text[0..16]
@bastengao
bastengao / buildagent.sh
Created April 23, 2015 02:47
Teamcity buildagent init start script
#!/bin/bash
# Teamcity buildagent daemon start/stop script.
### BEGIN INIT INFO
# Provides: Teamcity buildagent
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
@bastengao
bastengao / mini_magic_append_images.rb
Created June 25, 2016 09:43
Imagemagic append images vertically or horizontally.
# http://www.imagemagick.org/script/command-line-options.php#append
# append two images vertically
# conver -append first.png second.png result.png
MiniMagick::Tool::Convert.new do |convert|
convert.append.-
convert << "first.png"
convert << "second.png"
convert << "result.png"
end
@bastengao
bastengao / init_postgresql_user.md
Last active July 1, 2016 09:18
Init postgresql user
sudo su - postgres
psql

CREATE USER wwwuser WITH PASSWORD 'password';
CREATE DATABASE wwwuser OWNER wwwuser;

GRANT ALL PRIVILEGES ON DATABASE wwwuser to wwwuser;

<!DOCTYPE html>
<html>
<head>
<title>系统升级中</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script type="text/javascript" src="//cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$.get('http://huimin-media0.smart-museum.cn/pano/bingmayong/one.html', function(html) {
# gem 'i18n_generators'
# rails g i18n_translation zh-CN
require 'yaml'
local = YAML.load_file(Rails.root.join('config/locales/translation_zh-CN.yml'))
models = local.dig('zh-CN', 'activerecord', 'models')
attributes = local.dig('zh-CN', 'activerecord', 'attributes')
models.each do |key, value|
class CustomError < StandardError
# custom options to GraphQLError
def options
end
end
class MuationError < CustomError
def initialize(key)
@key = key
message = I18n.t(key, scope: 'mutations.errors')
@bastengao
bastengao / vacuum_all_tables.rb
Last active May 17, 2019 05:18
Execute vacuum analyze for all tables
ActiveRecord::Base.connection.tables.each { |name| puts "VACUUM ANALYZE #{name}"; ActiveRecord::Base.connection.execute("VACUUM ANALYZE #{name};") }