Skip to content

Instantly share code, notes, and snippets.

View Shoghy's full-sized avatar

Shoghy Martinez Shoghy

  • MekTechnology
  • Santiago De Los Caballeros, Dominican Republic
View GitHub Profile
@Shoghy
Shoghy / adding float16 bytes.ts
Last active April 14, 2025 13:41
Manual float 16 add
const byteMask = 0xff_ff;
function AddFloat16(a: number, b: number): number {
a = a & byteMask;
b = b & byteMask;
const signA = a >> 15;
const signB = b >> 15;
let expA = (a >> 10) & 0b11111;
let expB = (b >> 10) & 0b11111;
let mantA = a & 0b1111111111;
export interface TimeSpanProps {
ms?: number;
seconds?: number;
minutes?: number;
hours?: number;
days?: number;
}
export class TimeSpan {
private readonly _ms: number;
type ValueOfNumber = { valueOf(): number };
abstract class Int<T extends new (value: ValueOfNumber) => InstanceType<T>> {
public abstract get value(): number;
public abstract set value(val: ValueOfNumber);
public abstract valueOf(): number;
private Construct: T;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public constructor(_: ValueOfNumber) {
@Shoghy
Shoghy / main.zig
Last active March 11, 2025 14:09
Base64 encoder
const std = @import("std");
const gpa = std.heap.page_allocator;
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
pub fn main() !void {
const text = "AAA";
var base64Length = (text.len / 3) * 4;
if ((text.len % 3) > 0) {
@Shoghy
Shoghy / defer.ts
Last active March 7, 2025 14:42
A kind of defer function in TS
export function SelfPromiseFunc<Params extends Array<unknown>, ReturnType>(
func: (this: Promise<ReturnType>, ...params: Params) => ReturnType,
) {
return (...p: Params) => {
let resolve: (v: ReturnType) => void;
let reject: (v: unknown) => void;
const promise = new Promise<ReturnType>((rsv, rjc) => {
resolve = rsv;
reject = rjc;
@Shoghy
Shoghy / modular.rs
Created May 4, 2024 20:10
Modular exponentiation
fn modadd(a: u64, b: u64, module: u64) -> u64{
if a >= module{
return a%module;
}else if b >= module{
return b%module;
}
if a > module - b{
return a - (module - b);
}else if b > module - a {
return b - (module - a);
@Shoghy
Shoghy / catcher.ts
Last active July 22, 2024 04:36
A typescript try/catch with type aware catchs.
export type Func<P extends Array<unknown>, R> = (...args: P) => R;
interface JSTypes{
string: string
number: number
bigint: bigint
boolean: boolean
symbol: symbol
undefined: undefined
object: object
@Shoghy
Shoghy / HandleInertiaRequests.php
Created March 12, 2024 13:57
How to use VueJS with Laravel 7
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
{
/**
@Shoghy
Shoghy / file_getter.js
Created February 26, 2024 15:40
A function to get all files on a folder and its subfolders recursively without using function recursion
import fs from "fs";
/**
* @param {Array<T>} arr
* @param {number} index
* @returns {Array<T>}
* @template T
*/
function RemoveIndexOfArray(arr, index){
const copyOfArray = [... arr];
@Shoghy
Shoghy / BetterStr.php
Last active February 16, 2024 11:47
A PHP class that saves a string and implements string methods
<?php
/**
* @property-read int $length
*/
class BetterStr{
protected string $value = "";
public function get_value(){
return $this->value;
}