Skip to content

Instantly share code, notes, and snippets.

View teomanofficial's full-sized avatar

Hasan Teoman Tıngır teomanofficial

View GitHub Profile
function pullOut(array &$arr, ...$parameters)
{
$result = [];
foreach ($parameters as $key => $parameter) {
$result[$key] = $arr[$parameter];
unset($arr[$parameter]);
}
return $result;
}
@teomanofficial
teomanofficial / select2.js
Created November 30, 2019 22:33
Common select2 examples
// load data by another event (on parent change)
$("#parent").on("change", function (e) {
$.ajax({
url: '/api' + e.target.value,
dataType: "json",
success: function (data) {
$("#child").select2({
data: data,
allowClear:true,
// fixed width and height
$('#banner').cropper({
movable: false,
resizable: false,
rotatable: false,
dragCrop: false,
dragMode: 'move',
cropBoxResizable: false,
responsive: true,
this.authService.login(request)
.subscribe((response) => {
localStorage.setItem('access_token', response.token);
this.router.navigate('/')
});
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
export function appendToken(req: HttpRequest<any>, token: string) {
return req.clone({
headers: req.headers.set('Authorization', `Bearer ${token}`)
});
}
// HTTP_INTERCEPTORS injection token'ini import etmeyi unutmayın!
import { HTTP_INTERCEPTORS } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
],
imports: [
CoreModule,
AppRoutingModule
@teomanofficial
teomanofficial / error-handler.interceptor.ts
Last active August 31, 2022 06:41
Setup Global Error Handler Using Interceptor
// Imports
@Injectable({ providedIn: 'root' })
export class ErrorHandlerInterceptor implements HttpInterceptor {
constructor(private readonly validationErrorService: ValidationErrorsService) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req)
.pipe(catchError(event => {
@teomanofficial
teomanofficial / elastic-logger.interceptor.ts
Created August 31, 2022 07:11
Angular - Log request and response details to elastic
// Imports..
@Injectable({ providedIn: 'root' })
export class ElasticLogInterceptor implements HttpInterceptor {
constructor(private logger: ElasticService) {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
export declare interface ControlValueAccessor {
writeValue(obj: any): void;
registerOnChange(fn: any): void;
registerOnTouched(fn: any): void;
setDisabledState?(isDisabled: boolean): void;
}
setDisabledState(isDisabled: boolean): void {
this.renderer.setProperty(this.input.nativeElement, 'disabled', isDisabled);
}