This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Repeater { | |
| export function repeat(value: string, count: number) { | |
| if (count < 0) throw new Error("Count must be a non negative number"); | |
| return value.repeat(count); | |
| } | |
| } | |
| module WhiteSpace { | |
| export function repeat(count: number) { | |
| return Repeater.repeat(" ", count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Connection, PublicKey, Transaction } from "@solana/web3.js"; | |
| import { getAssociatedTokenAddress, createAssociatedTokenAccountInstruction } from "@solana/spl-token"; | |
| import Solana from "@ledgerhq/hw-app-solana"; | |
| import TransportNodeHid from "@ledgerhq/hw-transport-node-hid"; | |
| (async () => { | |
| // Check your derivative address path via the ledger live app. | |
| const bip32path = "44'/501'"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn shl_plain(v: [u32; 4], o: i32) -> [u32; 4] { | |
| [v[0] << o, v[1] << o, v[2] << o, v[3] << o] | |
| } | |
| #[cfg(target_arch = "aarch64")] | |
| fn shl_neon(v: [u32; 4], o: i32) -> [u32; 4] { | |
| use std::arch::aarch64::{vld1q_s32, vld1q_u32, vqshlq_u32, vst1q_u32}; | |
| unsafe { | |
| let v = vld1q_u32(v.as_ptr()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn sha256(data: &[u8]) -> [u8; 32] { | |
| #![allow(non_camel_case_types)] | |
| #![allow(non_snake_case)] | |
| macro_rules! ch { | |
| ($x:expr, $y:expr, $z:expr) => { | |
| ($x & $y) ^ ((!$x) & $z) | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::ops::Deref; | |
| pub trait FloatBitOps { | |
| type UBits; | |
| type SBits; | |
| fn sign_bit_left(self) -> Self::UBits; | |
| fn exponent_bits_left(self) -> Self::UBits; | |
| fn mantissa_bits_left(self) -> Self::UBits; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn encode<'a, I>(data: I, key: u8) -> Vec<u8> | |
| where | |
| I: IntoIterator<Item = &'a u8>, | |
| { | |
| data.into_iter() | |
| .map(|&b| b.wrapping_add(key)) | |
| .collect::<Vec<_>>() | |
| } | |
| pub fn decode<'a, I>(data: I, key: u8) -> Vec<u8> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub trait DwordOps<TOutput> { | |
| fn low_dword(self) -> TOutput; | |
| fn high_dword(self) -> TOutput; | |
| } | |
| impl DwordOps<u64> for u64 { | |
| #[inline(always)] | |
| fn low_dword(self) -> u64 { | |
| self & 0x0000_0000_ffff_ffff_u64 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn generate(count: usize) -> Vec<u32> { | |
| assert!(count > 0); | |
| let mut probe = 1; | |
| let mut primes = { | |
| let mut vec = Vec::with_capacity(count); | |
| vec.push(2u32); | |
| vec | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub trait BitSelect { | |
| fn bitselect(self, right: Self, filter: Self) -> Self; | |
| } | |
| macro_rules! impl_bitselect { | |
| ($first:ty, $($rest:ty),+) => { | |
| impl_bitselect!($first); | |
| impl_bitselect!($($rest),+); | |
| }; | |
| ($ty:ty) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Uuid = string; |
NewerOlder