Skip to content

Instantly share code, notes, and snippets.

View ashaffah's full-sized avatar
🎯
Focusing

Alt ashaffah

🎯
Focusing
  • bedroom
View GitHub Profile
<div style="position:absolute;top:-999px;left:-999px">
<svg
id="effectSvg"
width="200"
height="200"
viewBox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg">
<filter id="displacementFilter4">
@ashaffah
ashaffah / broadcast-channel.md
Created June 6, 2025 16:41 — forked from davestewart/broadcast-channel.md
Example of using BroadcastChannel to communicate with pages in the same domain

screenshot

@ashaffah
ashaffah / http-headers.util.js
Last active June 6, 2025 16:39
http headers combinator
/**
* @typedef {(
* "text/plain" |
* "text/html" |
* "text/css" |
* "text/javascript" |
* "application/javascript" |
* "application/json" |
* "application/xml" |
* "application/x-www-form-urlencoded" |
@ashaffah
ashaffah / BaseStation.java
Created May 28, 2025 21:45 — forked from eslamfaisal/BaseStation.java
An example to get cell towers info on Android
package com.mirrordust.gpscellinfodemo;
public class BaseStation {
private int mcc; // Mobile Country Code
private int mnc; // Mobile Network Code
private int lac; // Location Area Code or TAC(Tracking Area Code) for LTE
@ashaffah
ashaffah / indexing.rs
Created February 2, 2025 10:13
Rust mongodb driver auto indexing helper
use mongodb::{ bson::doc, options::IndexOptions, Collection, Database, IndexModel };
pub async fn auto_indexing_collection<T>(db: Database, key: Vec<String>, collection_name: String)
where T: serde::Serialize + serde::de::DeserializeOwned + Unpin + Send + Sync
{
let options = IndexOptions::builder().unique(true).build();
let collection: Collection<T> = db.collection(&collection_name);
for k in key {
let model = IndexModel::builder()
.keys(doc! { k : 1 })
@ashaffah
ashaffah / helpers.go
Created February 2, 2025 10:10
Golang Mongodb dynamic auto indexing
package helpers
import (
"context"
"log"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@ashaffah
ashaffah / App.tsx
Last active May 29, 2025 14:47
React Provider tree for provider hell
const ProvidersTree = BuildProvidersTree([
[ProviderOne],
[ProviderTwo],
[ProviderThree, {data:data}],
]);
function App(): React.JSX.Element {
// something else..
return (
<ProvidersTree />
@ashaffah
ashaffah / helper.ts
Last active March 20, 2025 03:09
object converter to formData
export const objectToFormData = (
obj: Record<string, any>,
form?: FormData,
namespace?: string,
): FormData => {
const formData = form || new FormData();
for (const property in obj) {
if (obj.hasOwnProperty(property)) {
const key = namespace ? `${namespace}[${property}]` : property;
@ashaffah
ashaffah / helper.rs
Created November 27, 2024 03:16
chrono_datetime_option_as_bson_datetime_option
pub mod chrono_datetime_option_as_bson_datetime_option {
use bson::{ Bson, DateTime };
use chrono::{ DateTime as ChronoDateTime, Utc };
use serde::{ Deserialize, Deserializer, Serialize, Serializer };
use std::result::Result;
use serde::de::Error;
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<ChronoDateTime<Utc>>, D::Error>
where D: Deserializer<'de>
{