Skip to content

Instantly share code, notes, and snippets.

View bojidaryovchev's full-sized avatar
🏠
Working from home

bojidaryovchev

🏠
Working from home
View GitHub Profile
@bojidaryovchev
bojidaryovchev / dateFormatter.js
Last active September 12, 2018 10:37
Date Formatting in JavaScript
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
@bojidaryovchev
bojidaryovchev / mongoosastic.txt
Last active October 11, 2020 23:36
Mongoose Mongoosastic ElasticSearch
mongoosastic
mongoose.model('product', ProductSchema);
PUT http://localhost:9200/products
{
"settings": {
"analysis": {
"analyzer": {
@bojidaryovchev
bojidaryovchev / tailwind-angular
Created October 29, 2020 13:53 — forked from kctang/tailwind-angular
Tailwind CSS support in Angular 10, with Angular Material
Index: client/angular.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- client/angular.json (revision fcfaf7440d0eaed6baa841b2b4d9eca231b002f6)
+++ client/angular.json (date 1603593891228)
@@ -39,7 +39,7 @@
"prefix": "app",
"architect": {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.clock {
background: #414141;
function partitionValues(total, minValue, values) {
const percentageByValue = {};
values.filter(v => v > minValue).forEach(v => percentageByValue[v] = v / total * 100);
total -= values.filter(v => v <= minValue).reduce((p, c) => p + c, 0);
const totalPercentage = Object.keys(percentageByValue)
.map(k => percentageByValue[k])
.reduce((prev, curr) => prev + curr, 0);
@bojidaryovchev
bojidaryovchev / htmlToImage.ts
Created December 29, 2020 12:28
export html elements to an image
// in index.html
// <script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js" integrity="sha512-01CJ9/g7e8cUmY0DFTMcUw/ikS799FHiOkA0eyHsUWfOetgbx/t6oV4otQ5zXKQyIrQjGTHSmRVPIgrgLccZi/WMA==" crossorigin="anonymous"></script>
// <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js" integrity="sha512-Qlv6VSKh1lgDKGoJbnyA5RMXYcvnpIqhO++MhkIM2fStMcGT9i2T//tSwYFlcyoRRDcDZ+TYHpH8azBBCyqhpSeqw==" crossorigin="anonymous"></script>
// in typescript
import 'dom-to-image';
import 'file-saver';
import * as mergeBase64 from 'merge-base64';
const masculineDigits = ['нула', 'един', 'два', 'три', 'четири', 'пет', 'шест', 'седем', 'осем', 'девет', 'десет'];
const feminineDigits = ['нула', 'една', 'две', 'три', 'четири', 'пет', 'шест', 'седем', 'осем', 'девет', 'десет'];
const teens = ['единайсет', 'дванайсет', 'тринайсет', 'четиринайсет', 'петнайсет', 'шестнайсет', 'седемнайсет', 'осемнайсет', 'деветнайсет']
const decimals = ['десет', 'двайсет', 'трийсет', 'четиридесет', 'петдесет', 'шейсет', 'седемдесет', 'осемдесет', 'деветдесет'];
const hundreds = ['сто', 'двеста', 'триста', 'четиристотин', 'петстотин', 'шестстотин', 'седемстотин', 'осемстотин', 'деветстотин'];
const thousands = ['хиляда', 'две хиляди', 'три хиляди', 'четири хиляди', 'пет хиляди', 'шест хиляди', 'седем хиляди', 'осем хиляди', 'девет хиляди'];
const moneySingular = 'лев';
const moneyPlural = 'лева';
const cent = 'стотинка';
@bojidaryovchev
bojidaryovchev / viewportHeight.html
Last active October 7, 2021 12:34
viewport height fix (mobile devices which have their buttons as part of the screen)
<!-- viewport height fix -->
<script>
function recalculateViewportHeight() {
// First we get the viewport height and we multiple it by 1% to get a value for a vh unit
const vh = window.innerHeight * 0.01;
// Then we set the value in the --vh custom property to the root of the document
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
window.addEventListener('load', () => {
@bojidaryovchev
bojidaryovchev / getDates.ts
Last active November 13, 2021 21:10
a function to get all dates surrounding a given date - it is intended to use when building calendars with 42 cells
getDates(date: Date): Date[] {
const dates: Date[] = [];
const firstDate: Date = new Date(new Date(date).setDate(1));
const firstDateDay: number = firstDate.getDay();
const daysBeforeFirst: number = firstDateDay - 1 === -1 ? 6 : firstDateDay - 1;
for (let i = daysBeforeFirst - 1; i >= 0; i--) {
dates.push(new Date(new Date(date).setDate(-i)));
}
@bojidaryovchev
bojidaryovchev / codingConvention.ts
Last active August 31, 2022 15:22
Coding Convention Proposal
// Here is an idea of a coding convention inspired by pure functions:
// Let's look at the following example:
interface Stuff {}
interface OtherStuff {}
class StuffApi {
getStuff(): Promise<Stuff> {