Skip to content

Instantly share code, notes, and snippets.

@Query(value = "SELECT new com.monggopesen.mainservice.valueobject.Levels(l1.name , l2.name , l3.name ) FROM Category AS l3 \n" +
"LEFT JOIN Category AS l2 ON l3.parent = l2.secureId \n" +
"LEFT JOIN Category AS l1 ON l2.parent = l1.secureId \n" +
"WHERE l3.secureId = :secureId")
Levels findBreadCrumbLevel3(@Param("secureId") String secureId);
@Query(value = "SELECT new com.monggopesen.mainservice.valueobject.Levels(l1.name , l2.name ) FROM Category AS l2 \n" +
"LEFT JOIN Category AS l1 ON l2.parent = l1.secureId \n" +
"WHERE l2.secureId = :secureId")
Levels findBreadCrumbLevel2(@Param("secureId") String secureId);
public class Levels {
private String level1;
private String level2;
private String level3;
//setter getter here
}
@Test
public void whenSetRating_Then_RatingDetail_Total_Increment() {
reviewItem = new ReviewItem(5);
review.addReviewItem(reviewItem);
assertAll(
() -> assertEquals(1, review.findRatingDetailByRatingGroup(5).getTotal(), 0),
() -> assertNotEquals(1, review.findRatingDetailByRatingGroup(2).getTotal(), 0),
() -> {
reviewItem = new ReviewItem(5);
review.addReviewItem(reviewItem);
package designpattern.singleton;
public class DbHelper {
private static Connection connection;
public static Connection getConnection() {
if (connection == null)
connection = new Connection("localhost", "root", "root");
@mohashari
mohashari / postgres-cheatsheet.md
Created March 8, 2020 10:02 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
spring.datasource.url=jdbc:postgresql://localhost/myDatabase
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.hbm2ddl.auto=update
spring.jpa.hibernate.ejb.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.hibernate.use_sql_comments=false
@mohashari
mohashari / snippet-2.Dockerfile
Created March 14, 2026 15:12
Code snippets — Docker Containerization Best Practices
FROM node:20.11-alpine3.19@sha256:abc123...
@mohashari
mohashari / snippet-2.yaml
Created March 14, 2026 15:12
Code snippets — Kubernetes For Backend Engineers
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-api
template:
@mohashari
mohashari / snippet-2.json
Created March 14, 2026 15:12
Code snippets — Rest Api Design Principles
{
"data": [...],
"meta": {
"total": 1543,
"page": 2,
"per_page": 20,
"next_cursor": "eyJpZCI6MTIwfQ"
}
}
@mohashari
mohashari / snippet-2.txt
Created March 14, 2026 15:12
Code snippets — Graphql Vs Rest
# One request instead of 5
query DashboardData {
currentUser {
name
recentOrders(limit: 10) {
id
total
status
items { name quantity }
}