Skip to content

Instantly share code, notes, and snippets.

View Tonel's full-sized avatar

Antonello Zanini Tonel

View GitHub Profile
// extracting the first tuple from the list
Tuple bookGenreTuple = bookGenreTuples.get(0);
// getting the first element of the tuple
// and converting it into a Book object
Book book = bookGenreTuple.get(0, Book.class);
// getting the second element of the tuple
// and converting it into a Genre object
Genre genre = bookGenreTuple.get(1, Genre.class);
// initializing the CriteriaBuilder and CriteriaQuery object
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
// if you want to perform a multiselect() you need define
// a CriteriaQuery with the Tuple type
CriteriaQuery<Tuple> criteriaQuery = criteriaBuilder.createQuery(Tuple.class);
Root<Book> root = criteriaQuery.from(Book.class);
// defining the JOIN clauses
Join<Book, Author> author = root.join("authors");
Join<Book, Genre> genre = root.join("genres");
// initializing the CriteriaBuilder and CriteriaQuery object
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Book> criteriaQuery = criteriaBuilder.createQuery(Book.class);
Root<Book> root = criteriaQuery.from(Book.class);
// defining the JOIN clauses
Join<Book, Author> author = root.join("authors");
Join<Book, Genre> genre = root.join("genres");
// specifying the WHERE conditions
web: node server.js
const express = require("express");
const path = require("path");
const app = express()
const PORT = process.env.PORT || 3000
app.use(express.static(path.join(__dirname, "build")))
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"))
@Tonel
Tonel / headers.js
Last active October 14, 2022 14:52
res
.set({
"Content-Type": "text/csv",
"Content-Disposition": `attachment; filename="<YOUR_FILE_NAME>.csv"`,
})
const express = require("express")
const app = express()
app.get("/users/getCSV", function (req, res) {
// retrieving the user with a query...
const users = [
{ name: "Patricia", surname: "Smith", age: null },
{ name: "John", surname: null, age: 56 },
{ name: "Maria", surname: "Brown", age: 37 },
@Tonel
Tonel / build.sh
Created September 15, 2022 14:49
# removing the .env.local file because
# next uses it if it is present
rm -f ./.env.local
# if this is the staging deployment environment
if test "$ENV" = "staging"
then
# removing the .env.production file
# because otherwise next would use it
# as the default .env file
@Tonel
Tonel / build.sh
Created September 15, 2022 14:08
# removing the .env.local file because
# react-scripts uses it if it is present
rm -f ./.env.local
# if this is the staging deployment environment
if test "$ENV" = "staging"
then
# removing the .env.production file
# because otherwise react-scripts would use it
# as the default .env file
const array1 = [];
// adding 100k elements to array1
for (let i = 0; i < 500000; i++) {
array1.push(i);
}
// creating a copy of the array1 variable
const array2 = [];
// adding one element at a time