Skip to content

Instantly share code, notes, and snippets.

@adielBm
adielBm / lru.py
Last active January 31, 2025 13:46
def cache_block_range(word_addresses, m, n, tag_width, address_width, K):
block_size = 2 ** m
index_mask = (1 << n) - 1
tag_mask = (1 << tag_width) - 1
# Cache: Dictionary of lists for each set (index), each with up to K ways
cache = {i: [{'tag': None} for _ in range(K)] for i in range(1 << n)}
# LRU tracking: LRU[index] keeps track of LRU order for K ways in that index
LRU = [[j for j in range(K)] for _ in range(1 << n)]
@adielBm
adielBm / direct.py
Last active January 31, 2025 14:18
def cache_block_range(word_addresses, m, n, tag_width, address_width):
block_size = 2 ** m
index_mask = (1 << n) - 1
tag_mask = (1 << tag_width) - 1
# Cache structure: list of dictionaries to hold index, tag, and data range
cache = []
mv_count, mt_count, hit_count = 0, 0, 0
@adielBm
adielBm / datahazard.js
Last active January 7, 2025 22:22
data hazard
const STAGES = { IF: 1, ID: 2, EX: 3, MEM: 4, WB: 5 };
const removeParentheses = (str) => str.replace(/.*\(|\)/g, "");
const printRed = (text) => process.stdout.write(`\x1b[31m${text}\x1b[0m`);
function detectDataHazards(instructions) {
let destStage;
process.stdout.write("\n\n---------------------TEST----------------------\n");
const hazards = instructions.map(() => Array(3).fill(null));
@adielBm
adielBm / arabicToHebrew.js
Last active August 30, 2023 13:20
arabicToHebrew
const YOUR_TEXT = "كتاب العين للخليل بن أحمد الفراهيدي"
function arabicToHebrew(str) {
const mapping = {
"ا": "א",
"ب": "ב",
"ج": "ג'",
"د": "ד",
"ذ": "ד'",
"ه": "ה",
@adielBm
adielBm / ipa-for-google-translate.js
Last active January 2, 2025 20:06
ipa for google-translate
// ==UserScript==
// @name IPA for translate.google
// @namespace https://gist.github.com/adielBm/21762fe5e964071cb820a0c46896da34
// @version 2024-06-27
// @description Convert phonetic transcription to IPA on Google Translate
// @author adielBm
// @match https://translate.google.com/*
// @grant none
// @updateURL https://gist.githubusercontent.com/adielBm/21762fe5e964071cb820a0c46896da34/raw
// @downloadURL https://gist.githubusercontent.com/adielBm/21762fe5e964071cb820a0c46896da34/raw
@adielBm
adielBm / shops.js
Created July 14, 2022 11:42
get Coordinates By Address
import { writeFile, readFile } from 'node:fs';
import fetch from "node-fetch";
async function getCoordinatesByAddress(address) {
const api = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=MY_API_KEY`;
const response = await fetch(api);
const data = await response.json();
return data;
}