Skip to content

Instantly share code, notes, and snippets.

View xcaptain's full-sized avatar

Joey xcaptain

View GitHub Profile
@xcaptain
xcaptain / deeper-chain-block-3234675.txt
Created March 15, 2022 10:50
block detail of 3234675
Header:
Header { parent_hash: 0x8933e679f6ec2f4ec831fdc856949483a5cd2f97b3092af61d1360c0ad56d10c, number: 3234675, state_root: 0x9395fe4ba2caf22d04c998492d083f2bc78b0355f7450d3cf03f4fa113464f1c, extrinsics_root: 0x68fe4fb0482a7af39b18d68f92f90c13edfc000e7878c7aa2cae1289bbce78f9, digest: Digest { logs: [DigestItem::PreRuntime([66, 65, 66, 69], [2, 1, 0, 0, 0, 81, 90, 160, 19, 0, 0, 0, 0]), DigestItem::Consensus([102, 114, 111, 110], [1, 26, 47, 127, 198, 167, 108, 138, 212, 3, 22, 129, 235, 44, 69, 155, 119, 55, 171, 124, 207, 219, 238, 190, 17, 213, 117, 214, 167, 56, 173, 42, 15, 4, 164, 24, 50, 229, 201, 233, 190, 118, 82, 223, 169, 58, 57, 173, 239, 215, 111, 6, 41, 120, 67, 188, 157, 124, 144, 128, 169, 142, 61, 180, 132, 254]), DigestItem::Seal([66, 65, 66, 69], [122, 250, 192, 111, 59, 137, 103, 110, 254, 167, 180, 48, 80, 23, 123, 150, 8, 255, 196, 182, 136, 155, 227, 111, 132, 119, 38, 14, 249, 208, 104, 81, 80, 233, 176, 131, 157, 96, 172, 221, 64, 77, 59, 127, 184, 144, 160, 94, 237, 211, 198, 213,
@xcaptain
xcaptain / offline_transfer.js
Created November 17, 2021 13:05
sign transaction offline and then submit to chain
const { ApiPromise, WsProvider } = require('@polkadot/api');
const { Keyring } = require('@polkadot/keyring');
const {
construct,
decode,
deriveAddress,
getRegistry,
methods,
PolkadotSS58Format,
} = require('@substrate/txwrapper-polkadot');
@xcaptain
xcaptain / main.rs
Last active December 28, 2019 02:49
actix-web casbin demo
use std::io;
use std::sync::{Arc, RwLock};
use casbin::{Enforcer, FileAdapter, Model, RbacApi};
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
/// simple handle
async fn index(enforcer: web::Data<RwLock<Enforcer<FileAdapter>>>, req: HttpRequest) -> HttpResponse {
println!("{:?}", req);
assert_eq!(vec!["data1_admin"], enforcer.write().unwrap().get_roles_for_user("alice"));
@xcaptain
xcaptain / di.rs
Last active November 14, 2019 08:30
A simple DI container
#[macro_use]
extern crate downcast_rs;
use downcast_rs::DowncastSync;
use std::any::{Any, TypeId};
use std::collections::HashMap;
pub trait Resolvable {
fn resolve<T: Injectable>(&self) -> Option<&T>;
// TODO: use impl Injectable or Box<dyn Injectable>?
"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-nostdlib" "/home/joey/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crt1.o" "/home/joey/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crti.o" "-L" "/home/joey/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "/home/joey/github/vector/target/x86_64-unknown-linux-musl/debug/deps/vector-041044fb0a65e4a1.10003g8tm9m9a9re.rcgu.o" "/home/joey/github/vector/target/x86_64-unknown-linux-musl/debug/deps/vector-041044fb0a65e4a1.1065etxaeawt1v5k.rcgu.o" "/home/joey/github/vector/target/x86_64-unknown-linux-musl/debug/deps/vector-041044fb0a65e4a1.128pf4ngj1mre226.rcgu.o" "/home/joey/github/vector/target/x86_64-unknown-linux-musl/debug/deps/vector-041044fb0a65e4a1.13m875uyi4ea1d9f.rcgu.o" "/home/joey/github/vector/target/x86_64-unknown-linux-musl/debug/deps/vector-041044fb0a65e4a1.1587nu0lntfrin53.rcgu.o" "/hom
@xcaptain
xcaptain / AuthzMiddleware.cs
Last active September 6, 2021 09:57
casbinnet asp dotnet core setup
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using TodoApi.Services;
namespace TodoApi.Middlewares
{
public class AuthzMiddleware
{
private readonly RequestDelegate _next;
@xcaptain
xcaptain / category_tree.py
Last active December 27, 2018 07:30
a generic tree in python
# generic tree in python
# to demostrate a category tree
class Tree:
def __init__(self):
self.roots = []
def add_root(self, val):
node = Node(val)
self.roots.append(node)
@xcaptain
xcaptain / typescript_function_type_error_test.ts
Created August 8, 2018 11:41
Argument of type 'Function' is not assignable to parameter of type '(...args: any[]) => void'. Type 'Function' provides no match for the signature '(...args: any[]): void'
function on(event: string, listener: Function) {
console.log('on event: ', event, 'typeof listener:', typeof (listener));
listener();
}
function on1(event: string, listener: (...args: any[]) => void) {
console.log('on event: ', event, 'typeof listener:', typeof (listener));
listener();
}
@xcaptain
xcaptain / simple_list.rs
Created August 7, 2018 03:52
simple list implementation in rust
struct List {
head: Link,
}
type Link = Option<Box<Node>>;
struct Node {
elem: i32,
next: Link,
}
@xcaptain
xcaptain / amphp_lumen.php
Last active December 9, 2022 02:51
server lumen app using amphp-server
<?php
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Server;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Socket;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\File\UploadedFile;