Skip to content

Instantly share code, notes, and snippets.

View hare1039's full-sized avatar
:shipit:
わかります

Ryan Yang (hare1039) hare1039

:shipit:
わかります
View GitHub Profile
@hare1039
hare1039 / peer-to-peer-NAT.go
Last active December 4, 2019 03:47
Exchange the ip addr, and try it. (Explaination in comments)
package main
import (
"fmt"
"net"
"time"
)
func main() {
dialer := &net.Dialer{
@hare1039
hare1039 / signal.go
Created November 23, 2019 04:15
signal server for github.com/hare1039/icy
package main
import (
"bufio"
"fmt"
"net"
"sync"
)
func main() {
@hare1039
hare1039 / benchmark.cpp
Last active November 18, 2019 20:22
CSE508 cpu, fork, and thread benchmark. compile: `c++ -o run -std=c++17 -static -pthread benchmark.cpp -Wl,--whole-archive -lpthread -Wl,--no-whole-archive && ./run`
#include <iostream>
#include <functional>
#include <chrono>
#include <vector>
#include <thread>
// unix header
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/wait.h>
@hare1039
hare1039 / time_measure.cpp
Created November 17, 2019 19:17
Time_measure class
class measure
{
using time_point = std::chrono::high_resolution_clock::time_point;
static inline time_point now() { return std::chrono::high_resolution_clock::now(); }
time_point start_ = now();
public:
~measure() { std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(now() - start_).count()
<< " nanoseconds\n"; }
};
#ifndef NET_UTIL_HPP_
#define NET_UTIL_HPP_
#include <functional>
#include <memory>
#include <iterator>
#include <algorithm>
#include <chrono>
#include <string>
#include <cstring>
@hare1039
hare1039 / iwara-friend.ps1
Last active January 27, 2020 18:29
This powershell script helps creaters on iwara accept or delete friend requests. Instructions: https://jet.hare1039.nctu.me/2020-01-25-Windows-Iwara-Script/
# Created by hare1039
$ErrorActionPreference = "Inquire"
$key = Read-Host -Prompt 'Enter Cookie Key'
$value = Read-Host -Prompt 'Enter Cookie Value'
Write-Host '[1] Accept all friend requests'
Write-Host '[2] Delete all friend requests'
$mode = Read-Host -Prompt 'Please enter 1 or 2'
if ($mode -eq "1") {
@hare1039
hare1039 / compose.cpp
Created April 30, 2019 06:50
composer for animation and duration
#include <iostream>
#include <chrono>
#include <type_traits>
#include <variant>
// concept: Animations = time duration + Callable
template<typename ... Animations>
class compose
{
static inline auto now() { return std::chrono::high_resolution_clock::now(); }
@hare1039
hare1039 / 2A2B.cpp
Created April 13, 2019 15:34
Simple impl of game 2A2B
#include <iostream>
#include <random>
#include <sstream>
#include <set>
bool is_all_different(int i)
{
std::stringstream ss;
ss << i;
std::string s = ss.str();
@hare1039
hare1039 / ooxx.cpp
Created April 12, 2019 16:13
Simple impl of ooxx
#include <iostream>
#include <vector>
class ooxx
{
/* -------------
| 1 | 2 | 3 |
-------------
| 4 | 5 | 6 |
-------------
@hare1039
hare1039 / cont.cpp
Created March 26, 2019 03:33
simple operator << for one std container
#include <iostream>
#include <iterator>
#include <vector>
#include <array>
template<typename T, typename _ = void>
struct is_container : std::false_type {};
template<typename... Ts>
struct is_container_helper {};