Skip to content

Instantly share code, notes, and snippets.

View Natata's full-sized avatar
🙌

Jonathan Natata

🙌
View GitHub Profile
@Natata
Natata / main.py
Created May 2, 2020 02:37
the base
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@Natata
Natata / .vimrc
Created April 20, 2020 06:55
jonathan vimrc
set nocompatible " be iMproved, required
filetype off " required
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive', { 'for': 'go'}
Plug 'fatih/vim-go', { 'for': 'go'}
Plug 'majutsushi/tagbar'
Plug 'scrooloose/nerdtree'
Plug 'fatih/molokai'
@Natata
Natata / travel_struct.go
Created September 15, 2019 06:01
travel all fields and tags of struct
func TravelStruct(v interface{}, f func(fieldName string, tag reflect.StructTag)) {
travelStruct(reflect.ValueOf(v).Type(), f)
}
func travelStruct(t reflect.Type, f func(fieldName string, tag reflect.StructTag)) {
t = PtrToType(t)
if t.Kind() != reflect.Struct {
return
}
@Natata
Natata / showroom.py
Last active March 10, 2019 18:02
python script for recording showroom live streaming. run `python3 showroom.sh -h` for help message
# -*- coding: utf-8 -*-
# __author__ = "Natata"
# __copyright__ = "Copyright 2019, Natata"
# __credits__ = ["Natata"]
# __license__ = "MIT"
# __version__ = "0.0.1"
# __maintainer__ = "Natata"
# __email__ = "ph2.71828@gmail.com"
# __status__ = "dev"
@Natata
Natata / gen_cert_key.sh
Created June 1, 2018 18:50
use openssl to generate certificate and key and separate private key
#!/bin/sh
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
openssl rsa -in key.pem -out pri.key
@Natata
Natata / backup.sh
Last active May 21, 2018 16:33
backup running mysql in docker
#!/bin/sh
# how to use:
# ./backup.sh mysql_prod root rootpw mydb /var/log/backup.sql
# crontab example:
# 0 0 * * * /backup.sh mysql_prod root rootpw mydb /var/log/backup.sql
# restore example:
# cat backup.sql | docker exec -i [container_name] /usr/bin/mysql -u [mysql_user] --password=[mysql_password] [database_name]
#!/bin/sh
# usage:
# ./go_installer_mac.sh [go version]
#
# example install go 1.10.2:
# ./go_installer_mac.sh 1.10.2
set -uex
@Natata
Natata / http_server.go
Created May 16, 2018 15:46
simple http server, just print request path and echo post payload
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
@Natata
Natata / createOrOpenFile.go
Last active April 24, 2018 01:49
function for create or open a file
func createOrOpenFile(dir, fn string) (*os.File, error) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.Mkdir(dir, 0700)
if err != nil {
log.Infof("mkdir %v fail", dir)
return nil, err
}
}
fallPath := filepath.Join(dir, fn)
@Natata
Natata / Dockerfile
Created April 7, 2018 07:06
Dockerfile example for run cron job on ubuntu
FROM ubuntu:16.04
MAINTAINER natataworld@love.com
ARG USER=docker_user
RUN apt-get update && apt-get -y install cron sudo
# create a normal user
RUN adduser --disabled-password --gecos '' $USER
RUN adduser $USER sudo