Skip to content

Instantly share code, notes, and snippets.

View j1n3l0's full-sized avatar

Nelo Onyiah j1n3l0

  • Goznel Limited
  • Kent UK
  • 13:22 (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 / 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'
@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 / gist:1798837
Created February 11, 2012 11:15
Clojure Protocols #clojure
(defprotocol Foo
"Does Foolike things"
(bar [a b] "does stuff with a & b")
(baz [a] "does stuff with a"))
(extend-protocol Foo
nil
(bar [_ _] nil)
(baz [_] nil)
@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();
{
"$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 / override-isa.t
Created August 19, 2020 10:58
Override the response to ->isa fot Test2 mock objects
use Test2::V0;
subtest 'Overriding "isa" on a mock object' => sub {
isa_ok(
mock( {}, override => [ isa => sub { pop eq 'Foo' } ] ),
['Foo'],
'should correctly respond to "isa"',
);
};
@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 => (