Skip to content

Instantly share code, notes, and snippets.

View samermurad's full-sized avatar

Samer Murad samermurad

View GitHub Profile
@samermurad
samermurad / Mutex.js
Created March 22, 2023 11:09
A very basic JavaScript implementation of a Mutex, using promises
class Mutex {
constructor() {
this.current = Promise.resolve();
}
async acquire() {
let release
const next = new Promise(resolve => {
release = () => { resolve(); };
@samermurad
samermurad / maps.hks.ts
Last active May 11, 2022 10:45
Open maps link on react-native
import {useCallback} from 'react';
import {Alert, Linking, Platform} from 'react-native';
const APPLE_MAPS_LINK = 'https://maps.apple.com/?address=';
const GOOGLE_MAPS_LINK = 'https://www.google.com/maps/search/?api=1&query=';
type AddressStringFunc = (address: string) => Promise<void>;
export const useOpenMapsWithAddress = (): AddressStringFunc => {
return useCallback(async (address: string) => {
@samermurad
samermurad / RateLimiter.cs
Created March 28, 2022 22:02
RateLimiter for various purposes
class RateLimiter {
public int fps = 100;
public bool isActive = true;
private float? timer = null;
public RateLimiter(int fps, bool immediate = false) {
this.fps = fps;
if (immediate) this.Invalidate();
else this.Reset();
}
@samermurad
samermurad / README.md
Created December 6, 2021 17:20
PBTails SDL2 X/Y Triangle/Square Mapping Fix

PBTails Controller mapping fix

https://www.pbtails.com/

This mapping fixes the flipp of the X/Y Triangle/Square buttons on the controller. I needed this fix for game dev and for the PS2 emulator, PCSX2

PCSX2 Fix

insert the following line into the game_controller_db.txt file, on macOS, file can be found:

@samermurad
samermurad / fixCarbonLinkOnMedium.js
Created September 3, 2021 15:58
Fixes the Links to Carbon.now.sh
function fixMediumLink(link) {
const text = document.createElement('input')
text.value = encodeURI(link.replace('sh/embed', 'sh').replace(/sh\/?/, 'sh/embed'))
text.select();
document.execCommand("copy");
return text.value
}
@samermurad
samermurad / lodashGetNonNull.js
Created November 16, 2020 10:31
lodash getNonNull
const _ = require('lodash');
/**
* File adds a "getNonNull" function to the set of the lodash functions
* function works exactly like `_.get` with one simple exception
* the _.getNonNull returns the default value for null values as well
* just make sure to require this file on your main js/ts file
*
* Example:
* var foo = { bar: undefined: bar1: null }
* with _.get:
@samermurad
samermurad / tmpCache.js
Last active September 30, 2020 13:00
Tmp Cache for NodeJs scripts, very useful for small program where you might want to persist some data for later reuse
// Written by Samer Murad
const path = require('path');
const fs = require('fs');
const os = require('os');
class TmpCache {
constructor(ID) {
this.FILE_ID = ID;
@samermurad
samermurad / outlinedProgress.html
Created May 19, 2020 15:02
HTML/JS/CSS Inverted Progress Text progress bar
<!DOCTYPE html>
<html>
<head>
<title> Test Progress</title>
</head>
<style type="text/css">
.progress {
position: relative;
display: flex;
height: 100px;
@samermurad
samermurad / tmMsg.js
Created January 10, 2020 17:59
Nodejs Request send Telegram Message through a bot
const requrest = require('request')
const BOT_TOKEN = '<YOUR_TOKEN_HERE>'
const CHAT_ID = 0 // <YOUR_CHAT_ID>
const tmMsg = (text) => {
const options = {
method: 'POST',
url: `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: CHAT_ID, text })
@samermurad
samermurad / cryptor.js
Last active January 10, 2020 13:57
Nodejs Basic aes256 encrypt decrypt implementation
const crypto = require('crypto');
const TAG = 'cryptor || '
/**
* @typedef CryptResult
* @property {string} iv
* @property {string} crypt
*/