Skip to content

Instantly share code, notes, and snippets.

View petemud's full-sized avatar

Petro Mudrievskyj petemud

  • Petro Mohyla Black Sea National University
  • Ukraine
View GitHub Profile
@petemud
petemud / strcpy.s
Created January 17, 2025 11:11
RISV-V vectorized strcpy
loop:
vsetvli t0, zero, e8, m8, ta, ma # set vl to VLMAX
vle8ff.v v8, (a0) # vleff only reads up until the page that is not mapped/demand-paged in.
# regular vle8 is unsuitable, because it can give a segfault
vmseq.vi v0, v8, 0 # flag null terminator
vfirst.m t1, v0 # find first null terminator
bgez t1, save_tail # finish if found
vse8.v v8, (a1) # store vl bytes (vl can be less than VLMAX)
@petemud
petemud / random-password.js
Last active October 26, 2019 10:35
JavaScript random password generator
var len = 12
var res = await fetch(`https://www.random.org/integers?num=${len}&min=32&max=126&format=plain&base=10&col=1`)
var text = await res.text()
console.log(String.fromCharCode(...text.trimEnd().split('\n')))

Как избежать столкновения в шею

Расскрасим всё поле в два цвета: черный и белый

 ▒ ▒ ▒ ▒
▒ ▒ ▒ ▒ 
 ▒ ▒ ▒ ▒
▒ ▒ ▒ ▒ 
 ▒ ▒ ▒ ▒
▒ ▒ ▒ ▒ 

There is a flaw in FindGame request (made by [Assembly-CSharp-firstpass] bgs.GamesApi.FindGame method).
It’s possible to send FindGame request with gameAccountId set to someone’s else game account.
This causes given account to connect to the game that we've you requested.
And if that account is already connected to some other game, it will disconnect from it.
Disconnect is not permanent. Player can reconnect. But if we're disconnecting him every couple of seconds he has no chance.
We can't request a ranked game for given game account because it requires deckId and we don't know deck ids.
We can't do FindGame request if we're already in the match.

How to exploit:

  • During the match get our opponent's gameAccountId:
@petemud
petemud / discrete_function.cpp
Last active March 1, 2018 21:02
C++ discrete function random access iterator
template<class Arg, class Result, class Fn>
struct discrete_function {
discrete_function (Fn fn, Arg start, Arg end) : fn_(fn), start_(start), end_(end) { }
struct iterator : public std::iterator<std::random_access_iterator_tag, Result, Arg> {
friend discrete_function;
bool operator == (const iterator &other) const { return arg_ == other.arg_; }
bool operator != (const iterator &other) const { return arg_ != other.arg_; }
bool operator < (const iterator &other) const { return arg_ < other.arg_; }
bool operator > (const iterator &other) const { return arg_ > other.arg_; }
@petemud
petemud / ternary_search.cpp
Last active March 1, 2018 21:01
C++ template ternary search algorithm over iterator
template<typename ForwardIterator>
ForwardIterator ternarySearch(ForwardIterator first, ForwardIterator last) {
auto count = std::distance(first, last);
while (count > 2) {
ForwardIterator m1 = first;
auto step = count/3;
std::advance(m1, step);
ForwardIterator m2 = m1;
std::advance(m2, step);
if (*m1 < *m2) {