Skip to content

Instantly share code, notes, and snippets.

@tyong920
tyong920 / SingletonMongoClient.py
Created April 13, 2019 09:20 — forked from wowkin2/SingletonMongoClient.py
Python Singleton with parameters (so the same parameters get you the same object) with support to default arguments and passing arguments as kwargs (but no support for pure kwargs).
"""
Python Singleton with parameters (so the same parameters get you the same object)
with support to default arguments and passing arguments as kwargs (but no support for pure kwargs).
And implementation for MongoClient class from pymongo package.
"""
from pymongo import MongoClient
import inspect
@tyong920
tyong920 / parse_dotenv.bash
Created October 19, 2018 06:35 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@tyong920
tyong920 / collectTagsOccurringWithGivenTag.py
Created May 24, 2018 01:49 — forked from rvprasad/collectTagsOccurringWithGivenTag.py
Python script to extract tags that co-occur with a given tag on question-type posts in Posts.xml file from Stack Overflow data dump.
#
# Copyright (c) 2017, Venkatesh-Prasad Ranganath
#
# BSD 3-clause License
#
# Author: Venkatesh-Prasad Ranganath
#
import argparse
import datetime
import itertools
from collections import OrderedDict
class OrderedSet:
"""
A set which keeps the ordering of the inserted items.
Currently backs onto OrderedDict.
"""
def __init__(self, iterable=None):
@tyong920
tyong920 / notify.py
Created March 12, 2018 06:25 — forked from lukaszb/notify.py
Simple Python script to send notification to the OSX Notifications Center (requires OS X 10.8+). Tested with pyobjc 2.5.1
#!/usr/bin/env python
from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from Foundation import NSUserNotificationDefaultSoundName
from optparse import OptionParser
def main():
parser = OptionParser(usage='%prog -t TITLE -m MESSAGE')
@tyong920
tyong920 / deploy-flask-gunicorn-supervisor-nginx.md
Created February 26, 2018 06:25 — forked from binderclip/deploy-flask-gunicorn-supervisor-nginx.md
Flask Gunicorn Supervisor Nginx 项目部署小总结

Flask Gunicorn Supervisor Nginx 项目部署小总结

服务器的基本连接和配置

SSH 连接

使用公钥私钥来登陆而不是账号密码,公钥私钥需要简单的在本地生成一下。Github 的生成 SSH 公钥私钥的教程:Generating SSH keys

可能需要使用 -i 参数选择一下本地的私钥,一个示例的 ssh 连接如下:

@tyong920
tyong920 / LICENCE SUBLIME TEXT
Created January 10, 2018 03:52
Sublime Text 3 Serial key build is 3143
## Sublime Text 3 Serial key build is 3103
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
@tyong920
tyong920 / tmux.md
Created January 8, 2018 03:50 — forked from Bekbolatov/tmux.md
Clean tmux cheat-sheet

Clean tmux cheat-sheet

By resources

sessions

list-sessions        ls         -- List sessions managed by server
new-session          new        -- Create a new session
ALTER TABLE xxxxxx
ADD created_at TIMESTAMP DEFAULT '0000-00-00 00:00:00',
ADD updated_at TIMESTAMP DEFAULT '0000-00-00 00:00:00';
CREATE TRIGGER xxxxxx_create BEFORE INSERT ON `xxxxxx`
FOR EACH ROW SET NEW.created_at = NOW(), NEW.updated_at = NOW();
CREATE TRIGGER xxxxxx_update BEFORE UPDATE ON `xxxxxx`
FOR EACH ROW SET NEW.updated_at = NOW(), NEW.created_at = OLD.created_at;
@tyong920
tyong920 / gist:a6419e2eb1b9f41e35881ebf75308a67
Created December 11, 2017 08:04 — forked from jaychoo/gist:1246146
Use MongoDB connection in singleton style
from pymongo import Connection
class MongoCon(object):
__db = None
@classmethod
def get_connection(cls):
if cls.__db is None:
cls.__db = Connection()
return cls.__db