Skip to content

Instantly share code, notes, and snippets.

View ochinchina's full-sized avatar

Steven Ou ochinchina

  • NOKIA Chengdu, China
View GitHub Profile
import com.google.common.io.CharStreams;
import javax.activation.DataSource;
import javax.mail.BodyPart;
import javax.mail.Header;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
import java.io.*;
import java.util.Enumeration;
@ochinchina
ochinchina / nginx.conf
Created October 31, 2018 04:33 — forked from kmjones1979/nginx.conf
Example NGINX configuration to dynamically set the local IP address during socket creation
# Example of proxy_bind using variables using split_clients and map
events { worker_connections 2014; }
http {
default_type text/plain;
error_log /var/log/nginx/debug_error.log debug;
server {
@ochinchina
ochinchina / sdkman_update_candidates.md
Created November 14, 2016 05:56
update the candidates of sdkman

If the ~/.sdkman/var/candidates is empty, we can refresh it by calling:

$ curl -s https://api.sdkman.io/candidates > ~/.sdkman/var/candidates
@ochinchina
ochinchina / docker_tags.py
Created November 7, 2016 05:35
list tags by the image name in docker
#!/usr/bin/python2
import json
import urllib2
import sys
def get_tags( image):
tmp = image.split("/")
if len( tmp ) == 3:
f = urllib2.urlopen("https://%s/v2/%s/tags/list" % (tmp[0], tmp[1] + "/" + tmp[2] ) )
@ochinchina
ochinchina / set_date_from_http.py
Created October 27, 2016 01:59
get the date time from the web site by http head and set it as the system time
#!/usr/bin/python2
import subprocess
import re
import os
import time
def set_os_date( url ):
header = subprocess.check_output( ["curl", "--head", url ], shell=False )
for line in header.split("\n"):
@ochinchina
ochinchina / wonderful_sites.md
Created October 25, 2016 05:06
site wonderful websites
@ochinchina
ochinchina / openssl_aes.py
Last active October 17, 2016 09:07
AES encrypt/decrypt with openssl
#!/usr/bin/python
import array
import optparse
import os
import sys
import base64
def gen_random_key( fileName ):
os.system("openssl rand -base64 -out %s 16" % fileName )
@ochinchina
ochinchina / boost_epoll_reactor_usage.md
Last active August 5, 2016 09:38
use the boost epoll_reactor directly

###in boost 1.39

struct BoostEpollHandler {
	BoostEpollHandler( const boost::function<bool (boost::system::error_code&, std::size_t&) >& _performHandler,
				const boost::function<void (const boost::system::error_code&, std::size_t ) >& _completeHandler )
	:performHandler( _performHandler ),
	completeHandler( _completeHandler )
	{
	}
@ochinchina
ochinchina / jsonrpc_client.py
Last active July 5, 2016 02:49
json rpc in python
import requests
import json
def main():
url = "http://localhost:4000/jsonrpc"
headers = {'content-type': 'application/json'}
# Example echo method
payload = {
@ochinchina
ochinchina / coreos_installation.md
Last active July 18, 2016 08:53
coreos installation & usage

##install coreos to the baremetal server

Prepare the cloud init configuration file like below:

#cloud-config

# include one or more SSH public keys
ssh_authorized_keys:
 - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDi9rg+WeNW2WkhBniXViHoMOJhEIK/JoIxMt6ig2Kksoot4V5oJwRs7odCVejHWaUYMhq8QsuwTejpt5172rtyQLLyd4QbwCct21+XHZul7lgjJR8EAhRBZDPHxg+c4d9gJYCQnxSxdBLYBpg2K8UQJY7jvHwpi2jjpAZQnQzJ5YYzpcyz+SjbONu8FZaqXxt7/s+O8U0OqIeCMJIeinu69xKwtCaW+ROe/kMPoMSrjcr66sRkcWVyrcPCjMI3nLoE6Ix+DB2UHK+mxnR8u5j0S3oX2AMPGZgQE/emd4Epa8KS3/Vh6I35De+RcT5+3HzJviYhxJLY7kLP3FyVsxQX ochinchina@ubuntu-1504-1