Skip to content

Instantly share code, notes, and snippets.

View studentIvan's full-sized avatar
🎯
Focusing

Ivan Maslov studentIvan

🎯
Focusing
View GitHub Profile
@studentIvan
studentIvan / server.ts
Created October 10, 2023 23:53
Example next.js custom server with headers taken from the page meta tags to solve the problem https://github.com/vercel/next.js/issues/50914
import { createServer, type IncomingMessage, type ServerResponse } from "http";
import { StringDecoder } from "string_decoder";
import { parse } from "url";
import next from "next";
import nextConfig from "../next.config";
const decoder = new StringDecoder("utf-8");
@studentIvan
studentIvan / start.applescript
Created June 21, 2021 13:59
Helpful developer's bash applescript (osascript) to open the tab with the specific url inside the google chrome new or reloaded. It may check the app running on the same port also and re-use this tab.
-- using example:
-- sleep 10 && osascript start.applescript "http://local.${PROJECT_DOMAIN}.com:8080" 8080 &
-- yarn start
on run argv
tell application "Google Chrome"
activate
set targetURL to (item 1 of argv)
-- I know I can parse it but I'm too lazy...
set targetPort to (item 2 of argv)
@studentIvan
studentIvan / pcss-plugin-variables-rename.js
Created June 17, 2021 12:28
Postcss plugin variables rename
/* eslint-disable no-plusplus */
/* eslint-disable func-names */
/* eslint-disable no-restricted-syntax */
const fs = require('fs');
const path = require('path');
/** load the existing json map with access to write and read */
const variablesMapJSON = path.join(__dirname, '/variables-map.json');
/**
@studentIvan
studentIvan / number-to-price.js
Created December 11, 2020 18:58
Price format super fast function by @studentIvan (Ivan Maslov)
/** [E]UR, [S]EK, [G]PB, [P]LN, [D]KK, NOK, CHF, [U]SD, [CA]D */
const defaultNumberToPriceFn = function numberToPrice(n, c) {
let smb = c || this.currency;
if (smb[0] === 'E') { smb = '€'; }
else if (smb[0] === 'U' || (smb[0] === 'C' && smb[1] === 'A')) { smb = '$'; }
else if (smb[0] === 'S' || smb[0] === 'D') { smb = 'kr'; }
else if (smb[0] === 'G') { smb = '£'; }
else if (smb[0] === 'P') { smb = 'zł'; }
const nR = Math.round(+(n || 0) * 100) / 100;
const nStr = nR.toString();
@studentIvan
studentIvan / mobile.preact.config.js
Last active May 18, 2020 18:22
Preact 8 with CLI configuration example. (the default configuration passed with --config is a web.preact.config.js)
/* eslint-disable */
import path from 'path';
import fs from 'fs';
import webpack from 'webpack';
import HtmlWebpackInlineSVGPlugin from 'html-webpack-inline-svg-plugin';
import SVGSpritemapPlugin from 'svg-spritemap-webpack-plugin';
// import { WebpackBundleSizeAnalyzerPlugin } from 'webpack-bundle-size-analyzer';
import packageData from '../../package.json';
import pathsResolveConfig from './paths.resolve.config';
import appPackageData from '../../../mobile-app/package.json';
@studentIvan
studentIvan / mobile.preact.config.js
Created May 18, 2020 18:19
Preact 8 with CLI configuration example.
/* eslint-disable */
import path from 'path';
import fs from 'fs';
import webpack from 'webpack';
import HtmlWebpackInlineSVGPlugin from 'html-webpack-inline-svg-plugin';
import SVGSpritemapPlugin from 'svg-spritemap-webpack-plugin';
// import { WebpackBundleSizeAnalyzerPlugin } from 'webpack-bundle-size-analyzer';
import packageData from '../../package.json';
import pathsResolveConfig from './paths.resolve.config';
import appPackageData from '../../../mobile-app/package.json';
@studentIvan
studentIvan / instructions.txt
Last active May 21, 2020 18:36
Fast solution to replace the node-spdy package using with the express.js on the node v12. Development purposes only!
1. npm uninstall spdy
2. npm install http2-proxy finalhandler
3. replace the code
import spdy from 'spdy';
spdy.createServer(HTTP2_OPTIONS, app).listen(HTTP2_PORT, (error) => { ...
with
@studentIvan
studentIvan / cloudSettings
Last active May 12, 2020 11:51
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-05-12T11:51:27.444Z","extensionVersion":"v3.4.3"}
/* eslint-disable */
var loaderUtils = require('loader-utils');
/**
* getLocalIdent function for preact-css-modules
* do (null, null, className) for manual use
*/
var getLocalIdent = (context, localIdentName, localName, options) => {
var result = localName;
/** exclude some classNames */
--c--- get multiplier from things todo object
on getMultiplierFromToDo(theToDo, defaultMultiplierValue)
local theToDo
set toDoName to name of theToDo
set multiplier to second character of toDoName
set multiplierBefore to first character of toDoName
set multiplierAfter to third character of toDoName
set isValidMultiplier to ((multiplierBefore is equal to "[") and (multiplierAfter is equal to "]"))
set multiplierValue to defaultMultiplierValue
if isValidMultiplier then set multiplierValue to multiplier as real