Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions python/strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def slugify(text):
return "-".join(text.lower().split())


def truncate(text, limit):
if limit < 0:
raise ValueError("limit must be non-negative")
if len(text) <= limit:
return text
return text[:limit].rstrip() + "..."


def initials(full_name):
return "".join(part[0].upper() for part in full_name.split() if part)


def title_case(text):
return " ".join(word.capitalize() for word in text.split())
19 changes: 15 additions & 4 deletions typescript/nestjs/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, NotFoundException, Param, Post, UseGuards } from '@nestjs/common';
import { Roles } from '../common/decorators/roles.decorator';
import { RolesGuard } from '../common/guards/roles.guard';
import { ParseIntPipe } from '../common/pipes/parse-int.pipe';
Expand All @@ -22,11 +22,22 @@ export class CatsController {
return this.catsService.findAll();
}

@Get('count')
async count(): Promise<number> {
const cats = await this.catsService.findAll();
return cats.length;
}

@Get(':id')
findOne(
async findOne(
@Param('id', new ParseIntPipe())
id: number,
) {
// get by ID logic
): Promise<Cat> {
const cats = await this.catsService.findAll();
const cat = cats[id];
if (!cat) {
throw new NotFoundException(`No cat at index ${id}`);
}
return cat;
}
}