Skip to content

Instantly share code, notes, and snippets.

View FFKL's full-sized avatar
🦔
This is The Hedgehog!

Dmitrii Korostelev FFKL

🦔
This is The Hedgehog!
View GitHub Profile
@FFKL
FFKL / simplejq.js
Created June 16, 2019 15:45
Simple jQuery
const $ = selector => new Proxy( document.querySelector(selector)||Element, { get: (target, key) => Reflect.get(target, key) } ) ;
Element.prototype.on = Element.prototype.addEventListener;
@FFKL
FFKL / start-app.sh
Last active December 22, 2019 22:34
Start node app using mongodb and pm2
#!/bin/bash
sudo mongod -f /etc/mongodb.conf --fork
pm2 start ecosystem.config.js
pm2 logs
@FFKL
FFKL / text-with-ellipsis.css
Created December 21, 2019 12:43
Hidden text with ellipsis ('text...')
div {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
@FFKL
FFKL / font-awesome-mixin.scss
Created December 22, 2019 22:45
FontAwesome icon mixin
@mixin font-awesome-icon($unicode, $font-size: 1rem, $line-height: 1) {
font-family: FontAwesome;
font-size: $font-size;
line-height: $line-height;
content: unquote("\"\\#{$unicode}\"");
display: inline-block;
}
@FFKL
FFKL / tslint-ordered-imports.json
Last active January 6, 2020 10:23
TSLint ordered-imports example
{
"ordered-imports": [
true,
{
"grouped-imports": true,
"import-sources-order": "any",
"named-imports-order": "case-insensitive",
"groups": [
{
"name": "third-party",
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { get } from 'lodash';
import { Subscription } from 'rxjs';
import { ToursCatalog } from 'package-types';
@Pipe({
name: 'departureCityLabel',
pure: false
@FFKL
FFKL / mixins.ts
Created January 16, 2020 19:18
Example of mixins usage.
type Constructor <T = {}> = new(...args: any[]) => T;
function Timestamped <TBase extends Constructor> (Base: TBase) {
return class extends Base {
timestamp = Date.now();
};
}
function Restorable <TBase extends Constructor> (Base: TBase) {
return class extends Base {
import { merge, Observable } from 'rxjs';
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
export function and(a: Observable<boolean>, b: Observable<boolean>): Observable<boolean> {
let res1: boolean = false;
let res2: boolean = false;
return merge(
a.pipe(tap((res: boolean) => res1 = res)),
b.pipe(tap((res: boolean) => res2 = res))
@FFKL
FFKL / fastest-validator-advanced-types.ts
Created March 6, 2020 20:06
Example of custom types for fastest-validator. Advanced auto completion.
interface ValidationTest {
arr: { haha: string } | { hoho: number }[];
obj: { oops: boolean };
str: string;
}
const schema: Validation<ValidationTest> = {
arr: { type: 'array', items: { type: 'object', props: { haha: { type: 'string' } } } },
obj: { type: 'object', props: { oops: { type: 'boolean' } } },
str: { type: 'string' }
@FFKL
FFKL / only-picked-type-fields.ts
Created March 6, 2020 20:18
This type is used to select the field names of the type (T) by the specified type (P).
type OnlyPickedTypeFields<T extends object, P> = { [K in keyof T]: T[K] extends P ? K : never }[keyof T];