This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. cd /usr/local/etc/rc.d | |
ln -s openvpn openvpn_voip | |
2. /etc/rc.conf | |
openvpn_enable="YES" | |
openvpn_configfile="/usr/local/etc/openvpn/openvpn.conf" | |
openvpn_voip_enable="YES" | |
openvpn_voip_configfile="/usr/local/etc/openvpn/gw.conf" | |
3.service openvpn restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LOCALE_MAP: Record<string, string> = { | |
RUB: 'ru-RU', | |
USD: 'en-US', | |
EUR: 'de-DE', | |
}; | |
export function formatCurrency(amount: number, currencyCode: string): string { | |
const locale = LOCALE_MAP[currencyCode] || 'ru-RU'; | |
const formattedAmount = new Intl.NumberFormat(locale, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const convertToISO = (date: string, time: string, zone: string): string => { | |
const [day, month, year] = date.split('.').map(Number); | |
const [hour, minute] = time.split(':').map(Number); | |
const dateTime = DateTime.fromObject({ year, month, day, hour, minute }, { zone }); | |
const utcDateTime = dateTime.toUTC(); | |
return utcDateTime.toISO(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ObjectWithNewProp<T, K extends string, V> = T & {[NK in K]: V}; | |
export class ObjectManipulator<T> { | |
constructor(protected obj: T) {} | |
public set<K extends string, V>(key: K, value: V): ObjectManipulator<ObjectWithNewProp<T, K, V>> { | |
return new ObjectManipulator({...this.obj, [key]: value} as ObjectWithNewProp<T, K, V>); | |
} | |
public get<K extends keyof T>(key: K): T[K] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toFunctional<T extends Function>(func: T): Function { | |
const fullArgCount = func.length; | |
function createSubFunction(curriedArgs: unknown[]) { | |
return function(this: unknown) { | |
const newCurriedArguments = curriedArgs.concat(Array.from(arguments)); | |
if (newCurriedArguments.length > fullArgCount) { | |
throw new Error('Too many arguments'); | |
} | |
if (newCurriedArguments.length === fullArgCount) { | |
return func.apply(this, newCurriedArguments); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Comparator<T> = (a: T, b: T) => number; | |
type GetIndex = <T>(input: T[], comparator: Comparator<T>) => number; | |
export const getMaxIndex: GetIndex; | |
export const getMinIndex: GetIndex; | |
export const getMedianIndex: GetIndex; | |
type GetElement = <T>(input: T[], comparator: Comparator<T>) => T | null; | |
export const getMaxElement: GetElement; | |
export const getMinElement: GetElement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'str-utils' { | |
type StrUtil = (input: string) => string; | |
export const strReverse: StrUtil; | |
export const strToLower: StrUtil; | |
export const strToUpper: StrUtil; | |
export const strRandomize: StrUtil; | |
export const strInvertCase: StrUtil; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CallbackBasedAsyncFunction<T> = (callback: (response: ApiResponse<T>) => void) => void; | |
type PromiseBasedAsyncFunction<T> = () => Promise<T>; | |
export function promisify<T>(fn: CallbackBasedAsyncFunction<T>): PromiseBasedAsyncFunction<T> { | |
return () => new Promise<T>((resolve, reject) => { | |
fn((response) => { | |
if (response.status === 'success') { | |
resolve(response.data); | |
} else { | |
reject(new Error(response.error)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getObjectKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[]; | |
export function filterPersons(persons: Person[], personType: User['type'], criteria: Partial<Omit<User, 'type'>>): User[]; | |
export function filterPersons(persons: Person[], personType: Admin['type'], criteria: Partial<Omit<Admin, 'type'>>): Admin[]; | |
export function filterPersons(persons: Person[], personType: Person['type'], criteria: Partial<Person>): Person[] { | |
return persons | |
.filter((person) => person.type === personType) | |
.filter((person) => { | |
let criteriaKeys = getObjectKeys(criteria); | |
return criteriaKeys.every((fieldName) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
type: 'user'; | |
name: string; | |
age: number; | |
occupation: string; | |
} | |
interface Admin { | |
type: 'admin'; | |
name: string; |
NewerOlder