Skip to content

Instantly share code, notes, and snippets.

View pedrolamas's full-sized avatar

Pedro Lamas pedrolamas

View GitHub Profile
@pedrolamas
pedrolamas / lambda_function.py
Created September 18, 2023 17:02 — forked from matt2005/lambda_function.py
Alexa Smart Home Skill Adapter for Home Assistant
"""
Copyright 2019 Jason Hu <awaregit at gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
[gcode_macro M117]
description: Set LCD Message
rename_existing: M117.1
gcode:
{% if rawparams %}
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0] | replace('"', '\\"') %}
SET_DISPLAY_TEXT MSG="{escaped_msg}"
RESPOND TYPE=command MSG="{escaped_msg}"
_SET_MARQUEE MSG="{escaped_msg}"
{% else %}
@pedrolamas
pedrolamas / test.yaml
Created May 21, 2021 16:36
Home Assistant sensor for IKEA Tradfri feed update check
sensor:
- platform: command_line
name: IKEA Tradfri OTA feed
command: >-
python3 -c "import hashlib, json, requests; response = requests.get('http://fw.ota.homesmart.ikea.net/feed/version_info.json'); ret = { 'ETag': response.headers.get('ETag'), 'Date': response.headers.get('Date'), 'Hash': hashlib.sha256(response.content).hexdigest() }; print(json.dumps(ret))"
value_template: '{{ value_json.Hash }}'
json_attributes:
- Date
- ETag
scan_interval: 10800
@pedrolamas
pedrolamas / _headers
Created March 24, 2021 17:21
Netlify headers generated by gatsby-netlify-plugin for pedrolamas.com website
## Created with gatsby-plugin-netlify
/*
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: accelerometer=(), autoplay=(), ambient-light-sensor=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), usb=()
X-Content-Type-Options: nosniff
/manifest.webmanifest
Content-Type: application/manifest+json
@pedrolamas
pedrolamas / docker-iptables-fix.sh
Created August 18, 2020 19:32
Script to fix Docker iptables on Synology NAS
#!/bin/bash
currentAttempt=0
totalAttempts=10
delay=15
while [ $currentAttempt -lt $totalAttempts ]
do
currentAttempt=$(( $currentAttempt + 1 ))
echo "Attempt $currentAttempt of $totalAttempts..."
@pedrolamas
pedrolamas / elgato_cam_link_4k.txt
Last active June 19, 2020 13:26
Elgato Cam Link 4k output from USBView (before and after freezing)
@pedrolamas
pedrolamas / old-docker-iptables-fix.sh
Last active March 10, 2021 18:26
Script to fix Docker iptables on Synology NAS
#!/bin/bash
start() {
iptables -t nat -N DOCKER
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL ! --dst 127.0.0.0/8 -j DOCKER
}
stop() {
iptables -t nat -D PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
@pedrolamas
pedrolamas / MultiWindowViewModelBase.cs
Last active March 21, 2018 11:27
Base view model that can be used in multiple windows
public class MultiWindowViewModelBase : INotifyPropertyChanged
{
private readonly ConcurrentDictionary<CoreDispatcher, PropertyChangedEventHandler> _dispatchersAndHandlers = new ConcurrentDictionary<CoreDispatcher, PropertyChangedEventHandler>();
public event PropertyChangedEventHandler PropertyChanged
{
add
{
var dispatcher = Window.Current.Dispatcher;
@pedrolamas
pedrolamas / gpg-cheat-sheet.md
Last active December 28, 2021 22:52
GPG cheat sheet

GPG Cheat Sheet

Generating a new key

gpg --gen-key

gpg --expert --full-gen-key
@pedrolamas
pedrolamas / CultureInfoHelper.cs
Last active August 15, 2021 14:36
Helper class to return the correct CultureInfo in UWP apps
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
public class CultureInfoHelper
{
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode)]
private static extern int GetLocaleInfoEx(string lpLocaleName, uint LCType, StringBuilder lpLCData, int cchData);
private const uint LOCALE_SNAME = 0x0000005c;