Skip to content

Instantly share code, notes, and snippets.

View UladRH's full-sized avatar

Uladzislau R. Hlebovich UladRH

  • Poland
View GitHub Profile
import { ControlValueAccessor } from '@angular/forms';
export abstract class SimpleControlValueAccessor<T>
implements ControlValueAccessor
{
value: T | null = null;
disabled = false;
onChange: (_: any) => void = (_: any) => {};
onTouched: () => void = () => {};
export function makeComparatorFromSequence<T extends any, K = string | number>(
sequence: K[],
iteratee: keyof T | K | ((value: T) => K)
): (a: T, b: T) => number;
export function makeComparatorFromSequence<T extends string | number>(
sequence: T[]
): (a: T, b: T) => number;
/**
@UladRH
UladRH / forInnerArray.ts
Created September 10, 2021 15:15
#rxjs
import {
merge,
mergeMap,
Observable,
OperatorFunction,
partition,
toArray,
} from 'rxjs';
import { fromArrayLike } from 'rxjs/internal/observable/from';
EXPLAIN ANALYZE
SELECT p.text,
pl.post_id IS NOT NULL AS liked,
pf.profile_id IS NOT NULL AS followed
FROM posts p
LEFT JOIN profiles a
ON a.id = p.author_id
LEFT JOIN posts_likes pl
ON pl.post_id = p.id
AND pl.profile_id = :viewer_id
import Ecto.Query
defmodule Profile do
use Ecto.Schema
schema "profiles" do
field :username, :string
field :followed, :boolean, virtual: true
end
package com.example.JSP;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class MyMatrix {
private int[][] mat;
@UladRH
UladRH / Book.java
Last active April 5, 2021 14:07
BookStore JSF
import java.io.Serializable;
public class Book implements Serializable {
private final int id;
private String title;
private String author;
private String publisher;
private int year;
private int pagesCount;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class SelectionSort {
public static <T> void sort(List<T> a, Comparator<T> c) {
for (int min = 0; min < a.size() - 1; min++) {
int least = min;
for (int j = min + 1; j < a.size(); j++) {
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
import { NamingStrategyInterface, Table } from 'typeorm';
export class OrmNamingStrategy extends SnakeNamingStrategy implements NamingStrategyInterface {
primaryKeyName(tableOrName: Table | string, columnNames: string[]) {
const table = tableOrName instanceof Table ? tableOrName.name : tableOrName;
return `${table}_pk`;
}
import { QueryFailedError } from 'typeorm';
export class PgError extends Error {
public type: PgErrorTypes;
public column?: string;
constructor(e: { type: PgErrorTypes; column?: string }) {
super('PostgresQL Error');
this.type = e.type;