Skip to content

Instantly share code, notes, and snippets.

View shekohex's full-sized avatar
🦀
building a better world

shekohex

🦀
building a better world
View GitHub Profile
@shekohex
shekohex / block.dart
Created December 21, 2017 00:06
Simple Block Chain Mechanism in Dart for Learning Purpose
library block;
import 'dart:async';
import 'package:crypto/crypto.dart' show sha256;
class Block {
int nonce = 0;
String _hash;
final int index;
final int ts;
@shekohex
shekohex / block.go
Created December 23, 2017 20:58
Simple Block Chain Mechanism in Go for Learning Purpose
package main
import (
"crypto/sha256"
"encoding/json"
"fmt"
"strings"
)
// Data ...
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shekohex
shekohex / main.js
Created September 8, 2018 18:32
Get YouTube Playlist total time
//@ts-check
console.time('Elapsed time');
const playlistVideos = document.querySelector(
"#contents > ytd-playlist-video-list-renderer > #contents"
);
const spanTime = document.querySelectorAll(
"#overlays > ytd-thumbnail-overlay-time-status-renderer > span"
);
let playlistTime = 0;
for (let i = 0; i < playlistVideos.childElementCount; i++) {
const users = [
{
Name: 'Ramy',
City: {
1: {
city: 'Zagazig'
},
2: {
city: 'Banha'
}
@shekohex
shekohex / async-result.ts
Created December 8, 2018 13:44
AsyncResult, a Rusty Result in Typescript, for fun.
export class AsyncResult<T, E extends Error = any> {
private constructor(private readonly value?: T, private readonly error?: E) {}
public static Ok<T, E extends Error>(value: T) {
return new AsyncResult<T, E>(value);
}
public static Err<T, E extends Error>(error: E) {
return new AsyncResult<T, E>(undefined, error);
}
@shekohex
shekohex / roles.pest
Created March 14, 2019 17:24
Simple boolean expression parser Roles using pest.rs https://pest.rs
AND = { "." }
NOT = { "`" }
OR = { "+" }
SEP = _{ (NEWLINE | WHITE_SPACE) }
VAR_NAME = { (ASCII_ALPHA ~ ASCII_DIGIT*) }
VAR = { VAR_NAME ~ SEP* ~ NOT? ~ SEP* }
EXP = { VAR ~ SEP* ~ ((OR | AND) ~ SEP* ~ VAR ~ SEP*)* }
FUNC = { VAR ~ SEP* ~ "=" ~ SEP* ~ EXP+ }
ROOT = _{ SOI ~ NEWLINE* ~ (FUNC | ANY) ~ NEWLINE* ~ EOI }
/// https://leetcode.com/problems/parsing-a-boolean-expression
/**
* @param {string} expression
* @return {boolean}
*/
var parseBoolExpr = function(expression) {
const stack = [];
for (let i = 0; i <= expression.length; ++i) {
const c = expression[i];
@shekohex
shekohex / errors.ts
Created August 7, 2019 11:50
Server Error Code Boilerplate for Nestjs applications
import { HttpStatus } from '@nestjs/common';
export const enum ErrorCode {
BAD_TOKEN = 1000,
TOKEN_ERROR,
UNAUTHORIZED,
}
export interface ErrorMessage {
errorCode: ErrorCode;
@shekohex
shekohex / rustfmt.toml
Created August 11, 2019 16:08
Rust Format Configuration for my projects
max_width = 80
tab_spaces = 4
fn_single_line = true
match_block_trailing_comma = true
normalize_comments = true
wrap_comments = true
merge_imports = true
reorder_impl_items = true
use_field_init_shorthand = true
use_try_shorthand = true