Skip to content

Instantly share code, notes, and snippets.

View nicowernli's full-sized avatar
🏠
Working from home

Nicolás Wernli nicowernli

🏠
Working from home
  • Málaga, Spain
  • 22:06 (UTC +02:00)
  • LinkedIn in/nwernli
View GitHub Profile
@nicowernli
nicowernli / app_config.dart
Created December 11, 2019 12:27
Flutter AppConfig for differente flavors
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class AppConfig extends InheritedWidget {
AppConfig({
@required this.flavorName,
@required this.apiBaseUrl,
@required Widget child,
}) : super(child: child);
@nicowernli
nicowernli / app.module.ts
Created March 28, 2019 11:36
Adds http interceptros to a module
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';
import {AppComponent} from './app.component';
import {BaseURLInterceptor} from './services/base-url.interceptor';
import {HttpErrorInterceptor} from './services/http-error.interceptor';
@NgModule({
declarations: [ AppComponent ],
@nicowernli
nicowernli / http-error.interceptor.ts
Last active March 28, 2019 11:28
An error interceptor to manage all HTTP errors in a single way
import {Injectable} from '@angular/core';
import {HttpHandler, HttpRequest, HttpInterceptor} from '@angular/common/http';
import {throwError} from 'rxjs';
import {catchError} from 'rxjs/internal/operators';
import {ErrorService} from '../my-services/error.service';
@Injectable({
providedIn: 'root'
})
export class HttpErrorInterceptor implements HttpInterceptor {
@nicowernli
nicowernli / base-url.interceptor.ts
Last active March 28, 2019 11:39
Simple HttpInterceptor that adds a header to a request
import { Injectable } from '@angular/core';
import {HttpHandler, HttpRequest, HttpInterceptor} from '@angular/common/http';
import {environment} from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class BaseURLInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler) {
if (!req.url.match(/^http(s)?:\/\/(.*)$/)) {
// GetItem finds a returns a single item from a dynamodb table.
// It returns an element and an error if any.
// If no element is found, will return nil without an error
func GetItem(id string, dest interface{}) error {
tableName := "table-name"
// create get operation information
item := &dynamodb.GetItemInput{
TableName: aws.String(tableName),
Key: map[string]*dynamodb.AttributeValue{
@nicowernli
nicowernli / search-bar.component.ts
Created August 31, 2018 10:16
Debounce time included
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { switchMap, debounceTime } from 'rxjs/operators';
import { PlanetService } from '../planet.service';
import { Planet } from '../planet';
@Component({
selector: 'app-search-bar',
templateUrl: './search-bar.component.html'
@nicowernli
nicowernli / search-bar.component.html
Created August 31, 2018 09:58
Search bar component template
<div class="p-4">
<p class="mb-2">search-bar works!</p>
<div class="relative">
<input [formControl]="search" type="text" class="border border-grey rounded shadow-inner p-2 w-full" placeholder="Search...">
<div class="absolute mt-1 bg-grey w-full rounded shadow">
<ul class="list-reset">
<li *ngFor="let planet of (planets$ | async)" class="p-2">{{ planet.name }}</li>
</ul>
</div>
@nicowernli
nicowernli / searc-bar.component.ts
Created August 31, 2018 09:54
The Search Bar Component base
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { PlanetService } from '../planet.service';
import { Planet } from '../planet';
@Component({
selector: 'app-search-bar',
templateUrl: './search-bar.component.html'
@nicowernli
nicowernli / app.module.ts
Created August 31, 2018 07:52
App Module with ReactiveForms
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { SearchBarComponent } from './search-bar/search-bar.component';
import { PlanetService } from './planet.service';
@NgModule({
@nicowernli
nicowernli / planet.ts
Last active August 31, 2018 10:56
Planet interface
export interface Planet {
name: string;
rotation_period: number;
orbital_period: number;
diameter: number;
climate: string;
gravity: string;
terrain: string;
surface_water: number;
population: number;