Skip to content

Instantly share code, notes, and snippets.

View nythrox's full-sized avatar
🌊

Jason Butler nythrox

🌊
View GitHub Profile
@nythrox
nythrox / affine-lambda-calculus.ts
Created March 10, 2024 17:42
Affine Lambda Calculus written purely in Typescript's type system
// the [Scope] of a [Expression] holds unbound variables
// in this implementation, scope works from the bottom-up:
// Var consumes declares a variable as consumed: (Var "a") :: { scope: { a: true } }
// Lambda supplies a variable, making it fresh
// Application joins the dependencies of its expressions: (Apply (Var "a") (Var "b")) :: { scope: { a: true, b: true } }
// and guarantees that its Lambda body cannot consume variables that its Argument has marked as consumed
// (Apply (Var "a") (Var "a")) will declare { a: false } so that its body can't use { a: true }
// The motivation for evaluating this bottom-up is that, on the type level, Typescript
// would require Context to be passed as a separate parameter for every single expression if evaluated top-down.

Creating Generative Art using Capi and Polkadot NFTs

In this guide we'll learn how to create algorithmically generated NFTs. We'll cover creating a Deno project, generating the images using the Canvas API, uploading them to IPFS, and minting them to Westmint using Capi.

Getting stared

In this guide we'll be using Deno, but you can also use node. If you don't have deno installed, make sure to get it installed [here].(https://deno.land/manual@v1.32.1/getting_started/installation)

To create a new Deno application, you can open your command line and run these commands to setup the project folder and create main.ts:

mkdir gen-art-nfts
@nythrox
nythrox / typography.dart
Last active August 22, 2022 16:28
Flutter custom typography with smart defaults and configuration using Dart's call() method
extension on BuildContext {
TextStyle get paragraph => TextStyle(fontSize: 22, color: Colors.grey[900]);
}
Widget build(BuildContext context) {
return Column(
children: [
Text("Hello world", style: context.paragraph),
Text("Hello world, again", style: context.paragraph(color: Colors.red)),
],
@nythrox
nythrox / pipeline.js
Last active July 29, 2022 14:08
Javascript pipeline operator using global mutable underline (_) variable
const envars = { secret: "hello world" }
const stringifyEnv = (env) => {
_= env
_= Object.keys(_)
_= _.map(envar => `${envar}=${envars[envar]}`)
_= _.join('&')
return _
}
@nythrox
nythrox / do.ts
Last active May 5, 2022 19:17
Typescript do notation (using generator functions)
// user: Either<string, { name: string, age: number }>
const user = doEither(function*() {
// name: string
const name = yield* Right("test")
// age: number
const age = Math.random() > 0.5 ? yield* Right(100) : yield* Left("oopsies")
return {
name,
age
}
@nythrox
nythrox / auto_immutability.dart
Created April 4, 2021 16:35
Automatic Immutability in Dart using noSuchMethod() with no build_runner
main() {
setupImmutable(() => User());
final user1 = create(User()
..name = "uwu"
..age = 100);
final user2 = copy(user1..name = "owo"..child = User());
final user3 = copy(user2..name = "eheh");
@nythrox
nythrox / mobx_dart_extensions.dart
Last active January 26, 2024 06:21
MobX dart extensions to avoid build_runner
void main() {
mainContext.config = mainContext.config.clone(writePolicy: ReactiveWritePolicy.never);
runApp(MyApp());
}
class TestCounterStore {
// ObservableInt
final count = 0.obs;
// ObservableString
final name = "olá".obs;
@nythrox
nythrox / pattern_matching.dart
Last active January 23, 2023 06:21
Flutter/Dart pattern matching
void main() {
Greeting message = Hi();
final result = match(message, {
on((Hi hi) => "hello, ${hi.name}"),
on((Bye bye) => "bye, see you at ${bye.seeYouAgain}"),
otherwise(() => throw Error()),
});
print(result);
@nythrox
nythrox / do_notation.dart
Last active January 23, 2023 06:23
Flutter/Dart do notation
main() {
// Either<dynamic, int> result
final result = Either.Do(() {
final num1 = perform(Right(5));
final num2 = perform(Right(2));
return num1 * num2;
});
print(result.value); // 10
// Option<int> result2
final result2 = Option.Do(() {
@nythrox
nythrox / do_notation_future.dart
Last active January 23, 2023 06:23
Dart await/async using Future and do notation
main() {
final value = async(() {
final num1 = await(Future.value(5));
final num2 = await(Future.value(2));
return num1 * num2;
});
value.then(print).catchError(print);
async(() {
[1,2,3,4,5].forEach((i) {