Skip to content

Instantly share code, notes, and snippets.

View jometho's full-sized avatar

Ochieng' Steve jometho

View GitHub Profile
@leewin12
leewin12 / jpa-mysql-json.java
Last active September 7, 2022 14:10
Build JPA 2.0 CriteriaQuery with MySQL JSON column
CriteriaBuilder cb = new CriteriaBuilder();
// = SELECT * FROM entity WHERE JSON_EXTRACT("json_column", "$.path")
Root<entity> root;
cb.equal(
cb.function("JSON_EXTRACT", Integer.class, root.get("json_column"), "$.path"),
100);
@RealDeanZhao
RealDeanZhao / autowire-resttemplate.md
Last active May 23, 2023 07:45
How to autowire RestTemplate using annotations

From StackOverflow

Errors you'll see if a RestTemplate isn't defined

Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.

or

No qualifying bean of type

@Kartones
Kartones / postgres-cheatsheet.md
Last active May 7, 2024 17:48
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)
@ThomasG77
ThomasG77 / postgis_geojson.php
Created September 21, 2012 20:25 — forked from bmcbride/postgis_geojson.php
PHP PostGIS to GeoJSON
<?php
header('Content-Type: application/json; charset=UTF-8');
/**
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 7, 2024 15:24
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'