Skip to content

Instantly share code, notes, and snippets.

View umaumax's full-sized avatar
🏠
Working from home

umaumax umaumax

🏠
Working from home
View GitHub Profile
#!/usr/bin/env python3
import argparse
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
def run(host, port, ctx, handler):
server = HTTPServer((host, port), handler)
server.socket = ctx.wrap_socket(server.socket)
print('Server Starts - %s:%s' % (host, port))
#!/usr/bin/env python3
import redis
import json
import argparse
import sys
def main():
parser = argparse.ArgumentParser(
@umaumax
umaumax / cors-server.py
Created December 28, 2022 00:12
web server with cors headers
#!/usr/bin/env python3
import argparse
from http.server import HTTPServer, SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
@umaumax
umaumax / rx.py
Last active April 2, 2023 11:39
python udp examples
#!/usr/bin/env python3
import argparse
import socketserver
class MyUDPHandler(socketserver.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
@umaumax
umaumax / get_timestamp_offset.cpp
Last active April 28, 2022 03:35
get timestamp offset(realtime - monotonic)
#include <time.h>
#include <iomanip>
#include <ios>
#include <iostream>
void print_timestamp(uint64_t tv_sec, uint64_t tv_nsec) {
std::cout << std::setw(10) << tv_sec << "." << std::setfill('0')
<< std::setw(9) << tv_nsec << std::setfill(' ') << std::endl;
}
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
#pragma once
#include <cassert>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <unordered_map>
namespace ArgPlus {
set term pdf
set output "memory.pdf"
set xlabel "time [sec]"
set ylabel "free memory [byte]"
set yrange [0:*]
plot "memory.log" using 1:2 with lines title "memory"
@umaumax
umaumax / stress.cpp
Created August 12, 2021 13:10
simple stress command
#include <chrono>
#include <fstream>
#include <iostream>
#include <thread>
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " "
<< "cpu_ratio" << std::endl;
return 1;
@umaumax
umaumax / Terminal.ahk
Created July 18, 2021 05:24
Terminal.ahk
global g_tmux_prefix_access_time := 0
GetCurrentTimeAsMilliSeconds() {
millis := (a_hour * 3600 + a_min * 60 + a_sec) * 1000 + a_msec
Return millis
}
IsTmuxAccess() {
now := GetCurrentTimeAsMilliSeconds()
sub := now - g_tmux_prefix_access_time