Skip to content

Instantly share code, notes, and snippets.

@likerRr
likerRr / 1. Readme.md
Last active May 22, 2018 10:17
Webpack's `require.context` emulation for nodejs

Webpack's require.context is a powerful feature which helps to extract an array of paths within which the search of modules will be done. e.g.:

const requireFromContext = require.context(__dirname, true, /config\.js$/);
// Now `requireFromContext` contains files inside `__dirname/config` folder and which extension is `.js`

require.context is a special feature of webpack. Native nodejs's require doesn't containt that method and if you want to run unbundled code on nodejs, then you have to emulate require.context.

@likerRr
likerRr / optional_accessor.js
Created February 14, 2020 07:14
Allows deeply access object properties through Proxies
{
const accessor = Symbol('accessor');
function createAccessor() {
function fn() {}
fn[accessor] = true;
return new Proxy(fn, {
apply() {
download on
first run
download on
next run
requires
package-lock.json
modifies
package-lock.json
deletes
node_modules
allows
install a single package
speed
npm i y if not found in cache
or cache is corrupted
no yes no yes normal
npm ci y if not found in cache
or cache is corrupted
yes no yes no fast
@likerRr
likerRr / weather.html
Created January 24, 2021 17:55
weather widget for notion
<a class="weatherwidget-io" href="https://forecast7.com/ru/53d9027d56/minsk/" data-label_1="MINSK" data-label_2="WEATHER" data-theme="original" >MINSK WEATHER</a>
<script>
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='https://weatherwidget.io/js/widget.min.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','weatherwidget-io-js');
</script>