Skip to content

Instantly share code, notes, and snippets.

View samermurad's full-sized avatar

Samer Murad samermurad

View GitHub Profile
@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 / 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 / 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 / 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 / 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(); };