Skip to content

Instantly share code, notes, and snippets.

View aaronkelton's full-sized avatar

Aaron 'Rails/Flutter' Kelton aaronkelton

View GitHub Profile
@aaronkelton
aaronkelton / main.dart
Last active May 29, 2024 19:49
How does null pass into a factory's method signature with an optional param and default value?
void main() {
Map<String, dynamic> json = {'type': null};
try {
ElementType too = ElementType.fromString(null); // passes null through (explicitly)
ElementType foo = ElementType.fromString(json['type']); // passes null through (explicitly via map)
ElementType bar = ElementType.fromString(json['key_missing']); // passes null through (implicitly via map)
ElementType baz = ElementType.fromString(); // does NOT pass null; factory uses 'default string'
HashyType bro = HashyType.fromString(stringValue: null); // passes null through (explicitly)
@aaronkelton
aaronkelton / main.dart
Created March 13, 2023 04:47
joyful-arc-1229
import 'package:flutter/material.dart';
import 'dart:math' as math;
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@aaronkelton
aaronkelton / main.dart
Created March 13, 2023 04:46
joyful-arc-1229
import 'package:flutter/material.dart';
import 'dart:math' as math;
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@aaronkelton
aaronkelton / main.dart
Created September 11, 2021 14:51
Dart Function Declaration vs. Anonymous Function in Variable Assignment
void main() {
void functionDeclaration() => print("I'm definitely declared!");
var functionAssignment = () => print("I'm ostensibly anonymous.");
functionDeclaration();
functionAssignment();
print(functionDeclaration);
print(functionAssignment);
}
import React from 'react'
import { shallow } from 'enzyme'
import HelloReact from 'packs/hello_react'
describe('HelloReact component', () => {
describe('when a name is given as a prop', () => {
it('renders Hello Aaron!', () => {
expect(shallow(<HelloReact name="Aaron" />).text()).toBe('Hello Aaron!')
})
})
@aaronkelton
aaronkelton / koans_solution_about_dice_project.rb
Created March 18, 2018 01:36
Quick Solution to Bypass about_dice_project.rb
class DiceSet
attr_reader :values
def initialize; end
def roll(i)
@values = []
i.times do
@values << rand(5)+1
end
end
end
@aaronkelton
aaronkelton / koans_solution_about_scoring_project.rb
Created March 18, 2018 01:34
Quick Solution to Bypass about_scoring_project.rb
def score(dice)
# You need to write this method
case dice
when [], [2,3,4,6] then 0
when [5] then 50
when [1] then 100
when [1,1,1] then 1000
when [2,2,2] then 200
when [3,3,3], [1,5,5,1] then 300
when [4,4,4] then 400
@aaronkelton
aaronkelton / koans_solution_triangle.rb
Created March 18, 2018 01:31
Quick Solution to Bypass about_triangle_project.rb and about_triangle_project_2.rb
# Triangle Project Code.
# Triangle analyzes the lengths of the sides of a triangle
# (represented by a, b and c) and returns the type of triangle.
#
# It returns:
# :equilateral if all sides are equal
# :isosceles if exactly 2 sides are equal
# :scalene if no sides are equal
#