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 / RC5.c
Last active October 7, 2019 19:58
RC5.c -- Reference implementation of RC5-32/12/16 in C for Decrypt CO3 Packets
/*
* RC5REF.C -- Reference implementation of RC5-32/12/16 in C.
* Copyright (C) 1995 RSA Data Security, Inc.
* reWritten By Shady Khalifa @shekohex 2018
* see this pdf for more info about RC5: https://goo.gl/U5G44K
*/
#include <stdio.h>
#include <stdlib.h>
typedef unsigned int WORD; // Should be 32-bit = 4 bytes
@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++) {
interface MyConfig {
dbName: string;
port: number;
env: 'prod' | 'dev' | 'test';
}
class TypedConfigManager<T = any> {
getConfig<K extends keyof T>(key: K, fallback: T[K]) {
// do magic stuf here.
}
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];