Skip to content

Instantly share code, notes, and snippets.

View EAirPeter's full-sized avatar

EAirPeter EAirPeter

View GitHub Profile
@EAirPeter
EAirPeter / ub.cpp
Created November 18, 2021 17:17
Try it with clang
#include <cstdio>
using namespace std;
void Foo(void) {
//puts("Foo Start");
for (int i = 0; i >= 0; ++i) {
// Undefined behavior
}
puts("Foo End");
@EAirPeter
EAirPeter / msws.hpp
Created October 8, 2020 00:32
Middle Square Weyl Sequence PRNG in C++14
// PRNG: Middle Square Weyl Sequence
//
// This is a rewrite of mswsrngv3 from https://mswsrng.wixsite.com/rand in
// C++14. This file is licensed under MIT license.
//
// Use msws::Msws as a UniformRandomBitGenerator and RandomNumberEngine.
// #define MSWS_NOIOS to remove formatted I/O support with C++ input/output
// streams.
//
// MIT License
@EAirPeter
EAirPeter / .vimrc
Created January 20, 2019 10:56
My .vimrc
set nocompatible
set encoding=utf-8
set fileencodings=utf-8,gbk,s-jis
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
@EAirPeter
EAirPeter / cppcp.cpp
Last active September 29, 2018 09:08
Combines multiple C/C++ files into one and copy to clipboard.
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <cstdlib>
#include <exception>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
@EAirPeter
EAirPeter / Decode.cpp
Created August 11, 2018 06:02
Decodes cdb file
#define _CRT_SECURE_NO_WARNINGS
#define _WIN32_LEAN_AND_MEAN
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <Windows.h>
-- add admin user
declare @adminUname varchar(32) = 'admin';
declare @adminPword varchar(32) = 'admin';
declare @adminSalt binary(64) = crypt_gen_random(64);
declare @adminStoredPword binary(64) = hashbytes('SHA2_512', convert(binary, @adminPword) + @adminSalt);
insert into [dbo].[User]([uname], [storedPword], [salt], [priv]) values
(@adminUname, @adminStoredPword, @adminSalt, 0);
-- add demo flights
declare @Airport table([iata] char(3) primary key);
@EAirPeter
EAirPeter / SudokuSolver.cpp
Created May 23, 2018 13:19
Copmile-time sudoku solver.
#include <cstdint>
namespace {
using namespace std;
template<uint32_t MaxCCol = 9 * 9 * 4, uint32_t MaxCNode = 9 * 9 * 9 * 9, uint32_t MaxCAns = 9 * 9>
class DancingLink {
private:
struct Node {
uint32_t U, D, L, R;
uint32_t Col, Row;
@EAirPeter
EAirPeter / gen.cpp
Created May 5, 2018 07:42
【Java实验二】数据生成用
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdio>
#include <random>
#include <string>
#include <vector>
using namespace std;
using namespace chrono;
@EAirPeter
EAirPeter / AutoClick.cpp
Last active May 2, 2018 09:52
按CTRL-ALT-Q,自动点击鼠标下窗口的相对坐标,间隔200ms。再次按CTRL-ALT-Q停止。https://enza.fun/game/1?code=f85c45f2-c7c7-4e7c-a17a-eb282c7c5f78&openExternalBrowser=1
#include <Windows.h>
#include <math.h>
#include <stdio.h>
void ErrorExit(const char *pszWhat) {
auto dwError = GetLastError();
char *pBuf;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &pBuf, 0, nullptr