Skip to content

Instantly share code, notes, and snippets.

@joaquin-alfaro
joaquin-alfaro / AmazonLex.ts
Created December 6, 2023 17:02
Example of interaction with Amazon Lex
import {
DeleteSessionCommand,
DeleteSessionCommandInput,
LexRuntimeV2Client,
PutSessionCommand,
PutSessionCommandInput,
RecognizeTextCommand,
RecognizeTextCommandInput
} from '@aws-sdk/client-lex-runtime-v2'
import AWS from 'aws-sdk'
/**
* Builds training dataset
* @param root
* @param nodeType
* @param propertiesAsPrompt
* @param propertyAsCompletion
* @return
*/
private List<Example> buildTrainingData(Session session, String root, String nodeType, List<String> propertiesAsPrompt, String propertyAsCompletion) throws RepositoryException {
List<Example> examples = new ArrayList<>();
@joaquin-alfaro
joaquin-alfaro / sign-and-validate.js
Created November 4, 2022 16:01
Sign and validate signature
const assert = require('assert')
const Web3 = require('web3')
const web3 = new Web3()
const { privateKey, address: publicKey } = web3.eth.accounts.create()
// 1. Sign arbitrary text
const { signature } = web3.eth.accounts.sign('Arbitrary and random text', privateKey)
// 2. Recover public key from the signature
import graphql from "../src/cli/graphql";
function Tours({ tours }) {
return (
<div>
{
tours.map((tour)=> {
return (
<div>
<h1>{tour.name}</h1>
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import fetch from 'isomorphic-unfetch'
import gql from 'graphql-tag'
const buildClient = () => {
return new ApolloClient({
ssrMode: true,
link: createHttpLink({
@joaquin-alfaro
joaquin-alfaro / schema.graphqls
Created April 26, 2020 09:53
GraphQL field nodes
type Query {
nodes(workspace: String!, path: String): [Node]
}
type Node {
name: String,
path: String,
nodeType: String,
properties: [Property]
children: [Node]
}
@joaquin-alfaro
joaquin-alfaro / pages.graphql
Last active April 26, 2020 08:45
GraphQL schema for query pages in Magnolia CMS
directive @definition(workspace : String!, rootPath : String, nodeTypes : [String]) on FIELD_DEFINITION
schema {
query: Query,
}
type Query {
pages_ql : [Page] @definition(workspace: "website", nodeTypes: ["mgnl:page"])
}
type Page {
name(jcrName: String): String,
title: String,
@joaquin-alfaro
joaquin-alfaro / GraphQLEndpoint.java
Created April 25, 2020 15:47
Provides the endpoint that handle GraphQL queries
@Api(value = "/magnolia-rest-graphql")
@Path("/magnolia-rest-graphql")
@I18n
@Slf4j
public class GraphQLEndpoint<D extends EndpointDefinition> extends AbstractEndpoint<D> {
private static final String STATUS_MESSAGE_OK = "OK";
private static final String STATUS_MESSAGE_METHOD_NOT_ALLOWED = "Method Not Allowed";
private static final String STATUS_MESSAGE_NO_CONTENT = "No content and Not Found";
private static final String STATUS_MESSAGE_NOT_FOUND = "Not Found";
Feature: Auction bidding
Buyers bid for items on sale
Scenario: Bids higher than reserve price are accepted
Given Auction with reserve price 200000
When A buyer make a bid for 205000
Then Bid for 205000 is accepted
Scenario: Bid lower than reserve price are rejected
Given Auction with reserve price 200000
Feature: Auction opening
The auctioneer opens the auction by announcing a reserve for the item on sale.
Scenario: Auctioned items must be shown and described in detail
When Open auction for "Porsche 550 RS Spyder 1954"
Then Smart contract for Auction of "Porsche 550 RS Spyder 1954" must be created
Scenario: Auction of items with not suitable description must be rejected
When Open auction for "Car"
Then Smart contract for Auction rejected due to "Poor description"