Skip to content

Instantly share code, notes, and snippets.

View fawazahmed0's full-sized avatar

Fawaz Ahmed fawazahmed0

View GitHub Profile
@fawazahmed0
fawazahmed0 / search.js
Created November 22, 2025 12:04
Search files with JS
const fs = require('fs/promises')
const path = require('path')
const pathToDir = path.join(__dirname, '.')
const textToSearch = /\.docx/i
async function main(){
let result = await fs.readdir(pathToDir, { withFileTypes: true, recursive: true })
result = result.filter(e => textToSearch.test(e.name))
console.log(result.map(e => path.join(e.parentPath, e.name)))
@fawazahmed0
fawazahmed0 / http-proxy.js
Last active May 23, 2025 08:05
simple http proxy
/*
client connects to proxy.example (via HTTP or HTTPS - depends on the proxy setup, but either is basically fine)
client sends "CONNECT remote-server.example:443" to the proxy server
The proxy server connects to that address
The proxy server responds to client with 200 OK, and then all future bytes are passed raw between client & the remote server
*/
// https://stackoverflow.com/questions/18340414/what-should-i-do-with-a-connect-event
const net = require('net');
const http = require('http');
@fawazahmed0
fawazahmed0 / cloudflare-tld-price-list.csv
Last active November 19, 2025 03:11
cloudflare domains price list for tlds
TLD Registration Fees Renewal Fees
example.org.uk 4.94 4.94
example.uk 4.94 4.94
example.me.uk 4.94 4.94
example.co.uk 4.94 4.94
example.date 4.16 5.16
example.trade 4.16 5.16
example.party 4.16 5.16
example.bid 4.16 5.16
example.stream 4.16 5.16
@fawazahmed0
fawazahmed0 / save-mhtml.js
Created April 13, 2024 21:19
save mhtml in playwright
const { chromium } = require('playwright');
const fs = require('node:fs/promises');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://playwright.dev/');
const session = await context.newCDPSession(page)
const {data:mhtmlData} = await session.send('Page.captureSnapshot')
await fs.writeFile('./mynewmhtml.mhtml', mhtmlData)
@fawazahmed0
fawazahmed0 / getPublicRandom.js
Last active March 4, 2024 09:00
Rejection sampling random number
// https://drand.love/blog/2023/02/22/how-to-use-drand/
// https://research.kudelskisecurity.com/2020/07/28/the-definitive-guide-to-modulo-bias-and-how-to-avoid-it
// https://go.dev/src/crypto/rand/util.go
// https://go.dev/src/crypto/rand/util.go
//follows rejection sampling
function getPublicRandom(max, randomHexString){
if(max<=0)
throw "max cannot be <=0"
@fawazahmed0
fawazahmed0 / countries-with-iso-datetime.json
Last active September 20, 2024 11:43
Countries with ISO datetime format
{
"af": {
"country_name": "afghanistan",
"country_iso3": "afg",
"country_iso_numeric": "4",
"currency_name": "afghani",
"currency_code": "afn",
"currency_number": "971"
},
"sv": {
const { firefox } = require('playwright');
const path = require('path')
const fs = require('fs/promises')
async function begin(){
let filename = 'myzip.7z'
const browser = await firefox.launch({headless:true});
const page = await browser.newPage();
await page.goto('https://gofile.io/d/bsgS8S');
const fs = require('node:fs/promises')
const path = require('path')
let pathToDir = path.join(__dirname, 'src')
let pathToDest = path.join(__dirname, 'dst')
async function begin(){
await fs.mkdir(pathToDest, {recursive:true})
@fawazahmed0
fawazahmed0 / arabicdiacriticsremove.js
Last active November 21, 2022 23:49
Remove Arabic diacritics & other things for searching
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
// https://unicode.org/reports/tr18/#General_Category_Property
// https://unicode.org/reports/tr24/#Script
// https://tc39.es/ecma262/multipage/text-processing.html#table-nonbinary-unicode-properties
// \p{Symbol} also includes pipe symbol i.e | etc
let str = "ٱلَّذِينَ يُؤۡمِنُونَ بِٱلۡغَيۡبِ وَيُقِيمُونَ ٱلصَّلَوٰةَ وَمِمَّا رَزَقۡنَٰهُمۡ يُنفِقُونَ"
str = str.normalize("NFD").replace(/\p{Diacritic}|\p{Mark}|\p{Extender}|\p{Bidi_Control}/gu, "").replaceAll('ٱ','ا')
console.log(str)
const { chromium } = require('playwright');
async function begin(){
let links = ["https://www.scholarify.in/teaching-concept-objectives-characteristics-levels/","https://www.scholarify.in/learners-characteristics/","https://www.scholarify.in/factors-affecting-teaching/","https://www.scholarify.in/teaching-methods/","https://www.scholarify.in/teacher-centred-and-learner-centred-methods/","https://www.scholarify.in/offline-vs-online-methods/","https://www.scholarify.in/swayam/","https://www.scholarify.in/swayam-prabha/","https://www.scholarify.in/massive-open-online-courses-moocs/","https://www.scholarify.in/teaching-support-system/","https://www.scholarify.in/evaluation-systems/","https://www.scholarify.in/choice-based-credit-system-cbcs/","https://www.scholarify.in/computer-based-test-cbt/","https://www.scholarify.in/innovations-in-evaluation-systems/","https://www.scholarify.in/research-meaning-types-characteristics/","https://www.scholarify.in/research-methods/","https://www.scholarify.in/steps-resear