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 / slice_benchmark.go
Created November 10, 2021 03:05
Go slice performance benchmark
package main
import "testing"
func BenchmarkInitLen(b *testing.B) {
n := b.N
for i := 0; i < n; i++ {
a := make([]int64, n)
for j := 0; j < n; j++ {
a[j] = int64(j)
@bastengao
bastengao / Passengerfile.json
Last active November 1, 2019 00:45
passenger standalone systemd service
{
"environment": "production",
"port": 3000,
"daemonize": true,
"pid_file": "tmp/pids/passenger.pid",
"log_file": "log/passenger.log"
}
@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};") }
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')
# 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|
<!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) {
<!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;
@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;

@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 / 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