Skip to content

Instantly share code, notes, and snippets.

View ilikerobots's full-sized avatar

Mike Hoolehan ilikerobots

View GitHub Profile
build: {
rollupOptions: {
input: {
main: '@/main.ts',
jack: '@/jack.ts',
},
},
}
import {defineCustomElement} from 'vue'
import JackInTheBox from "@/JackInTheBox.vue";
customElements.define('jack-in-the-box',
defineCustomElement(JackInTheBox, {
shadowRoot: false
}),
);
<script setup lang="ts">
import {ref, computed} from 'vue'
const props = defineProps<{
tapCount: number
message: string
}>()
const currentTaps = ref(0)
const showMessage = computed(() => currentTaps.value >= props.tapCount)
@ilikerobots
ilikerobots / image_with_average_color.py
Created March 28, 2022 06:46
Django Image model with Average Color field
from decimal import Decimal
from django.db import models
class Color(models.Model):
red = models.DecimalField(blank=False, null=False, decimal_places=2, max_digits=12)
green = models.DecimalField(blank=False, null=False, decimal_places=2, max_digits=12)
blue = models.DecimalField(blank=False, null=False, decimal_places=2, max_digits=12)
alpha = models.DecimalField(blank=False, null=False, decimal_places=2, max_digits=12, default=Decimal(1.0))
export const createSharedStore = (modules) => {
return new createStore({
plugins: [
createPersistedState({
paths: Object.entries(modules).map(
([mName , m]) => 'persistentPaths' in m
? m.persistentPaths.map(path => mName + "." + path)
: []
).flat(),
})
createPersistedState({
paths: Object.entries(modules).map(
([mName , m]) => 'persistentPaths' in m
? m.persistentPaths.map(path => mName + "." + path)
: []
).flat(),
})
export default {
state: {count: 0},
mutations: {
increment: state => state.count++,
decrement: state => state.count--
},
persistentPaths: ["count", ]
}
export const createAppInEl = (options, store, selector) => {
const mountEl = document.querySelector(selector);
const app = createApp(options, {...mountEl.dataset});
app.use(store);
// additional configurations here
app.mount(selector);
return app;
}
const datasetDatatypePostfix = "Datatype";
const convertDatasetToTyped = (dataset) => {
const keys = Object.keys(dataset);
keys.forEach(function(key){
let datatypeKey = key + datasetDatatypePostfix;
if (datatypeKey in dataset) {
let datatype = dataset[datatypeKey];
switch (datatype) {
case "String": //already string, do nothing
<div id="hello_world_b" data-msg="{{ msg1 }}">
<hello-world></hello-world>
</div>