C# WPF run a function every second

To run a function every second use the DispatcherTimer Class

https://docs.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatchertimer?redirectedfrom=MSDN&view=netframework-4.8

//  DispatcherTimer setup
DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0,0,1);
dispatcherTimer.Start();

private void dispatcherTimer_Tick(object sender, EventArgs e)
{
    // This will tricker every second
}

DispatcherTimer will tick evey second calling dispatcherTimer_Tick. You can set the interval with a timespan

GitHub Action WorkFlow HCL to YML for AWS Lambda Deploy

To migrate https://github.com/marketplace/actions/aws-lambda-deploy to using yml. Your workflow looks something similar to this:

action "Upload Simple Lambda" {
  uses = "appleboy/lambda-action@master"
  secrets = [
    "AWS_ACCESS_KEY_ID",
    "AWS_SECRET_ACCESS_KEY",
    "AWS_REGION"
  ]
  args = [
    "--function-name", "hello-world",
    "--source", "main.py"
  ]
}

Migrating this to YML

name: Upload Simple Lambda

on: [push]

jobs:
  build:
    name: Upload Simple Lambda
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@master
      - uses: appleboy/lambda-action@v0.0.1
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_REGION: eu-west-1
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        with:
          args: --function-name hello-world --source main.py

Note that you need to add the Access Key ID and Secret Access Key to Github Security

Tagged with:

Connect to a different port with SQL Server Management Studio

Microsoft SQL Server Management Studio (SSMS) will default connect to port 1421 and there’s not obvious way to changing the port number. However it is possible by using a comma in the server name.

So in the example:
database-1.eu-west-1.rds.amazonaws.com,1521
First the server name, then a comma, and then the port number.

servername,portnumber
Tagged with:

Check if two dictionaries have same keys in python

I was lazy loading a large json file and wanted to collect only two keys. Running through with ujson I had to check that I had the correct data. I needed to check if my tmp dict was what I wanted. By using set() on a dict you’ll get all the keys and then do the compare easily. Here’s a simplified example of using set() on dictionaries:

key_include = ['artist', 'multiverseId']
outside = ['obc', 'artist']
tmp = ['artist', 'multiverseId']

if set(key_include) == set(outside):
   print('key_include and outside has the same keys')

if set(key_include) == set(tmp):
   print('key_include and tmp has the same keys')

# output key_include and tmp has the same keys
Tagged with:

Change a value with configparser for python

configparser is a great module to store configuration information into a file
https://docs.python.org/2/library/configparser.html
a config file could look like this:

[DEFAULT]
value = 7

To load the value from the file

import configparser

config = configparser.ConfigParser()
config.read('config.ini')
value = self.config['DEFAULT']['value']
print(value)
# output value 7

To change the value in the file:

# set new value
config.set('DEFAULT', 'value', '42')

# save the file
with open(self.config_filename, 'w') as configfile:
    config.write('config.ini')

Tagged with:

Dictionary changed size during iteration while using pop() in python

Running through a json file remove all keys but one

for key in obj.keys():
        if key != 'multiverseId':
                print(key)
                obj.pop(key)

This is fine running python2 but in python3 you will run into this error

Calling keys() in python2 makes a copy of the keys that we iterate through. This is not how it works in python3, this returns an iterator instead of a list, hence the error we get while we try to run through the list and deleting keys. What we can do is converting in into a list

for key in list(obj.keys()):
        if key != 'multiverseId':
                obj.pop(key)
                print(key)
Tagged with:

Remove non letter characters before and after characters in Python

To remove none letters characters from the beginning and end in python use regex from the re.py library. I needed it to remove spaces as well but not in between the words.

Here’s what I did:

import re

s = '( $My letters]'
s = re.sub('^[^a-zA-z]*|[^a-zA-Z]*$','',s)

print(s)

Output:

My letters
Tagged with:

AWS Lambda – name ‘Key’ is not defined

When going through the example from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.04.html I ran into the following error message:

Response:
{
  "errorMessage": "name 'Key' is not defined",
  "errorType": "NameError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 20, in lambda_handler\n    KeyConditionExpression=Key('year').eq(1985)\n"
  ]
}

The error come from this line

response = table.query(
    KeyConditionExpression=Key('year').eq(1985)
)

The issue was that I was only importing boto3, this is not enough. Guess I have to read the whole tutorial. You’ll have to add the following import.

from boto3.dynamodb.conditions import Key

Code sign wants to sign using key Allow button not working

A rather stupid error without any indication on what’s wrong. The button Allow always and Allow doesnt work for “Code sign wants to sign using key”. You can press it but does not do anything and the system doesn’t say not allowed or some sort. This happened when I deployed from Visual Studio using Xamarin to iPhone device through the mac I had to verify the certificate but I couldn’t.

Source of the solution: https://forums.developer.apple.com/thread/25092

“I am using a software to make the movement of my mouse smoother. The app is called “SmoothMouse” and if it is active, it’s impossible to click prompt asked by the keychain. I deactivated it and everything worked fine. So, if you use VPN or any software that simulate/modify your mouse position, keychain won’t let you click on it’s popup messages.”

My issue came from using Teamviewer to remote control the mac and doing everything from Teamviewer. After I went on the local machine, closed down Teamviewer. Deployed the solution from Visual Studio, got the “Code sign wants to sign using key” message on the mac and press with the local mouse I was allow to press the buttons. Hurray! What a stupid issue.

Tagged with: ,

Plex on Synology “failed to run the package service”

Got following message from Plex “failed to run the package service” when installing and trying to run it. I had missed adding certificate key. There’s a good tutorial here at plex

The public key that needs to be added in the package center: https://downloads.plex.tv/plex-keys/PlexSign.key

 

Tagged with: ,
Top