Skip to content

Instantly share code, notes, and snippets.

import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# -----------------------------------------------------
# Step 1: Generate Sample Data
# -----------------------------------------------------
# Create a date range for 10 days.
start_date = datetime(2025, 1, 1)
dates = [start_date + timedelta(days=i) for i in range(10)]
@erik4github
erik4github / spl
Last active January 21, 2025 16:34
| bin span=1d _time
| stats sum(count) AS daily_total by _time
| where _time < relative_time(now(), "d") // Exclude today for calculating historical metrics
| eventstats avg(daily_total) AS avg_total stdev(daily_total) AS stdev_total
| eval upper_bound = avg_total + (2 * stdev_total)
| eval lower_bound = avg_total - (2 * stdev_total)
| append [
search <your_base_search> earliest=-1d@d latest=@d
| bin span=1d _time
| stats sum(count) AS daily_total by _time
import logging
import requests
from requests.adapters import HTTPAdapter, Retry
from requests.exceptions import RetryError, HTTPError
# Configure basic logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def call_api_with_retries():
logger = Logger(
service="my-lambda-service", # or any service name
utc=True,
# Setting formatter_cls doesn't exist directly—pass an instance as below
logger_formatter=OtelJsonFormatter(),
# log_level="INFO", # optionally set a log level
)
@erik4github
erik4github / README.md
Created August 24, 2022 03:57
Normalize Git line endings

often I get annoying CRLF to LF issues when using an editor that doesn't let you specify default line endings like Obsidian, which is super annoying when syncing notes across devices

so here's a script to use. if you want to filter (e.g. only markdown files) you can pass it as an arg like normalize *[.md]

@erik4github
erik4github / schema.json
Last active October 15, 2021 19:24
HubSpot CMS Modules JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"title": "HubSpot Module",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The variable name you will use to refer to this field's values, and is what the value of the field is stored against. Cannot contain spaces or special characters.",
@erik4github
erik4github / OrgIsSandBoxClass.cls
Last active March 18, 2021 21:35
Determine if Salesforce org is sandbox in case there's something you need to enable on sandboxes but not prod
@TestVisible
private static Boolean orgIsSandbox {
get {
if (orgIsSandbox == null) {
orgIsSandbox = [SELECT IsSandbox FROM Organization LIMIT 1].IsSandbox;
}
return orgIsSandbox;
}
set;
}
@erik4github
erik4github / apex.json
Created March 11, 2021 22:57
Apex User Snippets for VSCode
{
"InvocableMethod": {
"prefix": "InvocableMethod",
"body": [
"@InvocableMethod(label='$1' description='$2' callout=${3|true,false|} category='$4' configurationEditor='$5')"
],
"description": "Apex InvocableMethod Annotation, @see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm"
},
"InvocableVariable": {
"prefix": "InvocableVar",
@erik4github
erik4github / Dotenv Outside Current Dir.md
Created February 18, 2021 04:19
Load dotenv .env file outside of current directory
  • /.env
    • /server/package.json

node -r dotenv/config index.ts dotenv_config_path=../.env

@erik4github
erik4github / sfdx_export
Created December 1, 2020 22:45
Export records via SFDX into CSV or JSON
#!/bin/bash
# CSV with SOQL example
sfdx force:data:soql:query -q "SELECT Name, Username, Email FROM User WHERE IsActive = True" --resultformat csv | paste -sd '\n' >| sf_users.csv
# JSON with SOQL Example
sfdx force:data:soql:query -q "SELECT Name, Username, Email FROM User WHERE IsActive = True" --resultformat json >> sf_users.json