Skip to content

Instantly share code, notes, and snippets.

View heffcodex's full-sized avatar
⚒️
Arbeiten

Vladislav Kolesnichenko heffcodex

⚒️
Arbeiten
View GitHub Profile
(?is)(?P<prefix>^|[\s\p{P}\p{S}])(?P<match>(https?://)?([a-zа-я0-9_-]+\.)+(xn--)?[a-zа-я0-9]{2,}(/[a-z0-9/%@._~+-]*)?(\?[a-z0-9/%@&\[\];_=+-]*)?(#[a-z0-9/%@&\[\];_=+-]*)?)(?P<suffix>[\s\P{L}]|$)
@heffcodex
heffcodex / yturl.js
Created December 9, 2022 21:02
Get YouTube URL containing canonical channel ID JS function suitable for bookmarklet
((w) => {
const urlPrefix = "https://www.youtube.com/";
const href = w.location.href;
if (!href.startsWith(urlPrefix)) {
alert("wrong page");
return;
}
fetch(href)
.then((res) => res.text())
func EscapeMarkdownV2(text string) string {
escapeChars := "_*[]()~`>#+-=|{}.!"
return regexp.MustCompile(fmt.Sprintf("([%s])", regexp.QuoteMeta(escapeChars))).ReplaceAllString(text, "\\$1")
}
@heffcodex
heffcodex / Makefile
Created May 9, 2020 17:31
Multi-arch generic makefile for go
DIR = ./.build
EXECUTABLE = app
GOARCH = amd64
GOOSWIN = windows
GOOSX = darwin
GOOSLINUX = linux
GOMOD = on
CGO_ENABLED = 0
<code_scheme name="Must Have" version="173">
<option name="LINE_SEPARATOR" value="&#xA;" />
<option name="FORMATTER_TAGS_ENABLED" value="true" />
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />
</MarkdownNavigatorCodeStyleSettings>
<PHPCodeStyleSettings>
<option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" />
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
<option name="PHPDOC_BLANK_LINE_BEFORE_TAGS" value="true" />
@heffcodex
heffcodex / Dockerfile
Created April 7, 2019 00:16
Pretty bash prompt for docker image
RUN touch ~/.bashrc \
&& echo "export PATH=${PATH}:/var/www/vendor/bin" >> ~/.bashrc \
&& echo "PS1='\[\033[1;36m\]\h \[\033[1;34m\]\W\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'" >> ~/.bashrc
import sys
class TxtProgress:
_tpl = ""
def __init__(self, template):
self._tpl = template
def _syswrite(self, string):
@heffcodex
heffcodex / schema.sql
Created November 7, 2018 15:59
SQL Magic
CREATE TABLE IF NOT EXISTS `clicks` (
`id` int primary key not null auto_increment,
`login` varchar(20) NOT NULL,
`button` varchar(20) NOT NULL,
`dt` datetime not null
) DEFAULT CHARSET=utf8;
INSERT INTO `clicks` (`login`, `button`, `dt`) VALUES
('Alice', 'blue', NOW()),
('Alice', 'red', NOW() - INTERVAL 1 DAY),
@heffcodex
heffcodex / chinese_symgen.py
Created October 27, 2018 21:02
Generate some chinese "words"
import io, random, argparse, time
# N words by CHARS length
def main():
argp = argparse.ArgumentParser()
argp.add_argument('N', metavar='N', type=int)
argp.add_argument('CHARS', metavar='CHARS', type=int)
args = argp.parse_args()
@heffcodex
heffcodex / array2tree_converter.php
Created October 27, 2018 20:44
Converts flat array into tree, avoiding the necromancy with references in PHP
<?php
class Array2Tree
{
public static function convert(array $data)
{
$instance = new self($data);
return $instance->getTree();
}