Skip to content

Instantly share code, notes, and snippets.

View lotusirous's full-sized avatar
💭
for { Learn() }

Kha Nguyen lotusirous

💭
for { Learn() }
View GitHub Profile
@lotusirous
lotusirous / git_authen.md
Last active December 17, 2017 05:03
Git authen by SSH key
@lotusirous
lotusirous / elastic_search.md
Created December 25, 2017 00:58
Install elastic search Cent OS 7

Install Elasticsearch in CentOS 7

  1. Download and install rpm file downloaded from oracle home page
# install by command
rpm -ivh jdk-8u151-linux-x64.rpm
# Check java version
java -version

Forward localhost service by a public ip

I have a service that listen on http://127.0.0.1:1017. This service is a binary file which can not change IP/port when turn it on.

socat for public this service by ip

socat TCP-LISTEN:8080,fork,reuseaddr TCP:127.0.0.1:1017
@lotusirous
lotusirous / flask_best_practice_app.py
Last active June 30, 2019 15:46
A beautiful example of flask app structure for production in practice
from flask import Flask
from flask import json, Response
"""
From: https://youtu.be/1ByQhAM5c1I
Refer to another repos:
- https://github.com/pallets/flask/tree/master/examples/flaskr
- https://github.com/wgwz/flask-for-fun-and-profit
"""
document.write('<style type="text/css">\n #Dome_12060_OA{position:absolute; width:120px; height:60px; background:url("//ad.wsodcdn.com/60d1f0505423aae2c8c976726b8fae2f/120x60_Dome_bkgd.png") no-repeat;}\n #Dome_12060_OA a.backgroundClick{position:absolute; width:120px; height:60px; background-color:#000000; opacity:0; filter:alpha(opacity=0);}\n #Dome_12060_OA a.CTA{position:absolute; width:116px; height:24px; top:36px; left:2px; background:url("//ad.wsodcdn.com/60d1f0505423aae2c8c976726b8fae2f/120x60_Dome_CTA_OA.png") no-repeat left top;}\n #Dome_12060_OA a.CTA:hover{background-position:left bottom;}\n</style>\n<div id="Dome_12060_OA">\n <a class="backgroundClick" href="//ad.wsod.com/click/8bec9b10877d5d7fd7c0fb6e6a631357/3966.2906.js.120x60.1513678357.B35735a38e61599701.1729.__304.0.18_11/**;17;1440x900x1;http:_@[email protected]_@2F;;" title="Knowledge. Support. Transparent Pricing. More reasons to say I\'m with Scottrade. Click to learn more!" target="_blank"></a>\n <a class="CTA" href="//ad.ws
import socket
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
hostname = socket.gethostname()
ipaddr = socket.gethostbyname(hostname)
return """
# Time
yum -y install ntp
ntpdate time.apple.com
# remove old kernel
yum install yum-utils
package-cleanup --oldkernels --count=2
# disable ipv6
# append in file `/etc/sysctl.conf`
@lotusirous
lotusirous / ip_validation.py
Last active June 11, 2018 04:58
voluptuous IP address validation
import ipaddress
from voluptuous.schema_builder import message
from voluptuous import All, Invalid, Required, Schema
from voluptuous.error import Invalid
class IPInvalid(Invalid):
"""The value is not valid IP."""
@message('expected an IP address', cls=IPInvalid)