Skip to content

Instantly share code, notes, and snippets.

View fczbkk's full-sized avatar
💭
writing Javascript

Riki Fridrich fczbkk

💭
writing Javascript
View GitHub Profile
@fczbkk
fczbkk / integromat.js
Created February 9, 2021 06:29
Integromat public test
console.log('this is public Integromat test')
@fczbkk
fczbkk / guess-number.js
Created October 1, 2020 05:41
Simple game loop for "Guess the number" game
const randomNumber = Math.ceil(Math.random() * 100)
let guessedNumber
do {
guessedNumber = Number(window.prompt(`I'm thinking of number between 1 and 100. Your guess:`))
if (randomNumber > guessedNumber) {
window.alert(`I'm thinking of HIGHER number than that.`)
}
if (randomNumber < guessedNumber) {
@fczbkk
fczbkk / index.js
Created May 23, 2020 05:38
Multiple versions of same library in Webpack
import modernJquery from 'modernJquery'
import legacyJquery from 'legacyJquery'
console.log('Look how much Jquery we can pack into single bundle!')
// 3.x.x
console.log('This is Jquery version:', modernJquery().jquery)
// 2.x.x
console.log('This is Jquery version:', legacyJquery().jquery)
@fczbkk
fczbkk / vue.config.js
Last active April 30, 2020 20:20
Import SCSS variables in every Vue component
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `@import "./styles/_variables.scss";`
}
}
}
};
const BrowserEvent = (eventName = '') => {
let event
if (typeof Event === 'function') {
event = new Event(eventName)
} else {
event = document.createEvent('Event')
event.initEvent(eventName, true, true)
}
// môže hodiť chybu, ak chýba `data`, `user` alebo `address`
const city = data.user.address.city
// relatívne bezpečné, ale strašne hnusné
const city = data &&
data.user &&
data.user.address &&
data.user.address.city
// ešte bezpečnejšie, ale o to hnusnejšie
@fczbkk
fczbkk / serialize.js
Created January 24, 2020 14:30
Function to serialize object into a string (e.g. URL parameters).
/**
* @typedef {Object} SerializeOptions
* @param {String} [pairDelimiter = '='] Delimiter to be used between each key and value.
* @param {String} [itemDelimiter = '&'] Delimiter to be used between each pair.
*/
/**
* Converts data object to a string, using delimiters. Primarily used to generate URL parameters.
* @param {Object} [data = {}]
* @param {SerializeOptions} [options]
@fczbkk
fczbkk / FullNameEditor.vue
Created November 23, 2019 09:06
Vue custom input
<template>
<div>
<p>
First name:<br>
<input v-model="first" @input="handleNameChange">
</p>
<p>
Last name:<br>
<input v-model="last" @input="handleNameChange">
</p>
@fczbkk
fczbkk / gatedQueue.js
Created September 10, 2019 06:05
Robustný spôsob, ako dynamicky vložiť mapu z api.mapy.cz do stránky. Použité knižnice "gatedQueue" a "loadExternalScript" sú znovupoužiteľné.
/**
* @typedef {Object} gatedQueueInterface
* @property {Function} openGate - Executes all functions currently in the queue. Functions added to the queue will be executed immediately, until the gate is closed again.
* @property {Function} closeGate - Closes the gate. Functions added to the queue will be executed only once the gate is opened again.
* @property {function(): boolean} isGateOpen - Checks whether the gate is currently open.
* @property {Function} addToQueue - Adds function(s) to the queue. Accepts single function or an array of functions.
* @property {Function} clearQueue - Removes all functions from the queue.
* @property {Function} processQueue - Calls all functions in the queue. Even if the gate is currently closed.
* @property {Function} getQueue - Returns copy of current queue.
*/
@fczbkk
fczbkk / format-as-currency.js
Last active August 1, 2019 04:46
Simple currency formatter
function formatAsCurrency (value = 0, currency = '$') {
const formattedValue = (value/100).toFixed(2)
return currency + formattedValue
}
formatAsCurrency(100)
// $1.00
formatAsCurrency(123)
// $1.23