Skip to content

Instantly share code, notes, and snippets.

View dimon-durak's full-sized avatar

Димон Дурак dimon-durak

View GitHub Profile
@dimon-durak
dimon-durak / .gitignore
Created January 27, 2022 08:45 — forked from smoser/.gitignore
cloud-init ubuntu nocloud example with network config
*.img
*.raw
@dimon-durak
dimon-durak / parse.js
Last active December 23, 2021 17:46
Parse string
let parsingSplitter = '~';
let strForParsing = 'Sherlock Holmes~221B Baker Street~London~UK';
let parsingKeys = ['name', 'address', 'city', 'country'];
const parse = (str, keys, splitter) => {
const reStr = keys.reduce((s, k, i, a) => `${s}(?<${k}>.*)${ i + 1 < a.length ? splitter : ''}`,'');
const RE = new RegExp(reStr);
const { groups:parsedData } = RE.exec(str);
return parsedData
};
@dimon-durak
dimon-durak / example.yaml
Created October 9, 2021 08:15
Запуск zx скриптов в Github Actions
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Run zx script
env:
npm_config_yes: true
run: npx zx script.js
@dimon-durak
dimon-durak / javascript-useful-links.md
Created September 16, 2021 06:32 — forked from genadyp/javascript-useful-links.md
javascript (js) useful links
@dimon-durak
dimon-durak / .eleventy.js
Created September 16, 2021 06:24 — forked from shawn-sandy/.eleventy.js
FP-Pages
const fs = require("fs")
const htmlmin = require("html-minifier")
const pluginRss = require("@11ty/eleventy-plugin-rss")
const markdown = require("@shawnsandy/ideas/lib/markdown")
const image = require("@11ty/eleventy-img")
const CleanCSS = require("clean-css")
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation")
const take = ("lodash.take")
@dimon-durak
dimon-durak / style.11ty.js
Created September 16, 2021 05:24 — forked from liamfiddler/style.11ty.js
SCSS + PostCSS pipeline for 11ty
// sass dependencies: `npm i -D sass`
const util = require('util');
const sass = require('sass');
const renderSass = util.promisify(sass.render);
// postcss dependencies: `npm i -D autoprefixer postcss precss`
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
const precss = require('precss');
const postcssProcessor = postcss([precss, autoprefixer]);
@dimon-durak
dimon-durak / gist:3eebe4fb7a5963bf9d38b570d8e19e4e
Created September 16, 2021 05:12 — forked from SteveALee/gist:0e78dff6040780720093a14ce3a6f0ba
Have browsers update when editing 11ty config file

By default 11ty devmode uses browsersync to reload webbrowsers whenever it regenerates pages to _site. It does this automatically when template files change.

However, the .eleventy.js file is only loaded when 11ty starts so if you edit shortcodes (say) you need to stop and restart 11ty.

The solution is to use nodemon to restart 11ty automatically when the config file changes. But then you need to use browser F5 to refresh. The solution to that is to get browsersync to reload the browsers To achieve that, the 11ty browsersync config option allows you to define a callback when browsersync is ready and you can add a browser reload call there.

Here's example code from music-practice-tools

@dimon-durak
dimon-durak / 11ty-parsing-post-collection-with-tags.md
Created September 16, 2021 05:12
11ty - Parsing posts collection with tags

11ty - Parsing posts collection with tags

My code to parse posts or any other collection in 11ty.

Result

  • Order of the posts gets reversed, sorting by date.
  • Date format normalized (d.m.y).
  • Description shortened to 105 characters.
  • Undefined or empty tags are ignored.
import { promises as fs } from "fs";
import * as path from "path";
import * as jsyaml from "js-yaml";
import { fileURLToPath } from "url";
import MarkdownIt from "markdown-it";
const mdit = new MarkdownIt({});
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const srcdir = path.resolve(__dirname, "./src");
const builddir = path.resolve(__dirname, "./build");
@dimon-durak
dimon-durak / markdown-details-collapsible.md
Created September 16, 2021 04:53 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets