Skip to content

Instantly share code, notes, and snippets.

😶
boop

andreas andreasvirkus

😶
boop
Block or report user

Report or block andreasvirkus

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
View brew-docker.sh
brew install docker docker-machine$ brew cask install virtualbox
docker-machine create --driver virtualbox default
docker-machine env default
eval "$(docker-machine env default)"
docker run hello-world
docker-machine stop default
@andreasvirkus
andreasvirkus / README.md
Created May 11, 2020
A lightweight Deno server using Oak.
View README.md

Deno server

A lightweight deno server that runs on oak.

Run it with deno --allow-net server.ts

@andreasvirkus
andreasvirkus / service-worker.js
Created Apr 28, 2020
SW for vue-cli with Google's workbox
View service-worker.js
// eslint-disable-next-line no-undef
workbox.setConfig({
debug: false
})
workbox.core.skipWaiting()
workbox.precaching.precacheAndRoute([])
workbox.routing.registerRoute(
@andreasvirkus
andreasvirkus / base.css
Last active Apr 22, 2020
When I'm too lazy to set up Tailwind and PurgeCSS for a prototype or a small project, then this will do.
View base.css
/* Handicraft reset */
*,
*::before,
*::after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
body {
@andreasvirkus
andreasvirkus / MasterList.vue
Created Apr 15, 2020
Demonstrating recursive Vue components
View MasterList.vue
<template>
<div id="app">
<nested-list
v-for="item in list"
:key="item.name"
:name="item.name"
:items="item.items"
:level="0"
/>
</div>
View strip.js
export const strip = html => {
const doc = new DOMParser().parseFromString(html, 'text/html')
return (doc.body.textContent || '').trim()
}
View pagination.js
const calculatePages = (length: number, current: number, total: number) => {
if (length === 0) return []
if (length === 1) return [current]
if (total <= length + 4) return Array.from({ length: total }, (_v, i) => i + 1)
const jumpSize = Math.ceil(length / 2)
const centerStart = Math.min(Math.max(current - (length - jumpSize), 3), total - length - 1)
const jumpStart = current <= length + 1 ? 2 : `-${jumpSize}`
const jumpEnd = current >= total - length ? total - 1 : `+${jumpSize}`
return [1, jumpStart, ...Array.from({ length }, (_v, i) => centerStart + i), jumpEnd, total]
}
View mergeImages.js
// Defaults
const defaultOptions = {
format: 'image/png',
quality: 0.92,
width: undefined,
height: undefined,
Canvas: undefined
}
const createCanvas = options => (options.Canvas ? new options.Canvas() : window.document.createElement('canvas'))
View convertTextToImage.js
export const convertTextToImage = (context, text, font = 'normal normal 24px cursive', color = '#000000') => {
context.font = font
context.fillStyle = color
context.fillText(text, 0, 10)
context.canvas.width = context.measureText(text).width
return context.canvas.toDataURL()
}
@andreasvirkus
andreasvirkus / canvasStitch.js
Created Dec 14, 2019
Stitch together 2 images and screenshot them
View canvasStitch.js
export const screenshot = (canvasRef, base, avatar) => {
const ctx = canvasRef.getContext('2d')
const imageObj1 = new Image()
const imageObj2 = new Image()
imageObj1.src = base.src
imageObj1.onload = () => {
ctx.drawImage(imageObj1, 0, 0, base.height, base.width)
imageObj2.src = avatar.src
imageObj2.onload = () => {
ctx.drawImage(imageObj2, avatar.left, avatar.top, avatar.height, avatar.width)
You can’t perform that action at this time.