Skip to content

Instantly share code, notes, and snippets.

View Matrixbirds's full-sized avatar

matrixbirds Matrixbirds

View GitHub Profile
@Matrixbirds
Matrixbirds / sshd_config
Created March 22, 2016 09:08
vagrant sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
@Matrixbirds
Matrixbirds / active_admin.rb
Created April 8, 2016 07:52
active admin custom authorization
ActiveAdmin.setup do |config|
# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "污妖王的后台,比你硬而且粗"
config.authorization_adapter = "AdminPermissionAdapter"
config.current_user_method = :current_user
config.authentication_method = :authenticate_admin!
# https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default
# set window split
bind-key v split-window -h
bind-key b split-window
# default window title colors
@Matrixbirds
Matrixbirds / nginx.conf
Last active August 25, 2016 08:18
A simple SPA Nginx demo
## try_files all request except /api, /admin/api
upstream backend_api {
server ip_address;
}
server {
listen 80;
server_name t66y.domain.com;
index index.html;
charset utf-8;
@Matrixbirds
Matrixbirds / config.ru
Created November 15, 2016 06:10
resolve sidekiq web ui 403 on rack & sidekiq post operation redirect drop port
use Rack::Session::Cookie, key: 'sidekiq.session', secret: ENV['secret_base_key']
Sidekiq::Web.class_eval do
use Rack::Protection, origin_whitelist: [ENV['domain']] # resolve Rack Protection HttpOrigin
end
@Matrixbirds
Matrixbirds / ability.rb
Created November 24, 2016 04:28
solve cancancan-1.15.0 marshal issue
class Ability
include CanCan::Ability
def marshal_dump
@rules.reject{|rule| rule.instance_variable_get :@block }.map {|rule| Marshal.dump(rule)}
end
def marshal_load _binary_arr
@rules ||= []
_binary_arr.map do |rule|
@Matrixbirds
Matrixbirds / config.ru
Created January 15, 2017 06:56
nginx fcgi ruby rack app config examples
require 'bundler'
Bundler.require(:default, ENV.fetch("RACK_ENV"))
SOCK_FILEPATH = "./rack.sock"
Rack::Handler::FastCGI.run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["It Works"]] }, File: SOCK_FILEPATH
@Matrixbirds
Matrixbirds / cli
Last active January 17, 2017 02:58
sysadmin codebase
## query condition and display line
## select line number
cat puma.stdout.log | grep '<condition>' -n | awk '{split($0, a, ":I"); print a[1]}'
## select range
export h=head -n1
export t=tail -n1
sed -n '$(h),$(t)p' puma.stdout.log | less -N
@Matrixbirds
Matrixbirds / step.sh
Last active January 18, 2017 04:42
os x setup postgresql
initdb -D /usr/local/var/postgres # create database cluster directory for postgresql
createuser -s postgres # create postgre role
cat file.log | grep 'matcher'
export line_number=12333
sed -n '${line_number},$p' file.log | less