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 / 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
@jbr
jbr / cargo.toml
Created April 24, 2020 05:10
surf-tide-proxy-example
[package]
name = "surf-tide-proxy-example"
version = "0.1.0"
authors = ["Jacob Rothstein <hi@jbr.me>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
surf = { git = "https://github.com/http-rs/surf", branch = "master" }
@Phaiax
Phaiax / how-does-async-work-in-async-std.md
Last active July 17, 2023 10:56
Blog article: How does async work in async-std?

How does async work in async-std?

(Phaiax - 2019/12/1 - CC_BY_SA 4.0)

Lately I was porting a software from tokio/futures-1.0 to async-await. I somehow thought async-std was the successor of tokio and ported everything to async-std. 80% in, I noticed that my hyper dependency requires tokio and that it's not possible to replace tokio with async-std without also replacing hyper. Also, tokio and async-std try to solve the same problem. So I started a journey into the inners of the rust async story to find out if it is possible to use both tokio and async-std at the same time. (tl;dr: it is). I had heard of reactors and executors before, but there was much new stuff to discover.

@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 / README.md
Last active November 14, 2022 19:48
RushJS cheatsheet

Commands

Install dependencies:

npm install -g @microsoft/rush

Initialize the project:

@xpepermint
xpepermint / index.js
Created September 30, 2017 16:47
Using RawModel in ExpressJS actions.
const { Model } = require("rawmodel");
const express = require("express");
/** Application context *******************************************************/
class Context {
constructor() {
this.db; // imaginary database
}
connect() {
@xpepermint
xpepermint / pre-post
Last active November 28, 2016 09:10
git `.git/hooks/pre-post` to commite bundles into `production` branch
```
#!/bin/sh
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [ "master" != "$branch" ]; then
exit;
fi
git checkout production
@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';
@fbaiodias
fbaiodias / README.md
Last active July 21, 2021 19:04
GraphQL circular dependencies

Circular dependencies on GraphQL schemas

Problem

Whenever I uncomment the lines on author.js I get the following error:

/Users/xicombd/Code/taskq/taskq-api/node_modules/graphql/jsutils/invariant.js:20
    throw new Error(message);
    ^