Skip to content

Instantly share code, notes, and snippets.

View orion55's full-sized avatar

Orion55 orion55

  • 16:49 (UTC +05:00)
View GitHub Profile
@orion55
orion55 / openvpn.sh
Created May 2, 2025 12:18
2 OpenVPN tunnels
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
@orion55
orion55 / formatCurrency.ts
Created December 13, 2024 12:55
formatCurrency
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, {
@orion55
orion55 / date.ts
Created April 22, 2024 06:54
Преобразование даты в нужной тайм-зоне в зону UTC и формат ISO
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();
};
@orion55
orion55 / index.ts
Created August 28, 2023 05:46
ObjectManipulator
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] {
@orion55
orion55 / index.d.ts
Created August 28, 2023 05:30
toFunctional
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);
@orion55
orion55 / index.d.ts
Created August 28, 2023 04:59
stats
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;
@orion55
orion55 / index.d.ts
Created August 28, 2023 04:38
str-utils
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;
}
@orion55
orion55 / promisify.ts
Created August 23, 2023 06:06
promisifyAll
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));
@orion55
orion55 / filterPersons01.ts
Created August 22, 2023 05:38
filterPersons01
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) => {
@orion55
orion55 / filterUsers.ts
Last active August 22, 2023 05:38
filterUsers
interface User {
type: 'user';
name: string;
age: number;
occupation: string;
}
interface Admin {
type: 'admin';
name: string;