Skip to content

Instantly share code, notes, and snippets.

View hidva's full-sized avatar
👻
大吉大利

盏一 hidva

👻
大吉大利
View GitHub Profile
@hidva
hidva / cvt.cc
Last active July 30, 2016 05:21
关于 C++ 中对中文标点的处理
#include <locale>
#include <codecvt>
#include <string>
#include <iostream>
#include <gtest/gtest.h>
template <typename CharT, typename F>
int FilteredCompare(const CharT *lb, const CharT * const le,
const CharT *rb, const CharT * const re,
@hidva
hidva / GetSetIntersectionNumber.cc
Last active August 1, 2016 07:13
C++ 求取交集个数
struct MeteringIterator: public std::iterator<std::output_iterator_tag, void, void, void, void> {
public:
MeteringIterator(size_t *times_ptr) noexcept :
times(times_ptr) {
*times = 0;
}
template <typename T>
MeteringIterator& operator= (T &&elem) noexcept {
++*times;
@hidva
hidva / install_jenkins_plugin.sh
Last active August 18, 2016 04:53 — forked from micw/install_jenkins_plugin.sh
Script to install one or more jenkins plugins including dependencies while jenkins is offline
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
echo "USAGE: $0 plugin1 plugin2 ..."
exit 1
fi
plugin_dir=.
@hidva
hidva / sample_statm.py
Last active August 27, 2016 05:11
周期性对指定进程的 /proc/pid/statm 文件进行采样.
#! /usr/bin/python
#coding:utf-8
import time
import sys
import getopt
import os
def PrintHelpAndExit() :
print "Usage: %s -f path -p pid -t time" % (sys.argv[0])
@hidva
hidva / unique_file.go
Created September 17, 2016 01:43
Golang 创建一个唯一的文件.
import (
"os"
"github.com/satori/go.uuid"
)
func UniqueFile(dir, prefix string, flags int, perm os.FileMode) (f *os.File, err error) {
unique_file_prefix := dir + "/" + prefix
flags |= os.O_EXCL | os.O_CREATE
@hidva
hidva / unique_rename.go
Created September 17, 2016 03:27
Golang 将文件重命名为一个唯一的文件
import (
"os"
"github.com/satori/go.uuid"
"github.com/williamsandrew/go-xchg"
"golang.org/x/sys/unix"
)
func UniqueRename(oldpath, newpath_dir, newpath_prefix string) (newpath string, err error) {
@hidva
hidva / template_Makefile.mk
Created September 28, 2016 04:22
Makefile 模板
GCC := gcc
GXX := g++
project_path := $(shell pwd)
BIN :=
C_SRC :=
CXX_SRC :=
CFLAGS :=
@hidva
hidva / http_get.go
Created October 24, 2016 02:58
golang wget
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
@hidva
hidva / remove-unopen-file.py
Last active May 28, 2019 05:46
python, 移除未被打开的文件
# coding: utf-8
import os
import sys
import logging
logging.basicConfig(format="%(asctime)s|%(process)d|%(thread)d|%(name)s|%(levelname)s|%(message)s", level=logging.INFO)
def opened_info(path):
@hidva
hidva / wrapper_exception.py
Last active May 6, 2017 05:55
WrapperException
# coding=utf-8
import traceback
import sys
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('test')