Skip to content

Instantly share code, notes, and snippets.

View owen800q's full-sized avatar

owen800q

  • Singapore
View GitHub Profile
@owen800q
owen800q / nginx-tuning.md
Created March 6, 2019 07:27 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@owen800q
owen800q / nginxproxy.md
Created March 6, 2019 07:27 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@owen800q
owen800q / crud.py
Last active August 1, 2019 05:28
SQLAlchemy repository pattern example
## Model classes
class Book(Base):
__tablename__ = 'books'
id = Column(Integer,primary_key = True)
book_id = Column(Integer,unique = True)
title = Column(String, nullable = False)
author = Column(String,index = True)
created_date = Column(DateTime,server_default = func.now())
@owen800q
owen800q / help.py
Last active August 27, 2019 09:29
SQLAlchemy helper functions
# Convert nested model object to dict
def my_dict(obj):
if not hasattr(obj,"__dict__"):
return obj
result = {}
for key, val in obj.__dict__.items():
if key.startswith("_") and key == 'metadata':
continue
element = []
@owen800q
owen800q / Call go functions in Python.md
Last active September 16, 2019 05:12
Call go functions in Python

Method 1:

Using socket, build go as a server. From python, pass parameter over socket connection and get results from go server.

Method 2:

Compile Go to shared object library, call from python with ctypes

sample code

@owen800q
owen800q / Flask_deployment.md
Last active September 19, 2019 09:20
Flask deployment
 uwsgi --socket 0.0.0.0:5000 --plugin python --protocol=http --wsgi-file wsgi.py 
open("/usr/lib/uwsgi/plugins/python_plugin.so"): No such file or directory [core/utils.c line 3691]
!!! UNABLE to load uWSGI plugin: /usr/lib/uwsgi/plugins/python_plugin.so: cannot open shared object file: No such file or directory !!!
uwsgi: unrecognized option '--wsgi-file'
getopt_long() error

Solution:

@owen800q
owen800q / git cheatsheet.md
Created October 24, 2019 03:47
Git_cheatsheet.md

Show Nth commit logs from the beginning

Example, Show first 4 commit histroies from first inital commit

it log  --pretty=oneline | tail -n 4

Output

@owen800q
owen800q / System Design.md
Created October 24, 2019 03:44 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@owen800q
owen800q / nginxproxy.md
Created March 6, 2019 07:27 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers