Skip to content

Instantly share code, notes, and snippets.

View NoTimeForHero's full-sized avatar

NoTimeForHero

View GitHub Profile
@NoTimeForHero
NoTimeForHero / config.php
Last active June 6, 2018 23:01
Simple website with 2 languages (using Twig, Phroute, php Gettext library)
<?php
require dirname(__FILE__). '/vendor/autoload.php';
use Gettext\Translator;
use Gettext\Translations;
$tplDir = dirname(__FILE__).'/templates/';
$tmpDir = dirname(__FILE__).'/tmp/cache/';
$loader = new Twig_Loader_Filesystem($tplDir);
@NoTimeForHero
NoTimeForHero / client_lib.cpp
Created September 23, 2018 19:03
Crazy Code
// TODO: Refactor this file
// It looks like a codegenerated crazy boilerplate code.
#define _HB_API_INTERNAL_ 1
#include <hbapi.h>
#include <hbapierr.h>
#include <hbstack.h>
#include <windows.h>
#include <hbapiitm.h>
@NoTimeForHero
NoTimeForHero / overlay.cpp
Last active May 19, 2019 21:18
Semi-transparent overlay to show user that window is blocked
#include <windows.h>
#include <hbapi.h>
#include <vector>
#include <map>
#include <cstdlib>
typedef std::vector<HWND> HWND_ARRAY;
std::map<HWND, HWND_ARRAY*> arrOverlays;
std::map<HWND, HBRUSH> overlaysBrushes;
@NoTimeForHero
NoTimeForHero / client.js
Created May 30, 2019 14:09
Simple Hot-Reload server
const hotReload = (address, options = {}) => {
// Константы
const CONST_RELOAD_MESSAGE = 'HOT_RELOAD_NOW';
// Настройки
const reconnect_timeout = options.reconnect_timeout || 500;
const reconnect_tries = options.reconnect_tries || 5;
// Локальные переменные
let socket = null;
let current_tries = 0;
@NoTimeForHero
NoTimeForHero / xpath.js
Created June 20, 2019 22:51
Сниппет для получения простого селектора XPATH по аналогии с querySelectorAll
document.xpathSelectorAll = (selector) => {
const nodes = document.evaluate(selector, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
return Array(nodes.snapshotLength).fill(1).map((x, id) => nodes.snapshotItem(id));
}
@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/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/polyfill.min.js"></script>
</head>
<body>
@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 / 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 / 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 / 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"