Skip to content

Instantly share code, notes, and snippets.

View thybzi's full-sized avatar

Evgeni Dmitriev thybzi

View GitHub Profile
/**
* Convert #1a2b3c to { r: 26, g: 43, b: 60 }
* @param {string} hex
* @returns {*}
* @see https://stackoverflow.com/a/5624139
*/
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
/**
* Convert #1a2b3c to { h: 210, g: 40, b: 17 }
* @param {string} hex
* @returns {*}
* @see https://stackoverflow.com/q/46432335/3027390
* @see https://stackoverflow.com/a/46432866/3027390
*/
function hexToHsl(hex) {
const rgb = _f.hexToRgb(hex);
const r = rgb.r / 255;
<?php
ini_set('user_agent', 'ThybziDiscogsClient/1.1 +http://thybzi.com/wishlist');
define('BASE_URI', 'https://api.discogs.com/');
define('API_TOKEN', 'YOUR_TOKEN_HERE'); // get one on https://www.discogs.com/settings/developers
define('CACHE_DIR', __DIR__ . '/../cache/');
define('CACHE_LIFE', 24 * 60 * 60);
define('PER_PAGE', 100);
function getUriContent($uri) {
[user]
name = John Smith
email = jsmith@example.com
[color]
ui = auto
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
co = checkout
[push]
default = tracking
@thybzi
thybzi / Gemfile
Created May 8, 2021 10:38
Gemfile for github pages
source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
# gem "jekyll", "~> 4.2.0"
function _patchFs() {
if (fs.hasOwnProperty('_mockedFiles')) {
return;
}
fs._readFileReal = fs.readFile;
fs._mockedFiles = {};
fs.mockFile = function(filePath, fileContent) {
fs._mockedFiles[filePath] = fileContent;
};
fs.readFile = function(filePath, cb) {
/**
* @param {string} url
* @returns {Promise<string>}
* @private
*/
async function _fetchRemote(url) {
const http = /^https:/.test(url) ? require('https') : require('http');
return new Promise((resolve, reject) => {
http.get(url, res => {
res.setEncoding('utf8');
/**
* Convert cli-style arguments to reasonable key-value hashmap object
* @param {string[]} args Raw cli args
* @param {boolean} dropFirstTwo Useful for nodejs (drops two leading args)
* @returns Object<string|number|boolean>
* @example
* yargify(['--foo=bar', '--qux="hello world", '--fred', '-x=42', '-y=false'])
* // => {foo: 'bar', qux: 'hello world', fred: true, x: 42, y: false}
*/
function yargify(args, dropFirstTwo=true) {
@thybzi
thybzi / tpl2.js
Last active April 1, 2019 09:05
The second lightest JS template engine! (And still so unsafe one)
/**
* The second lightest JS template engine! (And still so unsafe one)
* Only replaces variables inside {{ }} (HTML-escaped) and {{{ }}} (unescaped)
* Second lightest after the original https://gist.github.com/thybzi/1e46eb8b23c11d55752ae4ac89a1cd13
* @param {string} template
* @param {object} data
* @returns {string}
* @example
* tpl2(
* '<div class="{{ classname }}">{{{ item.content }}}</div>',
@thybzi
thybzi / tpl.js
Last active April 1, 2019 09:05
The lightest JS template engine ever! (And the most unsafe one)
/**
* The lightest JS template engine ever! (And the most unsafe one)
* Only replaces variables inside {{ }} (without any escaping)
* @param {string} template
* @param {object} data
* @example
* tpl(
* '<div class="{{ classname }}">{{item.title}}</div>',
* { classname: 'ololo', item: { ad: 'zzz', title: 'afffa!!bazinga' } }
* );