Skip to content

Instantly share code, notes, and snippets.

View kirklewis's full-sized avatar
🙂
try { positivity() } catch { negativity() } finally { laugh() }

Kirk Lewis kirklewis

🙂
try { positivity() } catch { negativity() } finally { laugh() }
View GitHub Profile
@kirklewis
kirklewis / perl-module-regex.pl
Created February 24, 2020 11:01
A Perl module Regular Expression.
use v5.24;
use Data::Dump qw(pp);
use constant PERL_MODULE_REGEX => qr/\w+:{2}[\w:]+/;
use constant PERL_USE_MODULE_REGEX => qr/use\s+(${\PERL_MODULE_REGEX})/;
use constant PERL_PACAKGE_MODULE_REGEX => qr/package\s+(${\PERL_MODULE_REGEX})/;
my $str = <<'MODULES';
use My::ACME;
use My::ACME::Imported;
@kirklewis
kirklewis / build-docker-compose-yaml.groovy
Created February 24, 2020 21:12
Groovy 3.0.0 YamlBuilder Example
import groovy.yaml.YamlBuilder
class DockerService { List ports; List volumes; Boolean tty; }
def ordersApiService = new DockerService(
ports: ['3040:3040'],
volumes: ['./:/opt'],
tty: true,
)
@kirklewis
kirklewis / cubelet-group.mtl
Last active March 22, 2020 14:11
Rubik's Cube Cubelet OBJ File
# Blender MTL File: 'cubelet.blend'
# Material Count: 1
newmtl Material
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000

Sequelize updateWithIncludes

A quick solution I made to update associated models dynamically. This can be taken a step further and made more generic so DirectorKey and director are based on any parent model. I am using a transaction to rollback everything when an error occurs. Just a bit of fun and it works!

Note: createdAt might be updated if supplied in the updates but this doesn't tend to happen in my case as Postman to controller validation do not allow default date fields.

The Setup

The following works fine with the exceptions:

  • it is not generic but can easily be made to be, this is from a use case I was proving.
  • it will fill missing field data with null. This can be fixed by replacing bulkCreate with a custom method to generate the [key-values] of each associate for use in VALUES but using ON DUPLICATE KEY UPDATE. This works well.