Skip to content

Instantly share code, notes, and snippets.

View louwersj's full-sized avatar
🏠
Working from home

Johan Louwers louwersj

🏠
Working from home
View GitHub Profile
@louwersj
louwersj / bash_remove_columns.md
Created January 17, 2023 20:25
BASH - Remove columns from a file

You can use the command cut to remove specific columns from a file. The basic syntax for removing columns is:

cut -f <column numbers> -d <delimiter> <input file> > <output file>

To remove all columns except the first and third columns from a file that is semicolon-separated, you would use the following command:

@louwersj
louwersj / LAC-service_kubernetes.py
Created November 17, 2021 12:55
Show Last applied config on service with kubectl in kubernets
from kubernetes import client, config
import json
def k8sGetServiceDetails(targetNameSpace):
v1Client = client.CoreV1Api()
servicesList = v1Client.list_namespaced_service(targetNameSpace)
for service in servicesList.items:
if service.metadata.annotations is not None:
servicePorts = ((json.loads(service.metadata.annotations["kubectl.kubernetes.io/last-applied-configuration"]))["spec"]["ports"])
serviceName = ((json.loads(service.metadata.annotations["kubectl.kubernetes.io/last-applied-configuration"]))["metadata"]["name"])
from kubernetes import client, config
# Load the connection config, default behaviour is to load ~/.kube/config
# For development this is fine, when moving into production another way
# of providing the config is required
config.load_kube_config()
v1 = client.CoreV1Api()
nameSpaceList = v1.list_namespace()
for nameSpace in nameSpaceList.items:
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "test-deploy-2",
"labels": {
"name": "test-deploy-2",
"stage": "test",
"production": "no"
}
package com.cegCloudNative.AdminServer;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AdminServerApplicationTests {
@Test
void contextLoads() {
package com.cegCloudNative;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@louwersj
louwersj / additional_error_catching.py
Created December 7, 2020 08:21
additional error catching
# Check the azureApiResponse code, taking into account the value of funcFailure. If the function has failed in an
# step before there is no need to do this check.
if funcFailure:
funcFailure = True
else:
# if response status code from the Azure API is between 200 and 299 we can assume the message has been received
# on the azure side and we can assume the sharing of the payload has been a success.
if (azureApiResponse.status_code >= 200 and azureApiResponse.status_code <= 299):
print('Accepted')
{
"meta_data": {
"payload_encoding": "base64",
"payload_encryption": "none",
"payload_encoded": true,
"payload_encrypted": false
},
"event_data": {
"event_id": "1234567890ABC",
"event_generated": "1589549929",
import base64
import json
import re
import shlex
#TODO (0) at current we fake the input with a local file, this needs to be a true http request based trigger in the future
#TODO (1) need to include error handling on all levels. (don on occasion already)
#TODO (2) implement decryption function
#TODO (3) ensure we will publish a error to error stream when we catch an exception. (could you publishEvent for this)