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
1. Build GraphQL server using `express-graphql` package.
2. Configure `schema.js` file.
3. Query for data.
@xpepermint
xpepermint / README.md
Last active November 14, 2022 19:48
RushJS cheatsheet

Commands

Install dependencies:

npm install -g @microsoft/rush

Initialize the project:

@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 / webpack.config.js
Last active October 27, 2022 06:12
Vue.js webpack.config.js
var path = require('path');
var webpack = require('webpack');
var isProduction = process.env.NODE_ENV === 'production';
/*
* Compile for usage in a browser-like environmen or for the server.
*/
exports.target = 'web';
@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 / 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": {
@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
@xpepermint
xpepermint / webpack.config.js
Last active April 20, 2021 07:04
Webpack Common Configuration File (ReactJS)
'use strict';
/**
* Webpack Configuration File
*
* This is a configuration file for Webpack module bundler. You should customize
* it to fit your project.
*
* To start the development server run:
*
// 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)