Skip to content

Instantly share code, notes, and snippets.

View UniBreakfast's full-sized avatar
💡
reinventing basic stuff in order to understand it better

Mykhailo "Ninin" Velykoselskyi UniBreakfast

💡
reinventing basic stuff in order to understand it better
View GitHub Profile
@UniBreakfast
UniBreakfast / php call if testing module
Created December 3, 2018 15:19
testing php module function in module
<?php
# some function in some php-file meant to be used as a module
function myFunc(param) {
echo param;
}
# testing function from module in that module
# so that it does not impact the usage elsewhere
if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) myFunc();
@UniBreakfast
UniBreakfast / recordsFromData.js
Last active May 3, 2019 14:42
a function to show data arrays as objects (w headers) in console.table
function recordsFrom(data) {
try { var [headers, rows] = data }
catch { var {headers, rows} = data }
return rows.map(row => {
let obj = {}
row.forEach((value,i) => obj[headers[i]] = value)
return obj
})
}
@UniBreakfast
UniBreakfast / gist:eb49cb9a003ede207b985883dd6272f7
Last active February 17, 2019 09:38
get the link from temp1
function get(temp) {
var text = temp.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.children[1].innerText,
end = text.search('","cdn":"akamai_interconnect","quality":"720p')+1 || text.search('","cdn":"fastly","quality":"720p')+1,
begin = text.substring(0,end).lastIndexOf('https')
return text.substring(begin,end-1)
}
get(temp1)
@UniBreakfast
UniBreakfast / keybindings.json
Last active February 20, 2019 15:21
VScode-settings-sync
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+shift+/",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+a",
"command": "-editor.action.blockComment",
@UniBreakfast
UniBreakfast / geekycolors.css
Created March 6, 2019 09:46
css hex colors that are easy to read and remember
#accede #beaded #bedded #bedead #beebee #beefed #cabbed #dabbed #decade #deeded
#deface #efface #facade #aced #babe #bead #beef #cafe #dead #deaf #deed #face
#fade #feed #ace #add #baa #bad #bed #bee #cab #cad #cee #dab #dad #dee #ebb
#eff #fad #fed #fee #abba
#123456
#234567
#345678
#456789
#567890
#098765
@UniBreakfast
UniBreakfast / cookie.js
Last active September 1, 2019 13:50
Just three simple functions to wrap browser's cookie API
`.selector {
property1: value;
property2: value;
}
#selector { property: value }`
.match(/[^{]+{[^}]+\}/g).forEach(rule => d.styleSheets[0].insertRule(rule))
@UniBreakfast
UniBreakfast / valid-js-identifiers.js
Created October 21, 2019 20:02
characters we can use in JavaScript names for variables, functions etc.
$, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, ª, µ, º, À, Á, Â, Ã, Ä, Å, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ð, Ñ, Ò, Ó, Ô, Õ, Ö, Ø, Ù, Ú, Û, Ü, Ý, Þ, ß, à, á, â, ã, ä, å, æ, ç, è, é, ê, ë, ì, í, î, ï, ð, ñ, ò, ó, ô, õ, ö, ø, ù, ú, û, ü, ý, þ, ÿ, Ā, ā, Ă, ă, Ą, ą, Ć, ć, Ĉ, ĉ, Ċ, ċ, Č, č, Ď, ď, Đ, đ, Ē, ē, Ĕ, ĕ, Ė, ė, Ę, ę, Ě, ě, Ĝ, ĝ, Ğ, ğ, Ġ, ġ, Ģ, ģ, Ĥ, ĥ, Ħ, ħ, Ĩ, ĩ, Ī, ī, Ĭ, ĭ, Į, į, İ, ı, IJ, ij, Ĵ, ĵ, Ķ, ķ, ĸ, Ĺ, ĺ, Ļ, ļ, Ľ, ľ, Ŀ, ŀ, Ł, ł, Ń, ń, Ņ, ņ, Ň, ň, ʼn, Ŋ, ŋ, Ō, ō, Ŏ, ŏ, Ő, ő, Œ, œ, Ŕ, ŕ, Ŗ, ŗ, Ř, ř, Ś, ś, Ŝ, ŝ, Ş, ş, Š, š, Ţ, ţ, Ť, ť, Ŧ, ŧ, Ũ, ũ, Ū, ū, Ŭ, ŭ, Ů, ů, Ű, ű, Ų, ų, Ŵ, ŵ, Ŷ, ŷ, Ÿ, Ź, ź, Ż, ż, Ž, ž, ſ, ƀ, Ɓ, Ƃ, ƃ, Ƅ, ƅ, Ɔ, Ƈ, ƈ, Ɖ, Ɗ, Ƌ, ƌ, ƍ, Ǝ, Ə, Ɛ, Ƒ, ƒ, Ɠ, Ɣ, ƕ, Ɩ, Ɨ, Ƙ, ƙ, ƚ, ƛ, Ɯ, Ɲ, ƞ, Ɵ, Ơ, ơ, Ƣ, ƣ, Ƥ, ƥ, Ʀ, Ƨ, ƨ, Ʃ, ƪ, ƫ, Ƭ, ƭ, Ʈ, Ư, ư, Ʊ, Ʋ, Ƴ, ƴ, Ƶ, ƶ, Ʒ, Ƹ, ƹ, ƺ, ƻ, Ƽ, ƽ, ƾ, ƿ, ǀ, ǁ, ǂ, ǃ, DŽ, Dž, dž, LJ, Lj, lj, NJ, Nj, nj, Ǎ, ǎ, Ǐ, ǐ, Ǒ, ǒ, Ǔ, ǔ, Ǖ, ǖ, Ǘ, ǘ, Ǚ, ǚ, Ǜ, ǜ, ǝ, Ǟ
@UniBreakfast
UniBreakfast / streamToString.js
Created November 9, 2019 20:25
wait for body / streamToString
// short version I prefer
const wait = (stream, parts=[])=> new Promise((resolve, reject)=>
stream.on('error', reject).on('data', part => parts.push(part))
.on('end', ()=> resolve(Buffer.concat(parts).toString('utf8'))))
// usage example
wait(req).then(body => console.log(body))
// original by Marlon Bernardes
function streamToString (stream) {
@UniBreakfast
UniBreakfast / c4console.js
Last active March 6, 2020 17:46
c4console.js: any_value.c for console.log(value) && return value in-place! MUCH more convenient (example in showcase.html below!) than console.log(...) w/o vars or debugger when all you need is to see what's there at a point. Use light version for cleaner output and autocomplete.
// leave only one version and delete the rest, or it will throw a (nonbreaking) error
// full version: with all 11 getters and time
{
let lastTime
const logger = label => function() {
const time = new Date().toLocaleTimeString('en', {hour12: false})
console.log(time == lastTime? '':lastTime=time, label || '', this.valueOf(),
this instanceof Node? {dir: this}: ''))
return this.valueOf()