Skip to content

Instantly share code, notes, and snippets.

View avishaybp81's full-sized avatar

Avishay Balderman avishaybp81

View GitHub Profile
@avishaybp81
avishaybp81 / invalid.ts
Created February 16, 2025 08:12
Invalid TS code snippet
function is_valid_ts(x,y) {
return "dont think so"
}
function isValidTs(x: string[], y: string): boolean {
return x.length > 0 && x[0] === y && x[x.length - 1] === y;
}
@avishaybp81
avishaybp81 / file_system.py
Created February 15, 2025 22:11
File System
from dataclasses import dataclass, field
from typing import List, Optional
@dataclass(order=True)
class File:
sort_index: int = field(init=False, repr=False)
name: str
size: int = 0
is_folder: bool = False
@avishaybp81
avishaybp81 / AdditionalPropertiesExtractor.java
Created December 4, 2024 16:51
Collect "additional properties" from SecurityEvent Object Graph
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) {
from dataclasses import dataclass
import os
import time
from pymongo import MongoClient
import sqlite3
@dataclass
class FieldMeta:
{
"keys": {
1: "Make",
2: "Model",
3: "Year",
4: "Color",
5: "Mileage",
6: "Price",
7: "Engine",
8: "Fuel Type"
@avishaybp81
avishaybp81 / 2a_lambda.py
Last active August 13, 2024 07:53
2_a_mock_python
import json
import boto3
NOT_FOUND = 'NOT_FOUND'
def get_permissions_for_endpoint_identity(endpoint_identity: str) -> set[str]:
try:
client = boto3.client('dynamodb')
response = client.get_item(TableName='2a_permission_table',
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_api import LogsApi
from datadog_api_client.v2.model.content_encoding import ContentEncoding
from datadog_api_client.v2.model.http_log import HTTPLog
from datadog_api_client.v2.model.http_log_item import HTTPLogItem
from datadog_api_client.model_utils import unset
from datadog_api_client.v2.api.metrics_api import MetricsApi
from datadog_api_client.v2.model.metric_payload import MetricPayload
class DataDogClient:
@avishaybp81
avishaybp81 / fake_2a_lambda.py
Last active March 28, 2024 18:03
Adding the second 'A' to '2A' Lambda
# A simple token-based authorizer example to demonstrate how to use an authorization token
# to allow or deny a request. In this example, the caller named 'user' is allowed to invoke
# a request if the client-supplied token value is 'allow'. The caller is not allowed to invoke
# the request if the token value is 'deny'. If the token value is 'unauthorized' or an empty
# string, the authorizer function returns an HTTP 401 status code. For any other token value,
# the authorizer returns an HTTP 500 status code.
# Note that token values are case-sensitive.
import json
import boto3
@avishaybp81
avishaybp81 / guard_ip_pool_modified.go
Last active February 3, 2024 19:12
guard_ip_pool
func CreateListOfIPsForIPPool(excludedIPs []string, deviceIPv4Range string) ([]string, error) {
_, cidr, err := net.ParseCIDR(deviceIPv4Range)
if err != nil {
return nil, fmt.Errorf("failed parsing cidr of device [%s]: %w", deviceIPv4Range, err)
}
// Sort excludedIPs once for efficient binary search
sort.Strings(excludedIPs)
var ipPoolAddresses []string
@avishaybp81
avishaybp81 / get_user.ts
Created November 10, 2023 19:13
A strongly types - pure TS Lambda function
import { Context } from 'aws-lambda';
// Define the UserID interface
interface UserID {
id: string;
}
// Define the UserDetails interface
interface UserDetails {
userId: string;