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

Dual monitor for LightDM

In case you have a GPU,

sudo apt install arandr

Save the configuration script file in: $HOME/.screenlayout/OfficeMonitor.sh

@lotusirous
lotusirous / app.py
Created April 26, 2019 04:33
A flask app for long task queue with wrapped sys.stdout.write
from flask import Flask, request
from rq import Queue
from redis import Redis
app = Flask(__name__)
q = Queue(connection=Redis())
@app.route("/", methods=["GET"])
def home():
return "Index"
@lotusirous
lotusirous / user.go
Last active April 25, 2019 00:01
An example of manipulate data in mongodb with golang
package main
import (
"context"
"log"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
package main
import (
"flag"
"fmt"
"net"
"os"
)
var host string

Install production ready cassandra cluster

  1. Download cassandra
  2. Configure export CASSANDRA_HOME=/home/test/local/cassandra
  3. configure $CASSANDRA_HOME/conf/cassandra.yaml as follows:
cluster_name: '[Your Cluster Name]'
listen_address: [public_ip_address]
rpc_address: [public_ip_address]
@lotusirous
lotusirous / proxy_pattern.go
Created March 8, 2019 00:54
Implement proxy pattern in golang
package main
import (
"log"
)
type Wizard struct {
Name string
}
@lotusirous
lotusirous / kafka_kubernetes_pod.md
Last active February 17, 2019 00:49
Connect to kafka from a pods in kubernetes clusters

If you want to integrate kubernetes with legacy system which are not running on kubernetes. You can connect from a kubernetes pods with those services by docker interfaces. The kafka is running on the host network at port 9092.

We have kafka client

import logging

# for checking internal connection of kafka module
logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger('test.kafka')
@lotusirous
lotusirous / main.go
Last active February 10, 2019 08:33
Simple web server returns hostname
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
)
@lotusirous
lotusirous / app.py
Created January 26, 2019 12:38
Example of flask blueprint and register logging to root logger
import logging
from flask import Flask
from werkzeug.utils import find_modules, import_string
def configure_logging():
# register root logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('werkzeug').setLevel(logging.INFO)
@lotusirous
lotusirous / wrap_with_argument.py
Created January 25, 2019 08:20
A sample wrapper with arguments
from functools import wraps
def role_required(a: list):
def with_roles(f):
@wraps(f)
def wrapper(*args, **kwds):
print('Calling decorated function', a)
return f(*args, **kwds)
return wrapper
return with_roles