Skip to content

Instantly share code, notes, and snippets.

View rakia's full-sized avatar

Rakia Ben Sassi rakia

View GitHub Profile
@rakia
rakia / GeminiController.java
Created February 5, 2025 15:09
A spring boot REST controller to connect to Gemini API
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/gemini")
public class GeminiController {
@Autowired
@rakia
rakia / OpenAIController.java
Created February 5, 2025 15:05
A spring boot REST controller to connect to OpenAI API
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/openai")
@rakia
rakia / build.gradle
Created February 5, 2025 15:03
The build.gradle file of my spring boot and spring AI application
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'
implementation 'org.springframework.ai:spring-ai-vertex-ai-gemini-spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
@rakia
rakia / ChatAppSpringApplication.java
Created February 5, 2025 15:01
A spring Boot and Spring AI Chat App: the main application file
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ChatAppSpringApplication {
public static void main(String[] args) {
SpringApplication.run(ChatAppSpringApplication.class, args);
}
}
@rakia
rakia / password-field.component.ts
Created December 24, 2024 19:36
Angular component: password-field
@Component({
selector: 'app-password-field',
templateUrl: './password-field.component.html',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ReactiveFormsModule, StrengthMeterComponent]
})
export class PasswordFieldComponent implements OnInit {
destroyRef = inject(DestroyRef);
@Input() passwordFormControl: FormControl = new FormControl<any>('');
@rakia
rakia / esc-field-name-already-exists.component.ts
Created July 21, 2024 19:23
Angular: Simplified logic to show real-time feedback to users when they type a name that already exists in the system
nameAlreadyExists: boolean = false;
private notifyParentComponentWhenNameChanges(): void {
this.form
?.get('name')
?.valueChanges.pipe(
takeUntilDestroyed(this.destroyRef),
debounceTime(300), // debounce user input
distinctUntilChanged()
)
@rakia
rakia / esc-field-name-already-exists.component.ts
Last active July 21, 2024 19:21
Angular: Simplified logic to show real-time feedback to users when they type a name that already exists in the system
@Component({
selector: 'app-ecs-field',
templateUrl: './ecs-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EcsFieldComponent implements OnInit, OnChanges {
private storeService = inject(EcsFieldsStoreService);
nameAlreadyExists: boolean = false;
@rakia
rakia / esc-field-name-already-exists.component.ts
Created July 21, 2024 18:56
Angular: Logic to show real-time feedback to users when they type a name that already exists in the system
@Component({
selector: 'app-ecs-field',
templateUrl: './ecs-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EcsFieldComponent {
formBuilder = inject(FormBuilder);
@Input() entity: EcsField;
@Input() nameAlreadyExists: boolean | null = false;
@rakia
rakia / esc-fieldsets-name-already-exists.component.ts
Created July 21, 2024 18:52
Angular: Logic to show real-time feedback to users when they type a name that already exists in the system
@Component({
selector: 'app-ecs-fieldset',
templateUrl: './ecs-fieldset.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EcsFieldsetComponent {
formBuilder = inject(FormBuilder);
@Input() entity: EcsFieldset;
@Input() nameAlreadyExists: boolean | null = false;
@rakia
rakia / esc-fieldset-name-already-exists.component.html
Created July 21, 2024 18:49
Angular: Logic to show real-time feedback to users when they type a name that already exists in the system
<ng-container *ngIf="isCreateMode">
<div class="mt-0">
<app-create-custom-field
[ecsFieldset]="entity.id!"
[nameAlreadyExists]="nameAlreadyExists"
(checkIfNameExists)="checkIfNameExists.emit($event)"
(cancelEdit)="cancelEdit.emit()"
(save)="createCustomField.emit($event)"
>
</app-create-custom-field>