Skip to content

Instantly share code, notes, and snippets.

@wh13371
wh13371 / GETOPT.c
Created July 2, 2026 11:38
C - getopt() example
#include <stdio.h> /* printf() */
#include <getopt.h> /* getopt() */
#include <stdbool.h> /* bool type */
#include <stdlib.h> /* atoi() & EXIT_FAILURE */
bool is_verbose = false;
void usage(const char *prog_name) {
printf("Usage: %s [-h/--help] [-v/--verbose] [-p/--port PORT] [-t/--time[=FORMAT]]\n", prog_name);
}
@wh13371
wh13371 / timestamp.c
Created June 20, 2026 08:51
c timestamp
#include <stdio.h> // printf()
#include <time.h> // time()
#include <sys/time.h> // localtime()
char timestamp[28];
char *now() {
time_t t = time(NULL);
struct tm* local_time = localtime(&t);
struct timeval epoch;
@wh13371
wh13371 / pid.c
Created June 19, 2026 10:27
get the process ID
#include <stdio.h> // printf()
#include <time.h> // time()
#include <unistd.h> // getpid()
int main() {
int PID = (int)getpid();
printf("pid = %d\n", PID);
@wh13371
wh13371 / epoch.c
Created June 19, 2026 10:23
get the number of seconds since 1/1/1970
#include <stdio.h>
#include <time.h>
int main() {
int epoch_seconds = (int)time(NULL);
printf("epoch = %d\n", epoch_seconds);
return 0;
@wh13371
wh13371 / hello_world.c
Last active June 19, 2026 10:18
hello_world.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
@wh13371
wh13371 / har.sh
Created March 18, 2022 12:21
use jq to delete data from a .har file
cat my.har | jq 'del(.log.entries[].response.content.text)' | jq 'del(.log.entries[].request.headers[])'
#! /bin/bash
_LOGFILE=/home/genesys/.@/$0.log
_NOW=$(date +"%Y-%m-%d %H:%M:%S.%6N")
_EPOCH=$(date +"%s.%6N")
_NOW_UTC=$(date --utc +%FT%T.%6N%Z)
_MSG="test message @ $_NOW_UTC"
_LOG="$(printf '{"timestamp": "%s", "epoch": "%s", "timestamp_utc": "%s", "message": "%s"}' "${_NOW}" "${_EPOCH}" "${_NOW_UTC}" "${_MSG}")"
@wh13371
wh13371 / send_scs_to_mattermost.py
Created December 22, 2020 13:51
send scs alarm data to Mattermost
def send_to_mattermost(mm_url, mm_channel, mm_username, redis_id, redis_data):
_text = {'@timestamp': get_now_iso(),
'epoch': int(get_epoch()),
"condid": int(redis_data.get(b'condid').decode()),
"condname": redis_data.get(b'condname').decode(),
"conddesc": redis_data.get(b'conddesc').decode(),
"msgid": int(redis_data.get(b'msgid').decode()),
"msgtext": redis_data.get(b'msgtext').decode(),
"appid": int(redis_data.get(b'appid').decode()),
@wh13371
wh13371 / send_scs_to_influxdb.py
Last active December 22, 2020 13:56
send scs alarm data to InfluxDB
def send_to_influxdb(redis_id, redis_data):
_data = [{
"measurement": "scs.alarms",
"tags": {
"host": redis_data.get(b'hostname'),
"app": redis_data.get(b'appname'),
"msgid": redis_data.get(b'msgid'),
},
"time": int(time.time()),
def start_redis_consumer():
dd("Starting Redis Consumer")
while True:
events = r.xread({REDIS_STREAM: '$'}, block=0, count=None)
for _, data in events:
stream = _
_redisid = data[0][0]
_redisdata = data[0][1]