Skip to content

Instantly share code, notes, and snippets.

View islahh's full-sized avatar

Islah Mohammad Musleh islahh

  • Forest Interactive
  • Kuala Lumpur Malaysia
  • 08:37 (UTC -12:00)
View GitHub Profile
@islahh
islahh / sql-query.sql
Last active September 17, 2023 09:52
SQL query Knowledge
# Using SQL Len function
select patient_id, first_name from patients
where first_name like "s%" AND first_name like "%s"
AND len(first_name) >= 6;
# Using count
select first_name from patients
group by first_name
having count(first_name)=1;
@islahh
islahh / user.storage.ts
Created April 8, 2023 08:01
Create async local storage using node JS async_hooks in NestJS
// user.storage.ts
import { AsyncLocalStorage } from 'async_hooks';
export interface User {
id: string;
}
export const UserStorage = {
storage: new AsyncLocalStorage<User>(),
get() {
@islahh
islahh / cmd.sh
Created December 30, 2021 04:29 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
Truncate a number to a fixed decimal point
Using the Math.pow() method, we can truncate a number to a certain decimal point that we provide in the function.
Ex.
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed);
// Examples
toFixed(25.198726354, 1); // 25.1
toFixed(25.198726354, 2); // 25.19
toFixed(25.198726354, 3); // 25.198
@islahh
islahh / queue.js
Created September 27, 2020 04:31 — forked from deleteman/queue.js
class Queue {
data = []
maxSize
constructor(initialData, maxSize = -1) {
this.data = Array.isArray(initialData) ? initialData : (typeof initialData == "undefined" ? [] : [initialData])
this.maxSize = maxSize
}
isFull() {
sudo kill $(sudo lsof -t -i:3000)
@islahh
islahh / url-segment.js
Created September 22, 2020 07:20 — forked from jserrao/url-segment.js
Get Last Segment of a URL in Javascript
var pageURL = window.location.href;
var lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
console.log(lastURLSegment);
@islahh
islahh / lumen_in_subfolder.md
Created September 22, 2020 04:40 — forked from dbaeck/lumen_in_subfolder.md
Howto deploy Lumen projects within a subfolder (on a shared hoster)

Howto deploy Lumen projects within a subfolder (on a shared hoster)

For Lumen (5.0.8) (Laravel Components 5.0.*)

Use Case: Deploying Lumen App to Shared Hoster such that it can be called via domain.tld/lumenapp/...

Folder Layout

  • Rename public to desired name (new root folder, for example lumenapp)
  • Move everything else into a new folder, named e.g. project_src
@islahh
islahh / render_image_from_binary
Last active September 23, 2019 02:40
How to render image from binary data in the browser
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Rendering image in brower from binary data</title>
</head>
<body>
<h1>Test</h1>
// Syntax: src="data:image/png;base64, image_binary_data"
# How to find my DB version and other destails, run the following sql
SHOW VARIABLES LIKE "%version%";