Skip to content

Instantly share code, notes, and snippets.

View NoTimeForHero's full-sized avatar

NoTimeForHero

View GitHub Profile
@NoTimeForHero
NoTimeForHero / replace.ts
Created February 9, 2024 20:08
Замена функции в объекте с полной поддержкой типов
// https://stackoverflow.com/questions/49752151/typescript-keyof-returning-specific-type
type KeyOfType<T, V> = keyof {
[P in keyof T as T[P] extends V ? P : never]: any;
};
type InferArgs<TValueType> = TValueType extends (...args: infer U) => any ? U : never;
type InferReturn<TValueType> = TValueType extends (...args: any) => infer U ? U : never;
const replaceFunction = <
TArgs extends InferArgs<TObject[TKey]>,
TReturn extends InferReturn<TObject[TKey]>,
TCallable extends (...args: any) => any,
type PollingConfig = {
timeout?: number;
interval?: number;
initialTimeout?: number
};
type RequestFnResult <T> = { pending: true } | { data : T };
type Callback <T> = () => Promise<RequestFnResult<T>>;
export const TimeoutError = Symbol('TimeoutError!');
@NoTimeForHero
NoTimeForHero / entrypoint.sh
Created March 11, 2023 13:32
Run WebPack with primary service (like a php-fpm or rails puma)
#!/bin/bash
echo "Docker Entrypoint is called!"
cd /website
if [[ -f "/website/public/hot" ]]; then
echo "Removing HOT_RELOAD file"
rm /website/public/hot
fi
@NoTimeForHero
NoTimeForHero / application_record.rb
Created March 3, 2023 09:26
Реализация Bulk Insert для PostgreSQL в Rails 5
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.bulk_insert(data)
# @type [PG::Connection] conn
conn = self.connection.raw_connection
raise NotImplementedError.new 'Database Driver not supported!' unless conn.class.to_s == 'PG::Connection'
raise ArgumentError "Data not an Array of Hashes!" unless data.is_a?(Array) && data.all? {|rec| rec.is_a? Hash }
return nil unless data.count > 0
@NoTimeForHero
NoTimeForHero / atom.ts
Created December 26, 2022 22:24
React Simple Atom Storage
// import { useEffect, useState } from 'react';
import { useEffect, useState } from 'preact/compat';
interface Atom<T> {
key: Symbol
}
interface StoreValue {
value: any,
listeners: Set<() => void>
}
@NoTimeForHero
NoTimeForHero / publish.ps1
Created April 10, 2022 00:30
Создание ZIP архива из проекта Visual Studio без лишнего мусора
$projectName = Get-ChildItem .\ -Filter "*.sln" | Select-Object -ExpandProperty Name
if (!$projectName) {
Write-Host "Not found any *.SLN files in current directory!"
Write-Host "Exit with error..."
exit
}
$projectName = [io.path]::GetFileNameWithoutExtension($projectName)
$targetZip = $projectName + ".zip"
@NoTimeForHero
NoTimeForHero / utils.js
Created November 26, 2019 22:44
Discord.JS function to get users IDS as array from any mention in message (@here/@everyone/@groupName/@userName)
const Utils = {
findUsersByMessage(ev) {
const findUsers = ev => {
const regExMention = /<@(\d+)>/g;
const users = [...ev.content.matchAll(regExMention)];
return users.map(x => x[1]);
}
const findGroups = ev => {
const regExMention = /<@&(\d+)>/g;
const groupsIds = [...ev.content.matchAll(regExMention)].map(x => x[1]);
@NoTimeForHero
NoTimeForHero / convert_line_endings.js
Created July 23, 2019 11:19
Script to recursive change file line endings (from CLRF to LR)
const commander = require('commander');
const colors = require('colors');
const replace = require('replace-in-file');
const fs = require('fs');
const util = require('util');
let path = null;
commander
.version('0.1.0')
@NoTimeForHero
NoTimeForHero / index.js
Created July 10, 2019 17:47
NodeJS script to remove 1000 DNS records added by Cloudflare when used * (wildcard) A record
// Now if you adding a domain with wildcard A record, Cloudflare uses strange scan, which added a 1000 trash domains (like 1-100, some english words like "ai", "air", "android").
// There's no way to bulk delete it, you can delete it only using their API.
// So I write a script that can help you with this problem.
// Discussions about same problem:
// https://community.cloudflare.com/t/delete-all-records-using-api/13410/2
// https://community.cloudflare.com/t/bulk-delete-dns-record/89540
const settings = {
email: 'your@email',
@NoTimeForHero
NoTimeForHero / index.html
Last active July 2, 2019 14:48
Загрузчик однофайловых Vue компонентов, работающий в IE10 (с Promise полифиллом)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IE10 Compatibility Vue SFC Loader</title>
<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
<script src="https://unpkg.com/promise-polyfill@8.1.3/dist/polyfill.min.js"></script>
</head>
<body>