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 / form.vue
Last active March 27, 2020 18:39
Dynamic Components
<template>
<form>
<Component v-for="({ type }, index) in schema" :key="index" :is="'v' + type" />
</form>
</template>
<script>
export default {
components: {
vInput: () => import('@/components/form/Input' /* webpackChunkName: "components/form/Input" */),
[
{
"password": {
"iterations": 10
},
"username": null,
"role": "admin",
"provider": "email",
"token": null,
"resetToken": null,
{
"data": {
"token": "123456"
}
}
{
"data": {
"firstName": "Foo",
"lastName": "Bar",
"email": "foo@bar.com"
}
}
@daliborgogic
daliborgogic / translate.js
Last active January 9, 2020 09:36
Cloud Translation v2
const { Translate } = require('@google-cloud/translate').v2
const translate = new Translate()
const text = 'Hello, world!'
const target = 'da'
async function translateText() {
// Translates the text into the target language. "text" can be a string for
// translating a single piece of text, or an array of strings for translating
// multiple texts.
@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)