Skip to content

Instantly share code, notes, and snippets.

View xpepermint's full-sized avatar
💭
Developing the future

Kristijan Sedlak xpepermint

💭
Developing the future
View GitHub Profile
@xpepermint
xpepermint / binary_search.rs
Created November 4, 2022 16:23
Find chunk index in buffer of chunks using binary search algorithm.
fn main() {
// vector of data built from 4-bytes chunks
let mut buf = vec![];
buf.extend(1u32.to_be_bytes());
buf.extend(10u32.to_be_bytes());
buf.extend(20u32.to_be_bytes());
buf.extend(47u32.to_be_bytes()); // searching for this one
buf.extend(59u32.to_be_bytes());
buf.extend(63u32.to_be_bytes());
@xpepermint
xpepermint / from-linux.rs
Last active May 2, 2022 09:25
Rust random number
use std::fs::File;
use std::io::Read;
fn main() {
let mut f = File::open("/dev/urandom").unwrap(); // from Linux
let mut buf = [0u8; 16];
f.read_exact(&mut buf).unwrap();
println!("{:?}", buf);
}
@xpepermint
xpepermint / u32_struct.rs
Last active October 7, 2021 21:14
Reimplementation of a u32 type in Rust.
use std::ops;
#[derive(Debug, Default, Clone, Copy, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct U32(u32);
impl ops::Add for U32 {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self(self.0 + rhs.0)
}
@xpepermint
xpepermint / example.rs
Created September 26, 2021 18:09
Check if struct implements a specific trait
```rs
// Based on: https://www.reddit.com/r/rust/comments/ehr8ct/announcing_impls_a_macro_to_determine_if_a_type/
// trait for T
trait TTrate {
const VALUE: bool = false;
}
impl<T> TTrate for T {}
// custom trait
// Parameter that each resolver accepts.
pub struct Intent {}
// Resolver definition.
pub trait Resolver {
fn resolve(&self, intent: Intent) -> Result<usize, usize>;
}
impl<F: Fn(Intent) -> Result<usize, usize>> Resolver for F {
fn resolve(&self, intent: Intent) -> Result<usize, usize> {
self(intent)
@xpepermint
xpepermint / xcert-certification-example-for-ethereum.js
Last active October 10, 2021 17:16
0xcert.org certification
const { Cert } = require('@0xcert/cert');
const { HttpProvider } = require('@0xcert/ethereum-http-provider');
const { AssetLedger } = require('@0xcert/ethereum-asset-ledger');
(async () => {
const schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"description": "A digital assets that have a unique combination of different properties.",
"properties": {
```
docker run -d \
--name geth-test \
-p 8545:8545 \
-v ~/.docker/machine/volumes/geth-test/data:/root/.ethereum \
ethereum/client-go \
--testnet \
--rpc \
--rpcaddr "0.0.0.0" \
--rpccorsdomain "*" \
@xpepermint
xpepermint / nuxt.config.js
Created November 25, 2018 10:47
Fix for: [nuxt] Error while initializing app ReferenceError: exports is not defined
export default {
build: {
extend(config, { isDev }) {
if (isDev) config.resolve.symlinks = false
},
},
}
@xpepermint
xpepermint / .travis.yml
Created October 4, 2018 08:10
Codecov setup
---
language: node_js
node_js:
- 9
- 10
script:
# use latest npm to work on node9
- npm install -g npm
# codecov
- npm install -g codecov
@xpepermint
xpepermint / README.md
Last active November 14, 2022 19:48
RushJS cheatsheet

Commands

Install dependencies:

npm install -g @microsoft/rush

Initialize the project: