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 / line_item.json
Last active December 21, 2019 18:32
Line Item JSON API specification (v1.0)
{
"data": {
"id": "5c70a48c318ce30ebd00c14c",
"type": "line_items",
"links": {
"self": "https://foo.example.com/api/line_items/5c70a48c318ce30ebd00c14c"
},
"attributes": {
"type": "sku",
"sku": "7J237-410",
@daliborgogic
daliborgogic / Img.vue
Last active November 12, 2019 19:40
Conditionaly load img based on current users download speed and users choice to save data.
<template>
<img :src="srcImage" :loading="loading" :alt="alt">
</template>
<script>
export default {
props: {
src: {
type: Object,
default: () => ({
@daliborgogic
daliborgogic / backup-files.sh
Last active November 8, 2019 14:41
I like to move it move it Google Cloud Bucket
#!/bin/bash
# . ./backup-files.sh from to
# Variables
WHAT=`date +%d%m%y%H%M%S`.tar.gz
WHERE=gs://$2/$WHAT
SMALLER_ARE_BETTER="tar -czvf $WHAT $1"
targz(){
async function foo (method, url, body) {
if (!url) throw new Error()
let config = {
headers: { accept: 'application/json' }
}
if (method && body) {
config.body = JSON.stringify(body)
config.method = method
}
const res = await fetch(url, { config })
@daliborgogic
daliborgogic / debounce.js
Created October 15, 2019 11:42
Debounce
export default function (func, wait, immediate) {
var timeout
return function() {
var context = this, args = arguments
var later = function() {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
clearTimeout(timeout)
@daliborgogic
daliborgogic / instagram.js
Last active October 4, 2019 10:27
Instagram Graph API Media
const fetch = require('node-fetch')
const { FB_PAGE_ID, FB_ACCESS_TOKEN } = process.env
const { getParams } = require('./helpers')
const GRAPH_URL = 'https://graph.facebook.com/v4.0'
const headers = { 'content-type': 'application/json' }
const options = { headers }
let params = { access_token: FB_ACCESS_TOKEN }
@daliborgogic
daliborgogic / localhost.sh
Created September 9, 2019 18:14
The simplest way to generate a private key and self-signed certificate for localhost.
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 / .aliases
Last active September 10, 2019 10:15
DNS over HTTPS (DoH) in Google Chrome
# Google Chrome
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
alias chromedoh='chrome --enable-features="dns-over-https<DoHTrial" --force-fieldtrials="DoHTrial/Group1" --force-fieldtrial-params="DoHTrial.Group1:server/https%3A%2F%2F1.1.1.1%2Fdns-query/method/POST"'
@daliborgogic
daliborgogic / Dockerfile
Last active August 18, 2023 06:47
Best-Practice Docker Image and GitHub Workflow for Node.js app. [Continuous Integration/Delivery/Deployment]
ARG VERSION=12.10.0
# Development ##################################################################
FROM mhart/alpine-node:${VERSION} AS dev
WORKDIR /app
COPY package*.json .gitignore ./
ENV HOST=0.0.0.0
ENV PORT=${PORT}
RUN npm ci --prefer-offline
COPY . .
FROM mhart/alpine-node:12.9.1
RUN npm i -g pkg
RUN which pkg
COPY package*.json /app/
RUN cd /app; npm ci \
&& npm run build \
&& /usr/bin/pkg -t node12-linux --output .dist .
COPY . /app