Skip to content

Instantly share code, notes, and snippets.

View j1n3l0's full-sized avatar

Nelo Onyiah j1n3l0

  • Goznel Limited
  • Kent UK
  • 02:39 (UTC -12:00)
View GitHub Profile
@j1n3l0
j1n3l0 / inherit-private-attribute.t
Created April 11, 2024 09:59
Inherit private attributes in Object::Pad
use Test2::V0;
use Object::Pad 0.808;
class Power {
field $_power :inheritable = 0;
method of ($number) { $number ** $_power };
};
class Square {
inherit Power '$_power';
@j1n3l0
j1n3l0 / install-dev-utilities.bash
Created January 16, 2023 16:10
Install the dev utilities I need
#!/bin/bash
set -euxo pipefail
#
# Install the dev utilities I need
# emacs (blead)
if ! [ -x "$(command -v emacs)" ]; then
# I needed these dependencies (you might not)
@j1n3l0
j1n3l0 / stubs.t
Created March 2, 2022 13:24
Using stubs in Test2
use Test2::V0;
subtest 'Using stubs in Test2' => sub {
my $user = mock { company => 'dev' };
my $userdata = mock { day => '2022-02-02' };
my $stats = mock { user => $user, userdata => $userdata };
is( $stats->user->company, 'dev',
'should return the right value for $stats->user->company',
);
@j1n3l0
j1n3l0 / scratch-ts-project.bash
Last active March 19, 2024 23:37
Set up a new development typescript project
#!/bin/bash
set -euxo pipefail
git init
npm init -y
npm install -D depcheck eslint eslint-config-prettier eslint-plugin-jsdoc eslint-plugin-json eslint-plugin-prettier husky lint-staged prettier
npm pkg set scripts.depcheck='depcheck'
npm pkg set scripts.lint-staged='lint-staged --allow-empty'
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"additionalProperties": false,
"properties": {
"client_id": {
"type": "string"
},
"source_id": {
"type": "string"
}
@j1n3l0
j1n3l0 / types-from-schemas.t
Last active October 19, 2021 10:19
Experiments with building Type::Tiny types from JSON schemas
BEGIN {
package MyTypes;
use Type::Library -extends => ['Types::Standard'], -declare => qw< Transaction >;
use Type::Utils -all;
use JSON::Schema::AsType;
my $schema_uri
= 'https://gist.githubusercontent.com/j1n3l0/43676471d8121bfbce2835119201b3ed/'
@j1n3l0
j1n3l0 / check-value-against-set-of-outcomes.t
Last active November 2, 2021 15:49
Use check_set to check a value is as expected and its type is also as expected
BEGIN {
package MyTypes;
use Type::Library -extends => ['Types::Standard'], -declare => qw< Error >;
use Type::Utils -all;
declare Error, as Dict [ error => Str ];
__PACKAGE__->meta->make_immutable();
const chai = require('chai');
const chaiHttp = require('chai-http');
const nock = require('nock');
const axios = require('axios');
chai.use(chaiHttp);
const { expect, request } = chai;
class Client {
@j1n3l0
j1n3l0 / Client.pm
Created March 17, 2021 11:10
Trying to avoid mutating a readonly attribute
package Client;
use Moo;
use Type::Utils qw< class_type >;
use Types::Standard -types;
use URI;
use experimental qw< signatures >;
has service_uri => (
@j1n3l0
j1n3l0 / undef.t
Last active March 3, 2021 08:04
Coerce an attribute from Undef|EmptyStr to a default value
use Test2::V0;
package Api::Client 1.0 {
use Moose;
use Moose::Util::TypeConstraints;
use Readonly;
Readonly my $DEFAULT_HOSTNAME => 'api.example.com';
subtype 'EmptyStr', as 'Str', where { /^$/ };