Skip to content

Instantly share code, notes, and snippets.

View leetschau's full-sized avatar

Leo leetschau

View GitHub Profile
@leetschau
leetschau / boms.yaml
Created September 23, 2017 15:40
BOMS API
openapi: '3.0.0'
info:
title: BOMS API
description: BOMS API Specification
version: "0.1.1"
servers:
- url: localhost:8080
description: test server
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@leetschau
leetschau / uploadjars.py
Created March 14, 2017 09:15
uploading private jar files to local nexus server
#!/usr/bin/env python3
import os, sys, re, subprocess
group_id = 'com.fr'
repo_id = 'znbt'
repo_url = 'http://192.168.12.233:8081/repository/znbt/'
sample_settings = '''<settings>
<servers>
<server>
<id>znbt</id>
@leetschau
leetschau / docker-show-repo-tags.sh
Created September 26, 2016 08:45
list all tags of an image in docker hub
#!/bin/sh
# From: http://stackoverflow.com/a/34054903/701420
# Simple script that will display docker repository tags.
#
# Usage:
# $ docker-show-repo-tags.sh ubuntu centos
for Repo in $* ; do
curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$Repo/tags/" | \
sed -e 's/,/,\n/g' -e 's/\[/\[\n/g' | \
grep '"name"' | \
@leetschau
leetschau / dsnote2evernote.py
Created September 17, 2016 10:06
将dsnote里面的笔记通过`geeknote create`命令同步到Evernote上
import os
import subprocess
basedir = '/home/leo/.donno/repo'
notebook = 'dsnote'
err_coll = []
for fn in os.listdir(basedir):
print('upload %s' % fn)
fullname = os.path.join(basedir, fn)
import argparse
parser = argparse.ArgumentParser(
description='Sync docs in MongoDB to Elasticsearch server')
parser.add_argument('inputfile_name',
help='the json file contains data to synced from MongoDB')
parser.add_argument('-s', '--server-name',
help='the IP address of Elasticsearch server')
parser.add_argument('-i', '--index', help='the index name of ES')
parser.add_argument('-t', '--type-name', help='the type name of the index')
@leetschau
leetschau / multi-dimension-correlation-matrix.py
Last active July 7, 2016 03:26
在Anaconda环境下运行,详细分析见"Data Science from Scratch"第10章读书笔记
import math
import random
import numpy as np
import matplotlib.pyplot as plt
def normal_cdf(x, mu=0, sigma=1):
return (1 + math.erf((x - mu) / math.sqrt(2) / sigma)) / 2
@leetschau
leetschau / cpColl.sh
Created May 28, 2016 14:06
Copy collection between MongoDB servers
#!/usr/bin/python
import sys, re
from os import system
usage = """
Usage:
Full style: ./cpColl sUser:sPwd@sHost:sPort/sDb-sColl dUser:dPwd@dHost:dPort/dDb-dColl
Abbr for source on localhost: ./cpColl sDb-sColl dUser:dPwd@dHost:dPort/dDb-dColl
Abbr for destination on localhost: ./cpColl sUser:sPwd@sHost:sPort/sDb-sColl dDb-dColl
@leetschau
leetschau / sorted.py
Created May 28, 2016 13:54
Python sorted 函数,当某项不包含排序依据时,可以将fallback值作为自己的排序依据
aa = [{'a': 3}, {'a': 2}, {'a': 5}, {'b':8}]
sorted(aa, key=lambda rec: rec['a'] if 'a' in rec else 1, reverse=True)
#: [{'a': 5}, {'a': 3}, {'a': 2}, {'b': 8}]
sorted(aa, key=lambda rec: rec['a'] if 'a' in rec else 6, reverse=True)
#: [{'b': 8}, {'a': 5}, {'a': 3}, {'a': 2}]
@leetschau
leetschau / convertDate.sh
Last active May 28, 2016 12:14
MongoDB导出的json数据中,时间字段前面都有{$date: 2016.04.04},$date不能被Elasticsearch识别,需要去掉,从{"timeStart: {$date: "xxx"}}变成{"timeStart: "xxx"}
#!/bin/bash
sed 's/{\"\$date\":\(\".\{10\}T.\{12\}Z\"\)}/\1/g' f1000.json > temp.json
sed -i 25d temp.json
mongoimport -d test -c strDate --type json --file temp.json
# sample data:
"timeStart":{"$date":"1015-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2018-03-02T00:00:00.000Z"},
"timeStart":{"$date":"2016-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2021-04-0kT00:00:00.000Z"},
"timeStart":{"$date":"2017-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2021-05-09T00:00:00.000Z"},