Skip to content

Instantly share code, notes, and snippets.

View tmacam's full-sized avatar

Tiago Alves Macambira tmacam

View GitHub Profile
@tmacam
tmacam / chcluster2.sh
Created September 29, 2023 22:56
Another approach to change kubectl context
#!/bin/bash
set -e
function listContexts() {
kubectl config get-contexts | sed -e 's/^ /off/' -e 's/^\*/on/' -e 1d | awk '{printf("%i\n%s\n", (NR-1),$2)}'
}
# https://stackoverflow.com/questions/11426529/reading-output-of-a-command-into-an-array-in-bash
IFS=$'\n' read -r -d '' -a contexts < <( listContexts && printf '\0' )
@tmacam
tmacam / chcluster.sh
Created September 29, 2023 22:20
dialog to change current kubectl context
#!/bin/bash
set -e
selected=$(
dialog --radiolist "Choose cluster" 0 0 0 $(
kubectl config get-contexts | sed -e 's/^ /off/' -e 's/^\*/on/' -e 1d | awk '{print $2,$3,$1 }'
) 2>&1 > /dev/tty
)
@tmacam
tmacam / normalize_string.py
Last active May 30, 2023 08:11
string normalization in python: HTML stripping and HTML entity resolution.
#!/usr/bin/python
# vim:ts=4:sts=4:sw=4:et:wrap:ai:fileencoding=utf-8:
"""A collection of string normalization routines.
You are probably looking for normalize_string, that does an aggressive (but
arguably sound) string normalization process.
"""
@tmacam
tmacam / state_for_all_components.py
Created August 3, 2022 22:47
Util script for dapr/dapr-docs project
from dataclasses import dataclass
import pathlib
import yaml
from operator import itemgetter
YAML_SUFFIX_LENGTH = len('.yaml')
@dataclass
class Component:
building_block: str
@tmacam
tmacam / relatorio.sublime-syntax
Last active July 28, 2022 23:03
Aditional syntax config to make editing my org-like worklog easier.
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: relatorio
file_extensions: [md]
scope: text.html.markdown
contexts:
main:
- match: '\b(PENDING)\b'
scope: keyword.control.c
# -*- coding: utf-8 -*-
from datetime import datetime
import time
import sublime_plugin
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date` and `time`
@tmacam
tmacam / README.md
Created July 20, 2022 17:12 — forked from tpitale/README.md
Sublime Text plugin to create a simple timestamp
  1. Go to Tools > New Plugin
  2. Paste timestamp.py contents and save in User as timestamp.py
  3. Open Preferences > Key Bindings - User (or Default, your call)
  4. Paste keybindings.json, or add a line to your keybindings
  5. Customize the keyboard shortcut to your liking and save
@tmacam
tmacam / export-process.rst
Created June 12, 2011 19:13
Short guide on how to export code to Git and tidy up its history

Exporting code to Git and tiding up its history

Author

Tiago Alves Macambira [tmacam burocarata org]

Licence

Creative Commons By-SA

Table of Contents

#ifndef PRODUCER_CONSUMER_QUEUE_HPP_
#define PRODUCER_CONSUMER_QUEUE_HPP_
// Based on code from http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
// Original version by Anthony Williams
// Modifications by Michael Anderson -- https://gist.github.com/482342
#include <boost/thread.hpp>
# just in case
curl -XDELETE http://localhost:9200/inall
curl -XPUT http://localhost:9200'/inall/' -d '{
"mappings": {
"thing": {
"include_in_all": false,
"type": "object",
"_all" : {