Skip to content

Instantly share code, notes, and snippets.

View joshuashaffer's full-sized avatar
🎯
练习关系

. joshuashaffer

🎯
练习关系
  • Shijiazhuang Donghua Jinlong Chemical Co., Ltd.
  • Shijiazhuang, Hebei, China
  • X @BertChintez
View GitHub Profile
@joshuashaffer
joshuashaffer / epoll_dummy_server.cpp
Last active March 3, 2024 16:49
Dummy epoll server that accept connections and keeps them open by sending a single character every 15 seconds.
#include <array>
#include <atomic>
#include <csignal>
#include <unordered_set>
#include <arpa/inet.h>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fcntl.h>
@joshuashaffer
joshuashaffer / to_int_constant.cpp
Created October 1, 2023 19:08
constexpr enum constants from string constants at compile time
/***
* @brief Convert a string literal to a compile-time integer constant.
* @tparam IntT The integer type to return.
* @tparam CharT The character type of the string literal.
* @tparam NameLength The length of the string literal.
* @tparam NameIndex The current index of the string literal.
* @tparam TBytes The number of bytes in the integer type.
* @param name The string literal to convert.
* @return The integer constant.
*/
from pathlib import Path
import r2pipe
# Instructions that are not available on 8086/8088:
_unsupported_instructions = [
'enter',
'leave',
'popa',
'pusha',
@joshuashaffer
joshuashaffer / compute-total-lfs.sh
Created June 16, 2023 15:50
Compute Total Amount of LFS
git lfs ls-files -s | rev | cut -d'(' -f1 | cut -c2- | rev | sed -e 's;TB;*1024*1024*1024+;' -e 's;MB;*1024*1024+;' -e 's;KB;*1024+;' -e 's;B;+;'|tr -d '\n' | rev | cut -c2- | rev | bc -l
@joshuashaffer
joshuashaffer / perm_ives.rs
Last active August 31, 2022 17:22
In place permutation iterator in Rust.
enum IteratorState {
First,
HasNext,
Done,
}
pub struct PermutationInPlace<'a, T> {
state: IteratorState,
counter: Vec<usize>,
@joshuashaffer
joshuashaffer / system-font.css
Created January 30, 2022 17:14
Use System Fonts
body {
font-family: -apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
"Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
}
@joshuashaffer
joshuashaffer / list_all_vars
Created August 23, 2021 20:56
List all CMake Variables.
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
@joshuashaffer
joshuashaffer / mmsolve.py
Last active April 24, 2018 20:28
Online master mind solver
import attr
@attr.s(frozen=True, slots=True)
class T(object):
a = attr.ib(default=1, type=int)
b = attr.ib(default=1, type=int)
c = attr.ib(default=1, type=int)
d = attr.ib(default=1, type=int)
perfect = attr.ib(default=1, type=int)
@joshuashaffer
joshuashaffer / bellard.f90
Created October 18, 2017 16:53
Bellard's Formulae
real(kind=16) function term (p)
implicit none
integer p
real(kind=16) t1
real(kind=16) t2
real(kind=16) t3
real(kind=16) t6
real(kind=16) n
n = dble(p)
@joshuashaffer
joshuashaffer / add-user-agents-wget-zsh.patch
Created October 17, 2017 22:46
Add User Agents to wget Command Completion in zsh
--- functions/Completion/Unix/_wget.org 2013-10-10 10:30:13.000000000 -0400
+++ functions/Completion/Unix/_wget 2017-10-17 18:40:36.035294849 -0400
@@ -3,6 +3,18 @@
local curcontext="$curcontext" state line
typeset -A opt_args
+local user_agents
+user_agents=("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
+"Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+"
+"NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)"