Skip to content

Instantly share code, notes, and snippets.

View space11's full-sized avatar
🐧

Borys space11

🐧
View GitHub Profile
@space11
space11 / sanitize.ts
Created September 4, 2023 21:47
Sanitizes input data to mitigate potential security risks by removing or escaping special characters, HTML entities, Unicode characters, and null bytes.
/**
* Sanitizes input data to mitigate potential security risks by removing or escaping
* special characters, HTML entities, Unicode characters, and null bytes.
*
* @param input The input data to be sanitized.
* @returns A sanitized version of the input data.
*/
function sanitizeData(input: string): string {
/**
* Removes carriage return characters (\r).
@space11
space11 / random.helpers.ts
Created August 15, 2023 18:02
Generates random number of digits of given length.
function generateRandomNumber(length: number): number {
return parseInt(
Math.ceil(Math.random() * Date.now())
.toPrecision(length)
.toString()
.replace('.', ''),
10
);
}
@space11
space11 / log.pipe.ts
Last active October 16, 2023 16:07
Angular pipe that logs to the console template variable.
import { Pipe, PipeTransform } from '@angular/core';
/**
* Log pipe is used for debugging purposes allows quickly log to the console a template value.
*
* @example
* <!-- Log value to a console. -->
* <div>
* {{ foo.value | log }}
* </div>
*/
@space11
space11 / is-authenticated.directive.ts
Created June 15, 2023 07:02
Angular Structural Directive - Hide element base on condition
import {
Directive,
TemplateRef,
ViewContainerRef,
OnInit,
} from "@angular/core";
import { AuthService } from "./auth.service";
@Directive({
selector: "[isAuthenticated]",
@space11
space11 / app.module.ts
Created April 20, 2023 13:30 — forked from harbirchahal/app.module.ts
Request Timeout HTTP Interceptor (Header)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RequestTimeoutHttpInterceptor, DEFAULT_TIMEOUT } from './interceptors';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
@space11
space11 / find-users-duplicate-email.sql
Created February 23, 2023 08:46
Find users with the same email address
-- Find users ID that have the same email address
SELECT u.id FROM `user` AS u
INNER JOIN
(
SELECT email FROM `user`
GROUP BY `user`.email HAVING count(id) > 1
) AS u2 ON u2.email = u.email;
@space11
space11 / only-number.directive.md
Created February 7, 2023 14:11 — forked from ahmeti/only-number.directive.md
Angular 5 - Only Number Input, Only Number Decimal
@space11
space11 / index.js
Created January 19, 2023 12:20
Get Angular root elements in the browser.
window.getAllAngularRootElements()
@space11
space11 / privatekey_single_line.md
Created December 25, 2022 21:47
How to convert privatekey into singleline

Credit to: https://www.kevinsimper.dk/posts/how-to-convert-privatekey-into-singleline

Sometimes you need to convert a file with newlines into a singleline, essentially turning newline characters into newline "\n", but that can be pretty difficult as most programs turns that into a actual newline, which is difficult to copy.

But using awk we can turn a file into a single line of text, perfect for a environment variable. However, remember that privatekeys shouldn't be stored in the environment for security reasons, it should live as a file.

$ awk -v ORS='\\n' '1' karnov-review.2019-01-21.private-key.pem | pbcopy

alias pbcopy='xclip -selection clipboard'

@space11
space11 / email-regexp.md
Created November 23, 2022 10:13
Mail::RFC822::Address: regexp-based address validation

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

`(?:(?:\r\n)?[ \t])(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^\"\r\\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?: \r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^\"\r\\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t])))@(?:(?:\r\n)?[ \t])(?:[^]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^\[\]\r\\]|\.)
](?:(?:\r\n)?[ \t])
)(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\\".\[\] \000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^\[\]\r\\]|\.)](?: