Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
daliborgogic / functions.php
Created Apr 14, 2020
Global Trade Identification Number (GTIN) WooCommerce
View functions.php
<?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 Oct 16, 2020
Vantablack? Nuxt.js simple theme switch
View default.vue
<script>
export default {
computed: {
theme () {
const [color, backgroundColor] = this.$store.state.theme
return {
'--color': color,
'--background-color': backgroundColor
}
}
@daliborgogic
daliborgogic / delay.js
Created Dec 16, 2016
Node.js Async/Await delay
View delay.js
'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 / _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' */),
@daliborgogic
daliborgogic / awss3deleteolderthan.sh
Last active Sep 1, 2020
Delete files older than n in S3
View awss3deleteolderthan.sh
#!/bin/bash
# Usage: . ./awss3deleteolderthan.sh [bucket] [path] "20 minutes ago"
endpoint="https://ams3.digitaloceanspaces.com"
aws s3 ls s3://$1/$2 --endpoint $endpoint --recursive | while read -r line;
do
createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
@daliborgogic
daliborgogic / App.vue
Last active Jul 30, 2020
Variable Fonts Vue.js
View App.vue
<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>
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")
@daliborgogic
daliborgogic / index.js
Last active May 22, 2020
amqp async/await node.js
View index.js
const amqp = require('amqplib')
const eventEmitter = require('events')
class OopsEmitter extends eventEmitter {}
const oopsEmitter = new OopsEmitter()
;(async () => {
try {
const conn = await amqp.connect('amqp://localhost?heartbeat=5s')
const ch = await conn.createChannel()
View .aliases
alias foo=npm audit --json | grep '"type":"auditAdvisory"' | jq -r '{(.data.advisory.module_name):.data.advisory.patched_versions}' | jq -s add
You can’t perform that action at this time.