Skip to content

Instantly share code, notes, and snippets.

Get one line from file

sed '5!d' file
@yuliji
yuliji / hist.py
Last active November 6, 2017 10:16
python plot
import matplotlib.pyplot as plt
fig, ax = plt.subplots(ncols=1, nrows=3, figsize=(10, 15))
ax[0].hist(scores1, bins=100, range=(0, 100)) # bins is number of columns, range is upper and lower bound
ax[1].hist(scores2, bins=100, range=(0, 100)) # bins is number of columns, range is upper and lower bound
ax[2].hist(diff, bins=100, range=(-300, 300)) # bins is number of columns, range is upper and lower bound
fig.tight_layout()
plt.show()
@yuliji
yuliji / prettyjson.sh
Created December 2, 2017 03:55
[pretty json cli] #cli #python
python -m json.tool ajsonfile.json
@yuliji
yuliji / partial_function.py
Last active December 7, 2017 10:48
[python partial function, currying]
# currying
def make_in_list(alist):
def in_list(e):
return e in alist
return in_list
in_list = make_in_list([1,2,3,4,5])
in_list(9)
@yuliji
yuliji / docker-compose.yml
Created January 3, 2018 04:21
[sampel docker-compose.yml] #docker
version: '3'
services:
linguistic-server:
image: "linguistic-server"
ports:
- "8888:8888"
# volumes:
# - .:/code
language-tool:
image: "language-tool"
@yuliji
yuliji / mean_std.py
Created January 10, 2018 06:46
[mean std] Calculate mean std of array
import numpy
a = numpy.array([1,2,3,4,5])
a.mean()
a.std()
a.max()
a.min()
@yuliji
yuliji / exif.py
Created January 15, 2018 08:20
[get exif] Python get exif of image
import PIL.Image
img = PIL.Image.open('img.jpg')
exif_data = img._getexif()
import PIL.ExifTags
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in PIL.ExifTags.TAGS
@yuliji
yuliji / exif_read_wand.py
Created January 15, 2018 09:25
[read exif wand]Read exif from python wand
from wand.image import Image
exif = {}
with Image(filename='wandtests/assets/beach.jpg') as image:
exif.update((k[5:], v) for k, v in image.metadata.items()
if k.startswith('exif:'))
@yuliji
yuliji / postgresql docker.yml
Created January 18, 2018 07:27
[postgresql docker]
version: '3'
services:
eudb:
image: "192.168.10.200:5000/zhparser:9.6"
environment:
POSTGRES_DB: "campus"
POSTGRES_USER: "osqa"
POSTGRES_PASSWORD: "RenCaiXue1234$$"
volumes:
- "./eudb/log:/var/log/postgres"
@yuliji
yuliji / kline.py
Created January 31, 2018 14:44
[candal stick] candal stick kline
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
from matplotlib.finance import candlestick_ohlc
import datetime
from matplotlib.dates import date2num
fig = plt.figure()
ax1 = plt.subplot2grid((1,1), (0,0))