Skip to content

Instantly share code, notes, and snippets.

View olehermanse's full-sized avatar

Ole Herman Schumacher Elgesem olehermanse

View GitHub Profile
@olehermanse
olehermanse / type_of.ts
Created February 13, 2024 15:07
An experiment in trying to determine the "type" of something
class Mock extends Object {
userid: string;
username: string;
}
function type_of_extended(a: any): string[] {
const to = typeof a;
if (["string", "number", "boolean", "null", "undefined"].includes(to)) {
return [to];
}
from cfbs.pretty import pretty
def mock_get_input():
return [
{
"type": "list",
"variable": "files",
"namespace": "delete_files",
"bundle": "delete_files",
@olehermanse
olehermanse / variable_class_guard.cf
Created October 3, 2022 11:27
Using variables in class guards
bundle agent __main__
{
vars:
"mycontext"
string => "ubuntu";
reports:
"$(mycontext)"::
"Hello, $(mycontext) (based on variable)";
}
@olehermanse
olehermanse / Code.gs
Last active November 4, 2021 14:30
Replace (JIRA) ticket numbers with links in a Google Doc
// This is a script which searches the current
// google doc for ticket numbers (based on a regex)
// and makes them into links. (To JIRA for example).
// It also shortens the links so they only show
// ticket number (removing the https... part)
//
// Edit these 2 variables to fit your needs:
const URL = "https://tracker.mender.io/browse/";
const REGEX = "(AC|ARCHIVE|CFE|CO|COOL|ENT|EV|IBT|INF|MAR|MC|MEN|MENWEB|MM|MPPT|NW|QA|SEC|ZEN)\\-[0-9]{1,5}";
@olehermanse
olehermanse / CONTRIBUTOR_STATEMENT
Last active October 7, 2019 13:47
Northern.tech Contributor Statement
**Northern.tech AS Contributor statement**
The terms stated below apply to your contribution of computer code and other
material to software or projects owned or managed by Northern.tech AS ("project"),
and set out the intellectual property rights in the contributed material you
transfer to Cfengine. If this contribution is on behalf of a company, "you" will
also mean the company you identify below.
1. "Material" and "contribution" shall mean any source code, object code, patch,
tool, sample, graphic, specification, manual, documentation, or any other
import pyglet
window = pyglet.window.Window(resizable=True)
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
@olehermanse
olehermanse / text_rendering.py
Last active June 4, 2019 22:23
Resizable high resolution hello world in pyglet - https://bitbucket.org/pyglet/pyglet/issues/249
'''Resizable hello world example which works on mac and windows
There are a few bugs / differences between pyglet on these platforms.
This example tries to work around those issues.
Based on:
https://bitbucket.org/pyglet/pyglet/issues/78/
https://bitbucket.org/pyglet/pyglet/issues/248/
...and a lot of trial and error.
'''
@olehermanse
olehermanse / main.rs
Created March 30, 2019 19:13
Rust Hyper server with shared immutable access to file
extern crate hyper;
use std::fs::File;
use std::io::prelude::*;
use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;
use hyper::rt::{self, Future};
@olehermanse
olehermanse / psql-dump.txt
Last active January 4, 2019 13:50
DON'T EDIT! GitHub's editor can't handle so large files(!)
This file has been truncated, but you can view the full file.
$ /var/cfengine/bin/psql -d cfdb -c "\dt" | grep "table" | awk -F "|" '{ print $2 }' | awk '{ print $1 }' | xargs -t -I "{}" /var/cfengine/bin/psql -d cfdb -c 'SELECT * FROM "{}" LIMIT 200;' > dump.txt 2>&1
/var/cfengine/bin/psql -d cfdb -c SELECT * FROM "__agentstatus" LIMIT 200;
hostkey | agentexecutioninterval | lastagentlocalexecutiontimestamp | lastagentexecutionstatus
----------------------------------------------------------------------+------------------------+----------------------------------+--------------------------
SHA=6654ca75e7c4e40fa75c0ad6c5c05b438fdae052def6e8bea8dacf01c8853a5d | 290 | 2019-01-04 13:43:02+00 | OK
SHA=89c60fb122de745572e2b4a9e7d34f61c2474dc15f71ac4203d936744f10aa5c | 292 | 2019-01-04 13:42:57+00 | OK
(2 rows)
/var/cfengine/bin/psql -d cfdb -c SELECT * FROM "__benchmarkslog" LIMIT 200;
hostkey
@olehermanse
olehermanse / stpncpy.c
Created July 26, 2018 17:38
Alternate implementation of stpncpy
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
// Copy at most len bytes, including NUL terminating byte
// if src is too long don't terminate
// if src is shorter than len, fill remainder with zeroes
// return pointer to terminator in dst
// if no terminator, return dst + len (address after last byte written)