Skip to content

Instantly share code, notes, and snippets.

@olegpolyakov
olegpolyakov / jsx-loader.js
Created January 13, 2023 04:27
Node JSX Loader
import { pathToFileURL } from 'url';
import { transformAsync } from '@babel/core';
const baseURL = pathToFileURL(`${process.cwd()}/`).href;
const extensionsRegex = /\.jsx$/;
const supportedModuleFormats = ['module', 'commonjs'];
const babelOptions = {
presets: [
['@babel/preset-react']
]
@olegpolyakov
olegpolyakov / csv2json.js
Created August 26, 2022 10:43
CSV to JSON
function csv2json(csv) {
const headerEndIndex = csv.indexOf('\r\n');
const bodyStartIndex = headerEndIndex + 2;
const headers = csv.substring(0, headerEndIndex).split(';');
const body = csv.substring(bodyStartIndex).split('\r\n').map(line => line.split(';'));
const data = body.map(item => {
const object = {};
headers.forEach((header, index) => {
@olegpolyakov
olegpolyakov / scrolling.css
Created July 28, 2022 12:30
CSS Scrolling Snippets
/* The basics */
.scroll-container {
overflow: auto;
scrollbar-width: thin;
scrollbar-color: hsl(0 0% 50%);
/* postcss-scrollbar will add the -webkit version automatically! */
}
@olegpolyakov
olegpolyakov / spinner.pug
Created July 8, 2020 19:48
Material Design Spinner Pug Mixin
mixin mdc-spinner
svg.mdc-spinner(
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 66 66'
class={
'mdc-spinner--colorful': attributes.colorful
}
)&attributes(attributes)
circle.mdc-spinner__circle(cx='33' cy='33' r='30')
//$todo
import {transform, registerPlugin, availablePlugins} from '@babel/standalone'
export type BabelPlugin = string | [string, any]
function writeStuckFlag(stuck: boolean) {
try {
localStorage.setItem('runtime/stuck', JSON.stringify(stuck))
} catch (err) {}
}
@olegpolyakov
olegpolyakov / github.auth.js
Created May 7, 2020 18:54
Express GitHub Auth
import express from 'express';
import request from 'request';
export default ({
config: {
GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET,
GITHUB_REDIRECT_URI
},
models: { User }
@olegpolyakov
olegpolyakov / server.js
Created May 3, 2020 12:37
Node HTTPS server
const fs = require('fs');
const https = require('https');
const ssl = {
key: fs.readFileSync(__dirname + '/ssl/codedojo.pem'),
cert: fs.readFileSync(__dirname + '/ssl/codedojo.crt')
};
https.createServer(ssl, server).listen(server.get('port'), 'codedojo.dev', () => {
console.log('Express server listening on port ' + server.get('port'));
@olegpolyakov
olegpolyakov / data.js
Created April 29, 2020 09:18
dedupMerge
const people = [
{
department: "Directing",
id: 20561,
job: "Director",
name: "James Gray"
},
{
department: "Writing",
id: 20561,
@olegpolyakov
olegpolyakov / 01_toys.md
Last active April 21, 2020 09:17
The Little JavaScripter

Правда ли что это строковое значение?

'atom'

Да, потому что 'atom' является набором буквенных символов, окруженных ковычками.


@olegpolyakov
olegpolyakov / mailerlite.js
Created April 7, 2020 10:20
MailerLite Node.js Client
const http = require('request');
const MAILERLITE_API_URL = 'http://api.mailerlite.com/api/v2';
module.exports = MAILERLITE_API_KEY => {
return {
subscribers: {
get(id) {
return request({
method: 'get',