Skip to content

Instantly share code, notes, and snippets.

View brachi-wernick's full-sized avatar

Brachi Packter brachi-wernick

  • moonactive
  • Israel
View GitHub Profile
@brachi-wernick
brachi-wernick / form.html
Last active December 28, 2017 17:29
form with require if conditional validator
<h3>My children </h3>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" [(ngModel)]="hasChildren" name="hasChildren"> I do not have any children
</label>
</div>
<div class="form-group">
<label>Name</label>
@brachi-wernick
brachi-wernick / errorHandler.ts
Last active January 14, 2018 11:53
handle error
import {ErrorHandler} from "@angular/core";
import {UNAUTHORIZED, BAD_REQUEST, FORBIDDEN} from "http-status-codes";
import {Router} from "@angular/router";
import {ToastsManager, Toast, ToastOptions} from "ng2-toastr";
@Injectable()
export class myAppErrorHandler implements ErrorHandler {
static readonly REFRESH_PAGE_ON_TOAST_CLICK_MESSAGE: string = "An error occurred: Please click this message to refresh";
static readonly DEFAULT_ERROR_TITLE: string = "Something went wrong";
@brachi-wernick
brachi-wernick / remove-item-api.ts
Last active January 14, 2018 13:03
remove item with callback
private removeItem(item: Item) {
let index = this.items.indexOf(item);
//remove the item
this.items.splice(index, 1);
//call back-end server to remove the item from the DB
this.itemService.deleteItem(item.id).subscribe(
//do some stuff
,
@brachi-wernick
brachi-wernick / send-callback-to-api.ts
Created January 14, 2018 13:12
call delete item but send the callback to the api
private removeItem(item: Item) {
let index = this.items.indexOf(item);
//remove the item
this.items.splice(index, 1);
//call back-end server to remove the item from the DB
this.itemService.deleteItem(item.id,()=>this.items.splice(index, 0, item)).subscribe(
//do some stuff);
}
@brachi-wernick
brachi-wernick / http-request-with-error.ts
Created January 14, 2018 13:18
send callback on http error
public deleteItem(id: number, callback?: any): Observable<{}> {
//some prepartion of the http request...
return this.http.request(path, requestOptions)
.map((response: Response) => {
//some stuff...
}).catch((error: any) => {
error.callback=callback;
return Observable.throw(error);
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "*"
}
]
}
@brachi-wernick
brachi-wernick / AWS_IAM_role_trusted.json
Created March 8, 2018 08:21
AWS IAM role trusted json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"apigateway.amazonaws.com"
@brachi-wernick
brachi-wernick / aws-java-sdk-lambda-deps.xml
Created March 8, 2018 08:33
aws-java-sdk-lambda-deps.xml
<dependency>
<artifactId>aws-java-sdk-api-gateway</artifactId>
<groupId>com.amazonaws</groupId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
</dependency>
@brachi-wernick
brachi-wernick / createCredentials.java
Created March 8, 2018 08:35
createCredentials.java
BasicAWSCredentials awsCreds = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY);
@brachi-wernick
brachi-wernick / findAwsRestApiByName.java
Last active March 8, 2018 13:31
findAwsRestApiByName
//prepare getway object
AmazonApiGateway gateway = AmazonApiGatewayClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion(region).build();
//find all rest apis
GetRestApisResult restApis = gateway.getRestApis(new GetRestApisRequest());
//find our predefined api by name
RestApi targetRestApi = restApis.getItems().stream()
.filter(item -> item.getName().equals(targetRestApiName)).findFirst()