Skip to content

Instantly share code, notes, and snippets.

Evgeni Dmitriev thybzi

Block or report user

Report or block thybzi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View yargify.js
/**
* 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 Apr 1, 2019
The second lightest JS template engine! (And still so unsafe one)
View tpl2.js
/**
* 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 Apr 1, 2019
The lightest JS template engine ever! (And the most unsafe one)
View tpl.js
/**
* 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' } }
* );
View discogs.php
<?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 Jul 20, 2018
async/await & class
View test.js
class Test {
constructor() {
this.processData({}).then((data) => {
console.log(data);
})
}
async processData(data) {
data = await this.one(data);
@thybzi
thybzi / getTransitionendEvent.js
Created Jul 7, 2018
Not tested in older browsers
View getTransitionendEvent.js
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';
View idle-refresh.js
(function() {
window.lastActivityTime = 0;
window.refreshInterval = 10000;
window.idleInterval = 60000;
resetRefreshTimer();
document.body.addEventListener('mousemove', resetRefreshTimer);
document.body.addEventListener('keypress', resetRefreshTimer);
setTimeout(refresh, window.refreshInterval);
View less-import-tree.js
// usage: node less-import-tree.js myfile.less
// change dirPath to whatever you need
var args = process.argv.slice(2);
var path = require('path');
var progeny = require('progeny');
var dirPath = 'resources/less';
var fileName = args[0];
var filePath = path.join(dirPath, fileName);
@thybzi
thybzi / resize-svg-path.js
Created Oct 27, 2016
Resize SVG path to 512px height (e.g. for better usage with grunt-webfont)
View resize-svg-path.js
#! /usr/bin/env node
// Usage: node resize-svg-path <currentHeight> <currentPath>
// E.g.: node resize-svg-path 32 "m0,16c0,-8.83656 7.16345,-16 16,-16c8.83655,0 16,7.16344 16,16c0,8.83656 -7.16345,16 -16,16c-8.83655,0 -16,-7.16344 -16,-16zm30,0c0,-7.73198 -6.26801,-14 -14,-14c-7.73199,0 -14,6.26802 -14,14c0,7.73198 6.26801,14 14,14c7.73199,0 14,-6.26802 14,-14zm-14,-1.41422l-3.53552,-3.53554l-1.41425,1.41422l3.53558,3.53554l-3.53558,3.53554l1.41425,1.41422l3.53552,-3.53554l3.53552,3.53554l1.41425,-1.41422l-3.53558,-3.53554l3.53558,-3.53554l-1.41425,-1.41422l-3.53552,3.53554z"
(function () {
'use strict';
// Read command line arguments
var args = process.argv.slice(2);
var parse = require('parse-svg-path');
var scale = require('scale-svg-path');
View createStyle.js
function createStyle(data, useImportant, w) {
var styleElement, styleContent, selector, property, value;
w = w || window;
styleContent = '';
for (selector in data) {
if (!data.hasOwnProperty(selector)) continue;
styleContent += '\n' + selector + ' {\n';
for (property in data[selector]) {
if (!data[selector].hasOwnProperty(property)) continue;
You can’t perform that action at this time.