Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Developing the future

Kristijan Sedlak xpepermint

💭
Developing the future
View GitHub Profile
@xpepermint
xpepermint / u32_struct.rs
Last active Oct 7, 2021
Reimplementation of a u32 type in Rust.
View u32_struct.rs
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 Sep 26, 2021
Check if struct implements a specific trait
View example.rs
```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
View Function accepts struct or function pointer
// 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)
View xcert-certification-example-for-ethereum.js
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": {
View gist:2ce1d9aaa134db8fed1b90c87292a373
```
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 Nov 25, 2018
Fix for: [nuxt] Error while initializing app ReferenceError: exports is not defined
View nuxt.config.js
export default {
build: {
extend(config, { isDev }) {
if (isDev) config.resolve.symlinks = false
},
},
}
View .travis.yml
---
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 Jul 10, 2021
RushJS cheatsheet
View README.md

Commands

Install dependencies:

npm install -g @microsoft/rush

Initialize the project:

@xpepermint
xpepermint / index.ts
Created Aug 13, 2018
Merkle tree implementation
View index.ts
/**
* Converts a list of values into a list of pairs.
* @param arr Single dimensional array of values.
*/
function toPairs(arr) {
return Array.from(Array(Math.ceil(arr.length / 2)), (_, i) => arr.slice(i * 2, i * 2 + 2));
}
/**
* Converts a list of values into a list of pairs.
@xpepermint
xpepermint / Command
Created Jul 19, 2018
MongoDB setup using Docker
View Command
docker run -d \
--name mongo \
-p 27017:27017 \
-v ~/.docker/machine/volumes/mongo/4/data:/data/db \
mongo:4