Skip to content

Instantly share code, notes, and snippets.

View daliborgogic's full-sized avatar
:octocat:
In Git we trust!

Dalibor Gogic daliborgogic

:octocat:
In Git we trust!
View GitHub Profile
@daliborgogic
daliborgogic / api.mjs
Last active September 12, 2022 06:51
Gateway as a Service (GaaS)
function createApi(baseUrl, defaults = {}) {
const callable = () => {}
callable.url = baseUrl
return new Proxy(callable, {
get({ url }, key) {
const method = key.toUpperCase()
if (['GET', 'POST', 'PUT', 'DELETE', 'PATCH'].includes(method)) {
return (data, overrides = {}) => {
const payload = { method, ...defaults, ...overrides }
switch (method) {
@daliborgogic
daliborgogic / worker.mjs
Last active August 22, 2022 19:45
Prepend/appen to stream
import { createApp } from './dist/app.mjs'
import { pipeToWebWritable } from 'vue/server-renderer'
const prepend = String.raw`<!doctype html>
<html lang="en">
<title>Title</title>
<div id="app">`
const append = String.raw`</div>
<script type="importmap">
import path from 'node:path'
import { loadEnv } from 'vite'
export default ({ mode }) => {
return {
env: Object.assign(process.env, loadEnv(mode, process.cwd()))
}
}
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 / delay.js
Created December 16, 2016 15:26
Node.js Async/Await delay
'use strict'
const timeout = ms => new Promise(res => setTimeout(res, ms))
function convinceMe (convince) {
let unixTime = Math.round(+new Date() / 1000)
console.log(`Delay ${convince} at ${unixTime}`)
}
async function delay () {
@daliborgogic
daliborgogic / functions.php
Last active May 6, 2021 15:46
Polylang REST API assign the translation
<?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 / nginx-geoip-module.md
Created June 12, 2018 13:44 — forked from VirtuBox/nginx-geoip-module.md
How to configure GeoIP module for Nginx

Create a folder to store the databases :

mkdir -p /usr/share/GeoIP

Download Country IP database

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
@daliborgogic
daliborgogic / App.vue
Last active November 2, 2020 07:07
Variable Fonts Vue.js
<template>
<div id="app" :style="cssVariables">
<label>wdth</label>
<input type="range" min="10" max="700" v-model="wght">
<label>wght</label>
<input type="range" min="10" max="100" v-model="wdth">
<span>The quick brown fox jumps over the lazy dog</span>
</div>
</template>
@daliborgogic
daliborgogic / functions.php
Created April 14, 2020 07:09
Global Trade Identification Number (GTIN) WooCommerce
<?php
/**
* Global Trade Identification Numbers (GTINs) to WooCommerce products.
* Render the Global Trade Identification Number (GTIN) meta field.
*/
function woocommerce_render_gtin_field() {
$input = array(
'id' => '_gtin',
'label' => sprintf(
'<abbr title="%1$s">%2$s</abbr>',
@daliborgogic
daliborgogic / default.vue
Last active October 16, 2020 17:59
Vantablack? Nuxt.js simple theme switch
<script>
export default {
computed: {
theme () {
const [color, backgroundColor] = this.$store.state.theme
return {
'--color': color,
'--background-color': backgroundColor
}
}