Skip to content

Commit

Permalink
2024-12-04 17:13:54.644919 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Dec 4, 2024
1 parent f8f753e commit 50ecff0
Show file tree
Hide file tree
Showing 21 changed files with 1,462 additions and 675 deletions.
35 changes: 35 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
--------------------------------------------------------------------------------
2024-12-04 17:13:54.644919
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: snippet/amcrest.py
deleted: snippet/build.sh
deleted: snippet/diamond.py
deleted: snippet/digitalioe9.py
deleted: snippet/quickstart.py
deleted: snippet/server_compare.py
deleted: snippet/tmux-sessionizer.sh

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/AdditionalPropertiesExtractor.java
snippet/Main.java
snippet/SecurityEvent.java
snippet/class.py
snippet/code.java
snippet/create_flux_wireguard.sh
snippet/decorator_example.py
snippet/headline.zsh
snippet/main.py
snippet/python_logging.py
snippet/seeds.py
snippet/test.java
snippet/tmux.conf

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------
2024-12-03 17:14:56.419452
--------------------------------------------------------------------------------
Expand Down
52 changes: 52 additions & 0 deletions seeker/snippet/AdditionalPropertiesExtractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//date: 2024-12-04T16:51:06Z
//url: https://api.github.com/gists/cf0f9afbcf359df65846a760da64d230
//owner: https://api.github.com/users/avishaybp81

package com.example.additionalproperties;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;


public class AdditionalPropertiesExtractor {

public static Map<String, String> extractAdditionalProperties(Object obj) {
Map<String, String> allProperties = new HashMap<>();
processObject(obj, allProperties, "");
return allProperties;
}

private static void processObject(Object obj, Map<String, String> allProperties, String prefix) {
if (obj == null) {
return;
}

if (obj instanceof Map) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) {
allProperties.put(prefix + "." + entry.getKey(), entry.getValue().toString());
}

} else {
for (Field field : obj.getClass().getDeclaredFields()) {
if (field.getType().getPackage().equals(SecurityEvent.class.getPackage()) || field.getType().equals(Map.class)) {
try {
field.setAccessible(true);
} catch (Exception ignored) {
continue;
}
try {
Object fieldValue = field.get(obj);
System.out.println("--->: " + fieldValue.getClass().getSimpleName() + " : " + fieldValue);
processObject(fieldValue, allProperties, obj.getClass().getSimpleName());
} catch (IllegalAccessException e) {
// Handle exception, e.g., log the error
e.printStackTrace();
}

}

}
}
}
}
58 changes: 58 additions & 0 deletions seeker/snippet/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//date: 2024-12-04T16:51:06Z
//url: https://api.github.com/gists/cf0f9afbcf359df65846a760da64d230
//owner: https://api.github.com/users/avishaybp81

package com.example.additionalproperties;

import com.example.additionalproperties.SecurityEvent;
import com.example.additionalproperties.AdditionalPropertiesExtractor;

import java.util.HashMap;
import java.util.Map;

public class Main {
public static void main(String[] args) {
SecurityEvent event = new SecurityEvent();
event.setEventId("event123");
event.setEventType("security_event");

// Set top-level additional properties
Map<String, String> topLevelProps = new HashMap<>();
topLevelProps.put("prop1", "value1");
topLevelProps.put("prop2", "value2");
event.setAdditionalProperties(topLevelProps);

// Create nested event
SecurityEvent.NestedSecurityEvent nestedEvent = new SecurityEvent.NestedSecurityEvent();
nestedEvent.setNestedId("nested123");
nestedEvent.setNestedType("nested_event");

// Set nested additional properties
Map<String, String> nestedProps = new HashMap<>();
nestedProps.put("nestedProp1", "nestedValue1");
nestedProps.put("nestedProp2", "nestedValue2");
nestedEvent.setAdditionalProperties(nestedProps);

// Create deeply nested event
SecurityEvent.NestedSecurityEvent.DeeplyNestedSecurityEvent deeplyNestedEvent = new SecurityEvent.NestedSecurityEvent.DeeplyNestedSecurityEvent();
deeplyNestedEvent.setDeeplyNestedId("deeplyNested123");
deeplyNestedEvent.setDeeplyNestedType("deeplyNested_event");

// Set deeply nested additional properties
Map<String, String> deeplyNestedProps = new HashMap<>();
deeplyNestedProps.put("deeplyNestedProp1", "deeplyNestedValue1");
deeplyNestedProps.put("deeplyNestedProp2", "deeplyNestedValue2");
deeplyNestedEvent.setAdditionalProperties(deeplyNestedProps);

nestedEvent.setDeeplyNestedEvent(deeplyNestedEvent);
event.setNestedEvent(nestedEvent);

// Extract additional properties
Map<String, String> extractedProps = AdditionalPropertiesExtractor.extractAdditionalProperties(event);

// Print extracted properties

System.out.println("Result below:");
extractedProps.forEach((key, value) -> System.out.println("\t" + key + ": " + value));
}
}
121 changes: 121 additions & 0 deletions seeker/snippet/SecurityEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//date: 2024-12-04T16:51:06Z
//url: https://api.github.com/gists/cf0f9afbcf359df65846a760da64d230
//owner: https://api.github.com/users/avishaybp81

package com.example.additionalproperties;

import java.util.Map;

public class SecurityEvent {
private String eventId;
private String eventType;
private Map<String, String> additionalProperties;
private NestedSecurityEvent nestedEvent;

// Getters and Setters
public String getEventId() {
return eventId;
}

public void setEventId(String eventId) {
this.eventId = eventId;
}

public String getEventType() {
return eventType;
}

public void setEventType(String eventType) {
this.eventType = eventType;
}

public Map<String, String> getAdditionalProperties() {
return additionalProperties;
}

public void setAdditionalProperties(Map<String, String> additionalProperties) {
this.additionalProperties = additionalProperties;
}

public NestedSecurityEvent getNestedEvent() {
return nestedEvent;
}

public void setNestedEvent(NestedSecurityEvent nestedEvent) {
this.nestedEvent = nestedEvent;
}

// NestedSecurityEvent Class
public static class NestedSecurityEvent {
private String nestedId;
private String nestedType;
private Map<String, String> additionalProperties;
private DeeplyNestedSecurityEvent deeplyNestedEvent;

// Getters and Setters
public String getNestedId() {
return nestedId;
}

public void setNestedId(String nestedId) {
this.nestedId = nestedId;
}

public String getNestedType() {
return nestedType;
}

public void setNestedType(String nestedType) {
this.nestedType = nestedType;
}

public Map<String, String> getAdditionalProperties() {
return additionalProperties;
}

public void setAdditionalProperties(Map<String, String> additionalProperties) {
this.additionalProperties = additionalProperties;
}

public DeeplyNestedSecurityEvent getDeeplyNestedEvent() {
return deeplyNestedEvent;
}

public void setDeeplyNestedEvent(DeeplyNestedSecurityEvent deeplyNestedEvent) {
this.deeplyNestedEvent = deeplyNestedEvent;
}

// DeeplyNestedSecurityEvent Class
public static class DeeplyNestedSecurityEvent {
private String deeplyNestedId;
private String deeplyNestedType;
private Map<String, String> additionalProperties;

// Getters and Setters
public String getDeeplyNestedId() {
return deeplyNestedId;
}

public void setDeeplyNestedId(String deeplyNestedId) {
this.deeplyNestedId = deeplyNestedId;
}

public String getDeeplyNestedType() {
return deeplyNestedType;
}

public void setDeeplyNestedType(String deeplyNestedType) {
this.deeplyNestedType = deeplyNestedType;
}

public Map<String, String> getAdditionalProperties() {
return additionalProperties;
}

public void setAdditionalProperties(Map<String, String> additionalProperties) {
this.additionalProperties = additionalProperties;
}
}
}
}

115 changes: 0 additions & 115 deletions seeker/snippet/amcrest.py

This file was deleted.

Loading

0 comments on commit 50ecff0

Please sign in to comment.