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;
@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"
[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
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) {
<?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) {
@thybzi
thybzi / test.js
Created July 20, 2018 14:30
async/await & class
class Test {
constructor() {
this.processData({}).then((data) => {
console.log(data);
})
}
async processData(data) {
data = await this.one(data);
@thybzi
thybzi / getTransitionendEvent.js
Created July 7, 2018 11:40
Not tested in older browsers
function getTransitionendEventName() {
if ('ontransitionend' in window) {
// Firefox 16+, IE 10+, Chrome 26+, Opera 12.1+, Safari 6.1+
return 'transitionend';
} else if ('onwebkittransitionend' in window) {
// Chrome 4+, Safari 3.1+
return 'webkitTransitionEnd';
} else if ('onmoztransitionend' in window) {
// Firefox 4+
return 'mozTransitionEnd';