Skip to content

Instantly share code, notes, and snippets.

View data-henrik's full-sized avatar

Henrik Loeser data-henrik

View GitHub Profile
@data-henrik
data-henrik / README.md
Created October 14, 2014 08:28
Use sipgate.io service to log phone calls in Cloudant and send out SMS via Twilio
@data-henrik
data-henrik / README.md
Last active August 29, 2015 14:27
Auto-respond to Twitter tweets and archive messages in DB2

Flow to automatically respond to tweets in Twitter. If the tag "archive" is used, then the incoming tweet is stored in the DB2-based sqldb service. A simple Web service is provided to retrieve the archived tweets from DB2.

To work, the table "twitarchive" needs to be created.

create table twitarchive(
id int generated always as identity,
tstamp timestamp,
tweet varchar(200),
username varchar(100)
@data-henrik
data-henrik / mywordcloud.py
Last active October 5, 2018 18:13
Python script to generate wordcloud for given background image
# Masked wordcloud
# ================
# Using a mask you can generate wordclouds in arbitrary shapes.
import sys, getopt
from os import path
from PIL import Image
import numpy as np
import random
import matplotlib.pyplot as plt
@data-henrik
data-henrik / README.md
Last active November 27, 2018 09:54
Pull data from a [Db2 or SQLAlchemy] database and inject into IBM Watson Discovery collection

From database into Watson Discovery

The code shown is a simple Python example of pulling data from a SQL database supported by SQLAlchemy, and then injecting the data as new JSON document into a collection of Watson Discovery Service on IBM Cloud.

@data-henrik
data-henrik / readme.md
Created March 20, 2020 08:15 — forked from lounagen/readme.md
Example for decoding a JWT Payload with your Shell (bash, zsh...)

Setup

Add this to your .profile, .bashrc, .zshrc...

BASE64_DECODER_PARAM="-d" # option -d for Linux base64 tool
echo AAAA | base64 -d > /dev/null 2>&1 || BASE64_DECODER_PARAM="-D" # option -D on MacOS

decode_base64_url() {
  local len=$((${#1} % 4))
  local result="$1"
 if [ $len -eq 2 ]; then result="$1"'=='
@data-henrik
data-henrik / db2serviceID.py
Last active April 17, 2020 17:51
Connect to Db2 on Cloud using an API key
import ibm_db
import pandas as pd
import ibm_db_dbi as dbi
import json,sys,os
def db2test(iamKey,hostname):
connstr="DATABASE=BLUDB;Authentication=GSSplugin;HOSTNAME={};PORT=50001;PROTOCOL=TCPIP;SECURITY=SSL;APIKEY={};".format(hostname,iamKey)
conn1 = dbi.connect(connstr)
# Quick test with Pandas and dataframe
df = pd.read_sql("select count(*) from syscat.tables", conn1)
@data-henrik
data-henrik / main.tf
Created August 27, 2020 13:06
Create an IBM Cloud service ID, then create and download an API key for that service ID
# See https://cloud.ibm.com/docs/terraform?topic=terraform-getting-started
# for details on IBM Cloud and Terraform
# First, obtain an IBM Cloud IAM token
# Thereafter, create a new IAM service ID and as
# follow-up step, using a local execution environment,
# utilize curl to create and download an API key.
# Obtain the IBM Cloud IAM authentication token
# It is needed for the embedded curl command below
@data-henrik
data-henrik / db2APItest.py
Created August 12, 2019 10:03
Simple Python-based test of the Db2 on Cloud REST API
# Simple test of the Db2 on Cloud REST API
# Written by Henrik Loeser, hloeser@de.ibm.com
# https://cloud.ibm.com/apidocs/db2-on-cloud
import requests, json, sys, time
# Read credentials from file
def readCreds(filename):
with open(filename) as data_file:
credentials = json.load(data_file)
return credentials
# this is not a script, but you may turn it into such
# it assumes that you already installed OBS Studio (sudo dnf install obs-studio)
# you could start by creating a project directory "obs"
# make obs
# cd obs
# clone the source for loopback device
git clone https://github.com/umlaeute/v4l2loopback
cd v4l2loopback
@data-henrik
data-henrik / getCredsFromKeyProtect.py
Created April 7, 2020 18:05
IBM Cloud Function / Openwhisk action to retrieve credentials
# IBM Cloud Functions / OpenWhisk action to
# 1) obtain an IAM Bearer token based on API key from env
# 2) fetch credentials in JSON object from Key Protect key
# 3) return the arguments, credentials and token
import json,sys,os
import requests,base64
# obtain IAM access token
def getAuthToken(api_key):