Skip to content

Instantly share code, notes, and snippets.

View ilikerobots's full-sized avatar

Mike Hoolehan ilikerobots

View GitHub Profile
@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>
@ilikerobots
ilikerobots / 2021-05-11-django-vue3.js
Created May 12, 2021 08:51
string-property-passing-01
const selector = "#my_app_element";
const mountEl = document.querySelector(selector);
const app = createApp(AppComponent, {...mountEl.dataset});
class _RainbowBoxState extends State<RainbowBox>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _anim;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 5),
Animatable<Color> bgColor = RainbowColorTween([
Colors.red,
Colors.blue,
Colors.green,
Colors.yellow,
Colors.red,
])