AWS Snippets

Install AWS CLI v2 $ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install AWS Documentation Generate Signed URLs with Linux Tools e.g. for accessing a website behind a CloudFront distribution using a canned policy. Write the policy file policy { "Statement": [ { "Resource": "https://xxxxxxxxxxxx.cloudfront.net/", "Condition": { "DateLessThan": { "AWS:EpochTime": 1648293147 } } } ] } Then apply the following commands[1] - you need to have OpenSSL installed. cat policy | tr -d "\n" | (1) tr -d " \t\n\r" | (2) openssl sha1 -sign private_key.pem | (3) openssl base64 -A | (4) tr -- '+=/' '-_~' (5) ...

March 1, 2018 · 2 min · 371 words · Micha Kops

JAX-RS Server API Snippets

Because a lot of my current projects are using JAX-RS in different versions I’d like to write down and share some frequently used snippets for implementing RESTful web-services with the JAX-RS specification here. Using RegEx in Path Expressions Sometimes we need to extract multiple parameters from a path expression e.g. in the following example where year, month and day are fragments if the path. @GET @Path("/orders/{year:\\d{4}}-{month:\\d{2}}-{day:\\d{2}}") @Produces(MediaType.TEXT_PLAIN) public Response getOrders(@PathParam("year") final int year, @PathParam("month") final int month, @PathParam("day") final int day) { return Response.ok("Year: " + year + ", month: " + month + ", day: " + day).build(); } ...

September 28, 2014 · 5 min · 924 words · Micha Kops

jq Snippets

Sample JSON File Sample JSON File containing well known programmers that we use for the following examples coders.json [ { "name": "Bjarne Stroustrup", "languages": [ { "name": "C++", "year_created": 1983 } ], "details": { "nationality": "Danish", "awards": ["IEEE Computer Society Computer Pioneer Award", "Charles Stark Draper Prize"] } }, { "name": "Guido van Rossum", "languages": [ { "name": "Python", "year_created": 1991 } ], "details": { "nationality": "Dutch", "awards": ["Free Software Foundation Award for the Advancement of Free Software", "NLUUG Award"] } }, { "name": "James Gosling", "languages": [ { "name": "Java", "year_created": 1995 } ], "details": { "nationality": "Canadian", "awards": ["Order of Canada", "The Economist Innovation Award"] } }, { "name": "Dennis Ritchie", "languages": [ { "name": "C", "year_created": 1972 }, { "name": "Unix", "year_created": 1969 } ], "details": { "nationality": "American", "awards": ["Turing Award", "National Medal of Technology"] } }, { "name": "Brendan Eich", "languages": [ { "name": "JavaScript", "year_created": 1995 } ], "details": { "nationality": "American", "awards": ["Webby Award"] } } ] ...

March 1, 2010 · 2 min · 223 words · Micha Kops

Postgres Snippets

Get size of a table SELECT pg_size_pretty(pg_total_relation_size('schemaname.tablename')); Select unique combination of fields / tuples SELECT DISTINCT ON(field1, field2) field1, field2 FROM thetable Select rows where a combination of fields is not unique SELECT columnA, columnB, count(*) AS count FROM thetable GROUP BY columnA, columnB HAVING count(*) > 1 Search for rows with array containing value Assuming, the field appointments has the type date[] SELECT * FROM mtable WHERE appointments @> ARRAY['2023-09-19'::date] ...

March 1, 2010 · 8 min · 1655 words · Micha Kops