This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"archive/zip" | |
"io" | |
"os" | |
"path/filepath" | |
"strings" | |
) | |
func zipit(source, target string, needBaseDir bool) error { | |
zipfile, err := os.Create(target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i := 0 | |
for { | |
pc, fn, line, ok := runtime.Caller(i) | |
if ok == false { | |
break | |
} | |
fmt.Printf("[stack-%d] %s[%s:%d]\n", i, runtime.FuncForPC(pc).Name(), fn, line) | |
i++ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func columnWidth(s string) int { | |
runes := []rune(s) | |
w := 0 | |
for _, r := range runes { | |
k := width.LookupRune(r).Kind() | |
if k == width.EastAsianWide || k == width.EastAsianFullwidth { | |
w = w + 2 | |
} else { | |
w = w + 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
//----------------------------------------------------------------------------- | |
// utf8_char_len | |
//----------------------------------------------------------------------------- | |
template <typename T> | |
size_t utf8_char_len(const char* str, size_t off, T eos) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
std::basic_string<T> replace_all(const std::basic_string<T>& str, const T* from, const T* to) | |
{ | |
std::basic_string<T> ret; | |
ret.reserve(str.length()); | |
size_t from_len = 0; | |
while (from[from_len]) { | |
from_len++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, typename F> | |
std::basic_string<T> regex_replace_with_lambda( | |
const std::basic_string<T>& str, | |
const std::basic_regex<T>& re, | |
F f) | |
{ | |
typedef std::basic_string<T> StrT; | |
auto ret = StrT(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool read_file(const char* path, vector<char>& buff) | |
{ | |
ifstream ifs(path, ios::in | ios::binary); | |
if (ifs.fail()) { | |
return false; | |
} | |
buff.resize(static_cast<unsigned int>(ifs.seekg(0, ios::end).tellg())); | |
if (!buff.empty()) { | |
ifs.seekg(0, ios::beg).read(&buff[0], static_cast<streamsize>(buff.size())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T, typename Pred, typename Conv> | |
auto filter_and_map(const vector<T>& cont, Pred pred, Conv conv) -> vector<typename std::remove_const<decltype(conv(T()))>::type> { | |
vector<typename std::remove_const<decltype(conv(T()))>::type> r; | |
for (const auto& el: cont) { | |
if (pred(el)) r.push_back(conv(el)); | |
} | |
return r; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lz4_decompress(path) | |
def read_value(data, pos, size) | |
case size | |
when 1; type = 'C' | |
when 2; type = 'S' | |
when 4; type = 'L' | |
end | |
[pos + size, data[pos, size].unpack(type)[0]] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:%0Aif(window.hasOwnProperty('pinyin'))%0Awindow.pinyin();else%0A$('script').attr('src','https://raw.github.com/yhirose/wol-bookmarklets/master/pinyin.js').appendTo('body'); |