Skip to content

Instantly share code, notes, and snippets.

🔥
In case of fire: git commit, git push, leave the building!

Dalibor Gogic daliborgogic

🔥
In case of fire: git commit, git push, leave the building!
Block or report user

Report or block daliborgogic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@daliborgogic
daliborgogic / default.vue
Last active Dec 9, 2019
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 / index.js
Last active Nov 29, 2019
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()
@daliborgogic
daliborgogic / Img.vue
Last active Nov 12, 2019
Conditionaly load img based on current users download speed and users choice to save data.
View Img.vue
<template>
<img :src="srcImage" :loading="loading" :alt="alt">
</template>
<script>
export default {
props: {
src: {
type: Object,
default: () => ({
@daliborgogic
daliborgogic / backup-files.sh
Last active Nov 8, 2019
I like to move it move it Google Cloud Bucket
View backup-files.sh
#!/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(){
@daliborgogic
daliborgogic / Content.vue
Last active Nov 6, 2019
Mark external links (UX). internal let router handle.
View Content.vue
<template>
<div v-html="content" />
</template>
<script>
export default {
props: {
content: {
type: String,
default: ''
View index.js
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 })
View debounce.js
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 / 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 / .dockerignore
Last active Oct 9, 2019
Mnml Nuxt.js Docker ~57.5MB
View .dockerignore
*
!assets
!pages
!static
!nuxt.config.js
!package-lock.json
!package.json
@daliborgogic
daliborgogic / github.js
Last active Oct 7, 2019
Request a user's GitHub identity
View github.js
const uuid = require('uuid')
const {
GITHUB_CLIENT_ID = '#####',
GITHUB_REDIRECT_URL = 'https://example.com/callback',
GITHUB_SCOPE = 'user:email'
} = process.env
const authorize = `https://github.com/login/oauth/authorize`
const states = []
You can’t perform that action at this time.