Skip to content

Instantly share code, notes, and snippets.

View hassansw's full-sized avatar
🎯
Focusing

Hassan Saleem hassansw

🎯
Focusing
View GitHub Profile

Global state management in React can be a foreign concept for new programmers. Over the years, we have met reducers, action types, atoms, etc. I have a friend that wants to learn web development, and I imagine it would be very difficult to teach him about these concepts.

zustand is a simple, straightforward, and un-opinionated library for global state management. Because of those traits, I am able to utilize it to manage global state like normal JavaScript thing. What I mean by "normal JavaScript thing" is there is no foreign concept involved in here. It's just a bunch of normal variables, normal functions, and occasionally normal React component. I hope my friend can understand global state management better and faster with this library.

@hassansw
hassansw / dec-price.directive.ts
Last active June 14, 2021 12:25
Update NgModel value using/from Directive Angular | Angular 2
import {
Directive,
HostListener,
ElementRef
} from '@angular/core';
import { NgControl, NgModel } from '@angular/forms';
import { Subscription } from 'rxjs';
@Directive({
selector: '[myDirective]'
@hassansw
hassansw / index.html
Created February 19, 2020 05:41 — forked from ThomasG77/index.html
Simple OpenLayers Reverse Geocoding sample with Nominatim
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=description content="">
<meta name=viewport content="width=device-width, initial-scale=1">
<title>Reverse geocoding</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.4.2/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,fetch"></script>
@hassansw
hassansw / emptyHtmlStringCheck.js
Created June 19, 2019 11:21
Check if an html string has text or not (for html editors)
fucntion isEmpty(htmlString) {
if (htmlString) {
const parser = new DOMParser();
const { textContent } = parser.parseFromString(htmlString, "text/html").documentElement;
return !textContent.trim();
} else {
return true;
}
};
@hassansw
hassansw / numberSorter.js
Created March 6, 2019 06:43
Order number to descending or ascending order
function descendingOrder(n){
const newArr = (n).toString(10).split("").map(Number);
return parseInt(newArr.sort(function (a, b) { return b - a }).join("")) // replace (b-a) to (a-b) for ascending order
}
findShort(s) {
try {
return Math.min(...s.split(' ').map(o => o.length));
} catch (error) {
return null
}
}
A. Create Installation DVD ISO Via Dism:
1. Extract Win 10 Enterprise version of the mirror sources folder install.wim to D drive temp directory
2. In the temp directory to create WimMount folder, and execute the following command to mount the wim file
Dism /Mount-Wim /WimFile:D:\temp\install.wim /Index:1 /MountDir:D:\temp\WimMount
3. Show the current version
Dism /Image:D:\temp\WimMount /Get-CurrentEdition
4. Show current version
Dism /Image:D:\temp\WimMount /Get-TargetEditions
@hassansw
hassansw / check-duplicate.js
Created December 4, 2018 14:13
Find Duplicate objects in an Array of Objects in Javascript
function checkDuplicateInObject(propertyName, inputArray) {
let seenDuplicate = false, testObject = {};
let dupItem = null
inputArray.map((item) => {
const itemPropertyName = item[propertyName];
if (itemPropertyName in testObject) {
testObject[itemPropertyName].duplicate = true;
item.duplicate = true;
seenDuplicate = true;
@hassansw
hassansw / alphabet-soup.markdown
Created November 5, 2018 10:00
Alphabet Soup
@hassansw
hassansw / cookies.injectable.ts
Created July 4, 2018 09:05
Cookies Injectable
import { Injectable } from '@angular/core';
@Injectable()
export class CookieService {
constructor() { }
public getCookie(name: string): any | null {
let ca: Array<string> = document.cookie.split(';');
let caLen: number = ca.length;