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 / pair.cpp
Created August 17, 2023 17:49
some rename test (not tested in productions)
#include <iostream>
struct point2d : public std::pair<int, int>
{
int& x() { return first; }
int& y() { return second; }
template <typename ... Args>
point2d(Args&& ... args) : pair<int, int>(std::forward<Args>(args)...) {}
};
@hare1039
hare1039 / py-cheatsheet.py
Last active January 3, 2023 12:26
plt cheatsheet
import matplotlib.pyplot as plt
import statistics
import collections
d = collections.defaultdict(lambda: 0)
x = statistics.mean(data1)
sys.argv;
"{0: <5}".format("abc")
"{:.2f}".format(0.001)
@hare1039
hare1039 / shell.sh
Last active July 22, 2023 21:07
gather of useful commands
# screen start and detach
screen -S sleepy -dm cmd
screen -XS sleepy quit
# mutex
waiter()
{
local max=$1;
while (( $(jobs -l | wc -l) >= $max )); do
sleep 1;
done
@hare1039
hare1039 / scope_exit.hpp
Created February 17, 2022 21:47
scope exit
#pragma once
#ifndef SCOPE_EXIT_HPP__
#define SCOPE_EXIT_HPP__
#include <functional>
#define BASIC_SCOPE_EXIT_CONCAT_IMPL(x, y) x##y
#define BASIC_SCOPE_EXIT_CONCAT(x, y) BASIC_SCOPE_EXIT_CONCAT_IMPL(x, y)
#define SCOPE_DEFER ::basic_scope_exit::scope_exit BASIC_SCOPE_EXIT_CONCAT(SCOPE_EXIT_UNIQUE_VAR_, __LINE__) = \
CURL_REQUEST_CMD=...;
XCODE_DL_LOCATION="/Volumes/Card512";
XCODE_TMP_EXTRACT_LOCATION="/Volumes/Card512/xcode";
XCODE_FINAL_EXTRACT_LOCATION="/Volumes/Card512"
# download xcode
cd "${XCODE_DL_LOCATION}" || \
{ echo "cd ${XCODE_DL_LOCATION} failed"; exit 1; }
while ! ${CURL_REQUEST_CMD} -o xcode.xip --continue -; do
@hare1039
hare1039 / sumof.cpp
Created March 12, 2021 18:31
simple solution of sumof
#include <iostream>
#include <vector>
bool sum_of(std::vector<int> const & list, int const target, int const maxdep)
{
if (maxdep < 0 or target < 0)
return false;
if (target == 0)
return true;
INTERNET_INTERFACE=wlp13s0
LOCAL_INTERFACE=enp15s0
LOCAL_INTERFACE_IP_BASE=192.168.155
LOCAL_INTERFACE_IP="${LOCAL_INTERFACE_IP_BASE}.1"
LOCAL_INTERFACE_MAC=$(cat /sys/class/net/${LOCAL_INTERFACE}/address)
ip link set up dev ${LOCAL_INTERFACE}
ip addr add "${LOCAL_INTERFACE_IP}"/24 dev ${LOCAL_INTERFACE}
@hare1039
hare1039 / steganography.cpp
Last active December 31, 2020 18:20
A simple steganography program stores data in png (red only)
#include <png++/png.hpp>
#include <iostream>
#include <memory>
#include <type_traits>
int constexpr bitmask = 0b00000011;
constexpr inline auto hash(char const * str, int h = 0) -> long long int {
return (!str[h] ? 5381 : (hash(str, h+1)*33) ^ str[h] );
#include <ArduinoSTL.h>
#include <vector>
#include <functional>
using arduino_time_t = unsigned long;
using function_ptr = void (*)();
class dispatcher
{
@hare1039
hare1039 / tetris.cpp
Last active April 4, 2020 20:37
tetris
#include <iostream>
#include <vector>
#include <sstream>
#include <limits>
#include <unordered_set>
class tetris
{
protected:
enum class ele { empty, occupied };