Skip to content

Instantly share code, notes, and snippets.

View BetterProgramming's full-sized avatar

BetterProgramming

View GitHub Profile
function calcAge(
input: Date | null | undefined | string | Person | Car
): number {
if (!input) {
return 0;
} else if (typeof input === "string") {
return diffInYears(parse(input));
} else if (input instanceof Date) {
return diffInYears(input);
} else if (input.type === "Car") {
type Person = {
birthday: Date;
category: "person";
};
type Car = {
yearOfConstruction: Date;
category: "car";
};
function calcAge(
input: Date | null | undefined | string | Person | Car
function calcAge(input: Date | null | undefined | string | Person): number {
if (!input) {
return 0;
} else if (typeof input === "string") {
return diffInYears(parse(input));
} else if (input instanceof Date) {
return diffInYears(input);
} else {
return diffInYears(input.birthday);
}
class Person {
birthday = new Date();
}
function calcAge(input: Date | null | undefined | string | Person): number {
if (!input) {
return 0;
} else if (typeof input === "string") {
return diffInYears(parse(input));
} else {
return diffInYears(input); // failure: can be Date or Person
[HttpPost]
public async Task<IActionResult> GenerateImage([FromBody] input input)
{
var resp = new ResponseModel();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", APIKEY);
var Message= await client.
val h1 = MaterialTheme.typography.h1
val h2 = MaterialTheme.typography.h2
val h3 = MaterialTheme.typography.h3
var textStyle by remember { mutableStateOf(h1) }
val animatedTextStyle by animateTextStyleAsState(
targetValue = textStyle,
spring(stiffness = Spring.StiffnessLow)
)
@Composable
fun animateTextStyleAsState(
targetValue: TextStyle,
animationSpec: AnimationSpec<Float> = spring(),
finishedListener: ((TextStyle) -> Unit)? = null
): State<TextStyle> {
val animation = remember { Animatable(0f) }
var previousTextStyle by remember { mutableStateOf(targetValue) }
var nextTextStyle by remember { mutableStateOf(targetValue) }
val scope = rememberCoroutineScope()
// Setup animatable float to use in the lerp function
val animation = remember {
Animatable(0f)
}
val h1 = MaterialTheme.typography.h1
val h2 = MaterialTheme.typography.h2
// derive the current TextStyle based on the animation position
val textStyle by remember(animation.value) {
type AddBitsWithCarry<
LHS extends Bit,
RHS extends Bit,
CF extends CarryFlag = Zero
> = LHS extends One
? RHS extends One
? CF extends One
? { value: One; cf: One }
: { value: Zero; cf: One }
: CF extends One
const requestOptions = {
method: "PUT",
headers: { "Content-Type": "multipart/form-data" },
body: selectedFile,
};
//Perform the upload
fetch(fileLocation, requestOptions)
.then((response) => {
if (response.status === 200) resolve(true);
else resolve(false);