Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
In Git we trust!

Dalibor Gogic daliborgogic

:octocat:
In Git we trust!
View GitHub Profile
View vite.config.js
import path from 'node:path'
import { loadEnv } from 'vite'
export default ({ mode }) => {
return {
env: Object.assign(process.env, loadEnv(mode, process.cwd()))
}
}
View index.mjs
import { createServer } from 'node:http'
import { createHmac } from 'node:crypto'
import { Printer, InMemory, Drawer, Style, Align, Model } from 'escpos-buffer'
const {
PORT = 3000,
HOST = 0,
GITHUB_WEBHOOK_SECRET,
PRINTER_MODEL = 'TM-T20',
PRINTER_COLUMNS = 56
@daliborgogic
daliborgogic / i18n.js
Last active Nov 6, 2021
[POC] i18n in 142 bytes 💥
View i18n.js
export default function (locale, path, ...args) {
return (path, ...args) => {
const keys = path.trim().split('.')
const fn = keys.reduce((prev, curr) => prev && prev[curr], locale)
return typeof fn === 'function' ? fn(...args) : fn
}
}
// export default function(t,e,...n){return(e,...n)=>{const r=e.trim().split(".").reduce((t,e)=>t&&t[e],t);return"function"==typeof r?r(...n):r}}
@daliborgogic
daliborgogic / functions.php
Last active May 6, 2021
Polylang REST API assign the translation
View functions.php
<?php
add_filter('rest_pre_echo_response', function($response, $object, $request) {
$post_id = $response['id'];
$type = get_post_type($post_id);
$from_post = $request->get_param('from_post');
if ($from_post && $type === 'hotels') {
pll_set_post_language($post_id, 'de');
pll_set_post_language($from_post, 'en');
pll_save_post_translations(array(
@daliborgogic
daliborgogic / vitals.js
Last active Aug 31, 2021
[POC] Sending Vite.js Core Web Vitals to Google Analytics
View vitals.js
const transformer = options => ({
apply: 'post',
transform({ code, isBuild }) {
if (!isBuild) return code
return code.replace('</body>', `<script defer type="module">
const KEY = 'ga:user'
const UID = (localStorage[KEY] = localStorage[KEY] || Math.random() + '.' + Math.random())
const onError = err => console.error('[vite vitals] ', err)
const onDebug = (label, payload) => console.log(label, payload)
@daliborgogic
daliborgogic / _page.vue
Last active Sep 3, 2020
[POC] Dynamic component by current route
View _page.vue
<template>
<Component :is="is" />
</template>
<script>
import layout from '@/helpers/layout'
const components = {
vBuilding: () => import('@/components/pages/Building.vue' /* webpackChunkName: `building` */),
vSeminaire: () => import('@/components/pages/Seminaire.vue' /* webpackChunkName: 'components/page/seminaire' */),
vCoaching: () => import('@/components/pages/Coaching.vue' /* webpackChunkName: 'components/page/coaching' */),
View main.js
document.querySelectorAll('input[type=search]').forEach(input => {
input.addEventListener('mouseup', e => {
if (input.value.length > 0) {
setTimeout(() => {
if (input.value.length === 0) {
// do reset action here
}
}, 5)
}
})
@daliborgogic
daliborgogic / localhost.sh
Created Jun 3, 2020
The simplest way to generate a private key and self-signed certificate for localhost is with this openssl.
View localhost.sh
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
View .aliases
alias foo=npm audit --json | grep '"type":"auditAdvisory"' | jq -r '{(.data.advisory.module_name):.data.advisory.patched_versions}' | jq -s add
@daliborgogic
daliborgogic / script.sh
Created May 8, 2020
Want to find out what files npm will publish into the tarball without actually publishing?
View script.sh
npm pack && tar -xvzf *.tgz && rm -rf package *.tgz