Skip to content

Instantly share code, notes, and snippets.

View andrisasuke's full-sized avatar

Andri Sasuke andrisasuke

View GitHub Profile
@andrisasuke
andrisasuke / app.py
Last active March 27, 2019 10:21
flask logging gunicorn and file
from logging.handlers import RotatingFileHandler
from flask import Flask
import logging
from logging import Formatter
app = Flask(__name__)
logger = logging.getLogger('your-logger-name')
file_handler = RotatingFileHandler('test.log', maxBytes=10000, backupCount=1)
@andrisasuke
andrisasuke / install_m2crypto.txt
Created May 2, 2017 10:12
python install m2crypto on Mac OS X
$> brew install openssl
$> brew install swig
$> env LDFLAGS="-L$(brew --prefix openssl)/lib" \
CFLAGS="-I$(brew --prefix openssl)/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include" \
pip install m2crypto
@andrisasuke
andrisasuke / m2crypto_sample.py
Created May 2, 2017 10:15
Python encryption-decryption RSA using M2Crypto
import base64
from M2Crypto import RSA, BIO
key = open('/path/public_key.pem', 'r').read()
pubkey = str(key).encode('utf8')
bio = BIO.MemoryBuffer(pubkey)
rsa = RSA.load_pub_key_bio(bio)
encrypted = rsa.public_encrypt('hello', RSA.pkcs1_oaep_padding)
print 'encrypted text ', encrypted.encode('base64')
@andrisasuke
andrisasuke / read_csv_put_es
Last active June 8, 2017 03:03
Python read csv and put to elasticsearch
import csv
import requests
f = open('station.csv', 'rb')
reader = csv.reader(f)
def _generate_header():
return {'Content-type': 'application/json'}
@andrisasuke
andrisasuke / query_param_encode.py
Created June 12, 2017 04:22
Query param url encode in python
import urllib
query_param = urllib.quote('+6281908765')
url = 'http://localhost:8080/test?phone=%s' % query_param
print 'clean url ', url
@andrisasuke
andrisasuke / expression_generator
Created June 15, 2017 05:14
python expression generator example
trs = [1, 2, 3, 4, 5, 6]
xyz = [1, 6, 9, 13]
gen = [tr for tr in trs if tr not in xyz]
for p in gen:
print p
@andrisasuke
andrisasuke / build.gradle
Last active June 20, 2017 07:16
sample-drawable-vector
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
}
@andrisasuke
andrisasuke / src.txt
Created July 13, 2017 05:11
pip install psycopg2 on mac os x
$ export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/VERSION/bin/
$ pip install psycopg2
{
"data": [
{
"id": 8,
"from_country_id": 101,
"from_country": "Indonesia",
"image": {
"original": "https://gibby.id/uploads/countries/101/14955144531007008508.jpg",
"@3x": "https://gibby.id/uploads/countries/101/14955144531007008508_@3x.jpg",
"@2x": "https://gibby.id/uploads/countries/101/14955144531007008508_@2x.jpg",
http://gibby.id/api/requests-offer/{request_id}/trip/{trip_id}?api_key=198bc4240396814a3c8fb73b52b451b0
{
"data" : {
"request_id": 1,
"has_offered": true, // false if blom pernah offer
"price" : 2000,
"gibby_fee" : 500,
"gibby_prosen" : 1700,
"price_to_pay" : 70000,