Skip to content

Instantly share code, notes, and snippets.

def two(path):
tmp = {}
with open(path) as f:
for line in f:
k, v = line.split(',')
k = k.strip()
v = float(v)
s, c = tmp.get(k, (0, 0))
tmp[k] = (s+v, c+1)
for k, (s, c) in tmp.items():
@comynli
comynli / GarbageCollectors.java
Created July 17, 2017 03:50 — forked from khotyn/GarbageCollectors.java
Garbage collectors used in HotSpot JVM under different VM Options
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
* Print the Collector used in the program.
* @author khotyn
# ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com

安装ipython 和 jupyter

  • pip install ipython
  • pip install jupyter

启动jupyter notebook

  • jupyter notebook --ip=0.0.0.0 --no-browser

安装pyenv

  1. 安装git yum -y install git
  • 安装pyenv curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

  • 配置环境变量, 在 ~/.bash_profile里增加如下内容

    export PATH="~/.pyenv/bin:$PATH"
    eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

class Node:
def __init__(self, value):
self.value = value
self.next = None
self.prev = None
class Deque:
def __init__(self):
self.head = None
import subprocess
import threading
class Command(object):
def __init__(self, cmd, out, timeout):
self.cmd = cmd
self.out = out
self.timeout = timeout
self.__event = threading.Event()
self.proc = None
We couldn’t find that file to show.
function flatten(target, opts = {delimiter: '.'}) {
let output = {};
function step(object, prev = '') {
Object.keys(object).forEach(key => {
let value = object[key];
let outKey = prev.length > 0? `${prev}${opts.delimiter}${key}`: key;
if (typeof value === 'object') {
return step(value, outKey)
}
import hmac
import time
import struct
import base64
import hashlib
def totp_gen(secret, time_range=30, i=0):
tm = int(time.time() / time_range)
b = struct.pack(">q", tm + i)
hm = hmac.HMAC(secret, b, hashlib.sha1).digest()