Skip to content

Instantly share code, notes, and snippets.

View k06a's full-sized avatar
🚀
DeFi dreamer

Anton Bukov k06a

🚀
DeFi dreamer
View GitHub Profile
@k06a
k06a / 4bytes.json
Created September 5, 2018 07:45
4bytes.json
This file has been truncated, but you can view the full file.
{
"0x94f61134":"executeOrder(uint256)",
"0xc5fee757":"executeOrder2(uint256)",
"0xe9fca283":"buy(uint256,bytes32)",
"0x0ed74c08":"func_0C2C()",
"0xba485844":"func_0C0E()",
"0x6971d64c":"func_0AB9()",
"0xe31e2d6d":"func_0A93()",
"0x304bac6f":"func_0A6E()",
"0x70357e79":"func_08D3()",
@k06a
k06a / AVPlayerItem+MLWPerformance.m
Last active September 7, 2023 11:51
Smooth AVPlayer scrolling in UICollectionView/UITableView
#import <JRSwizzle/JRSwizzle.h>
@implementation AVPlayerItem (MLWPerformance)
+ (void)load {
[AVPlayerItem jr_swizzleMethod:NSSelectorFromString(@"_attachToFigPlayer") withMethod:@selector(mlw_attachToFigPlayer) error:nil];
}
- (void)mlw_attachToFigPlayer {
static dispatch_queue_t queue = nil;
@k06a
k06a / MLWAsyncAVPlayer.h
Last active September 7, 2023 11:51
Awesome optimized AVPlayer for smooth scrolling AVPlayerLayer inside UICollectionView/UITableView (tested on iOS10+)
#import <AVFoundation/AVFoundation.h>
@interface MLWAsyncAVPlayer : AVPlayer
@end
@k06a
k06a / ShardedToken.sol
Last active May 17, 2023 13:15
ShardedToken
contract ShardedToken {
using SafeMath for uint256;
address owner = msg.sender;
uint256 private _totalSupply;
mapping(address => ShardedToken.Extension) private extensions;
function register() public {
extensions[msg.sender] = new Token.Extension();
}
@k06a
k06a / query.sh
Last active October 18, 2022 11:09
Passwords Query (+macOS-fix) (+sgrep)
#!/bin/bash
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# magnet:?xt=urn:btih:7ffbcd8cee06aba2ce6561688cf68ce2addca0a3
# 1. Fixed letter1, letter2, letter3 assignments for macOS compatibility
# 2. Changed grep to sgrep (sorted grep), need to preinstall: npm i -g sgrep
if [ "$1" != "" ]; then
letter1=$(echo ${1:0:1})
if [[ $letter1 == [a-zA-Z0-9] ]]; then
@k06a
k06a / isPowOfTen.yul
Last active September 29, 2022 14:49
isPowOfTen.yul
// https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
function isPowerOfTen(uint256 x) public pure returns (bool result) {
assembly {
let dict := 0x00011c021d0e18031e16140f191104081f1b0d17151310071a0c12060b050a09
let zeroes := 0
for { let offset := 0 } lt(offset, 256) { offset := add(offset, 32) } {
let v := and(shr(offset, x), 0xffffffff)
switch v
@k06a
k06a / lohi.h
Created January 21, 2022 12:23
Efficient BigInt - Lohi (uint128_t, uint256_t, uint512_t)
#ifndef Lohi_h
#define Lohi_h
namespace lohi {
template<typename T>
struct Lohi;
template<typename T>
T zero(thread const T &) {
return 0;
@k06a
k06a / log_2_rand_0_1.sol
Last active August 25, 2022 14:56
log_2_rand_0_1
/*
* ABDK Math 64.64 Smart Contract Library. Copyright © 2019 by ABDK Consulting.
* Author: Mikhail Vladimirov <mikhail.vladimirov@gmail.com>
*/
pragma solidity ^0.5.7;
/**
* Modified version of this code:
* https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L366
*
const { BN } = require('bn.js');
const { keccak256 } = require('ethereumjs-util');
const { toBN } = require('web3-utils');
// function hash (selector, salt, m) {
// return new BN(selector, 'hex').xor(toBN(salt)).toNumber() % 25469 % m;
// }
function hash (selector, salt, m) {
const saltStr = toBN(salt).toString('hex', 8);
@k06a
k06a / sodis.js
Created June 22, 2022 20:45
Constant-time Solidity dispatcher MVP
const { BN } = require('bn.js');
const { keccak256 } = require('ethereumjs-util');
const { toBN } = require('web3-utils');
const numberOfSelectors = 1000;
const tableSizeKoef = 1.5;
const maxBucketSize = 2;
function hash (selector, salt, m) {
return new BN(selector, 'hex').xor(toBN(salt)).toNumber() % 65537 % m;