Skip to content

Instantly share code, notes, and snippets.

@watsy0007
watsy0007 / mongo_cache.py
Created October 9, 2018 08:23
mongodb 封装
class MongoCache:
db = None
def __init__(self):
if not hasattr(MongoCache, 'pool'):
MongoCache.create_instance()
@staticmethod
def create_instance():
@watsy0007
watsy0007 / monitor_proc.sh
Created March 4, 2018 17:03
monitor shell
#! /bin/sh
host_dir=`echo ~` # 当前用户根目录
proc_name="net_speeder" # 进程名
file_name="/root/log/netspeed.log" # 日志文件
pid=0
proc_num() # 计算进程数
{
num=`ps -ef | grep $proc_name | grep -v grep | wc -l`
@watsy0007
watsy0007 / pre-commit
Created November 19, 2017 17:12
pre commit rails test
#!/bin/bash
STASH_NAME="pre-commit-$(date +%s)"
git stash save -q --keep-index $STASH_NAME
cd backend
ERROR_MSG=`rails test | grep "errors,"`
cd -
TASHES=$(git stash list)
@watsy0007
watsy0007 / .jsbeautifyrc
Created May 16, 2017 16:09
npm install -g js-beautify
{
"indent_size": 2,
"indent_char": " ",
"eol": "\n",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": false,
"space_after_anon_function": false,
@watsy0007
watsy0007 / ssh_list.py
Created May 2, 2017 16:09
ssh config hosts
import os.path, re
filename = os.path.expanduser("~/.ssh/config")
hosts = []
file = open(filename, 'rb')
contents = file.read()
for line in contents.split('\n\n'):
m = re.search('[Hh]ost\s+(?P<host_name>\w+)', line)
if m is not None:
{
"libs": [
],
"plugins" : {
"node" : {
}
},
"ecmaVersion": 6
}
@watsy0007
watsy0007 / ziroom.rb
Created January 9, 2017 10:40
自如预定房源
# -*- coding: utf-8 -*-
require 'uri'
require 'net/http'
require 'json'
require 'byebug'
require 'pp'
def request(url)
req ||= Net::HTTP::Post.new url
@watsy0007
watsy0007 / station.sh
Created November 4, 2016 09:09
install station
#!/usr/bin/env sh
apt-get update && apt-get upgrade -y
apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
apt-get install -y libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
@watsy0007
watsy0007 / prod_cons_actors.rb
Created October 18, 2016 03:10
Producer Consumer with Actors
require 'celluloid/current'
class Cook
include Celluloid
def produce(manager)
manager.async.inform("produced")
end
end
@watsy0007
watsy0007 / shell
Last active August 2, 2016 07:33
backup_mysql
#!/bin/bash
echo $DB_HOST
echo $DB_USER
echo $DB_PASSWORD
databases=`mysql -h $DB_HOST -u $DB_USER -p$DB_PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"