Skip to content

Instantly share code, notes, and snippets.

@jonnyyu
jonnyyu / zip_utils.py
Last active August 23, 2022 06:39
zip a folder with zipfile
def zip(zip_file, src_dir):
with zipfile.ZipFile(zip_file, 'w') as zipObj:
for folderName, subfolders, filenames in os.walk(src_dir):
for filename in filenames:
# create complete filepath of file in directory
filePath = os.path.join(folderName, filename)
zipObj.write(filePath, osp.relpath(filePath, src_dir))
@jonnyyu
jonnyyu / FileLock.h
Created October 11, 2022 03:28
file-based named mutex like lock for multi-processes.
#pragma once
#include <filesystem>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
using std::ofstream;
using std::filesystem::path;
using boost::interprocess::file_lock;
using boost::interprocess::scoped_lock;
@jonnyyu
jonnyyu / PerfCounter.h
Created October 11, 2022 03:32
std::chrono based PerfCounter
#pragma once
#include <string>
#include <chrono>
namespace chrono = std::chrono;
using hrclock = chrono::high_resolution_clock;
namespace utils
{
class PerfCounter
@jonnyyu
jonnyyu / EnumByChunk.h
Created October 11, 2022 03:43
C++ iterate by chunk
#pragma once
namespace utils
{
template<class T>
void enumByChunk(const typename T::const_iterator& cbegin, const typename T::const_iterator& cend, const size_t chunkSize,
const function<void(const typename T::const_iterator& sub_begin, const typename T::const_iterator& sub_end)>& func)
{
auto it = cbegin;
while (it < cend)