Skip to content

Instantly share code, notes, and snippets.

View bogdanbujdea's full-sized avatar
💭
Who reads this?

Bogdan Bujdea bogdanbujdea

💭
Who reads this?
View GitHub Profile
@bogdanbujdea
bogdanbujdea / s3.cs
Created November 2, 2020 22:19
Startup.cs configuration for S3 and LocalStack
if (_environment.IsDevelopment())
{
var amazonS3 = new AmazonS3Client(new BasicAWSCredentials("abc", "def"), new AmazonS3Config
{
ServiceURL = "http://localhost:4572",
ForcePathStyle = true,
UseHttp = true
});
services.AddSingleton(typeof(IAmazonS3), provider => amazonS3);
@bogdanbujdea
bogdanbujdea / dynamodb.cs
Created November 2, 2020 22:17
Configure DynamoDb and LocalStack in .NET Core
if (_environment.IsDevelopment())
{
services.AddSingleton<IAmazonDynamoDB>(sp =>
{
var clientConfig = new AmazonDynamoDBConfig
{
ServiceURL = "http://localhost:4569",
UseHttp = true
};
return new AmazonDynamoDBClient(new BasicAWSCredentials("abc", "def"), clientConfig);
@bogdanbujdea
bogdanbujdea / docker-compose.yaml
Created November 2, 2020 22:14
LocalStack docker compose
version: '3.7'
services:
localstack:
network_mode: bridge
image: localstack/localstack:latest
container_name: localstack
environment:
- SERVICES=s3:4572,ssm:4583,dynamodb:4569
- DATA_DIR=/tmp/localstack/data
@bogdanbujdea
bogdanbujdea / consumers.yaml
Created October 30, 2020 18:30
Active consumers card with auto entities
type: conditional
conditions:
- entity: sensor.apartment_power_total
state_not: "off"
card:
type: vertical-stack
cards:
- type: custom:auto-entities
card:
@bogdanbujdea
bogdanbujdea / subflow.json
Last active October 21, 2020 20:48
Node-Red subflow for sending notifications
[{"id":"3c8ad50a.81cbba","type":"subflow","name":"Subflow 1","info":"","category":"","in":[{"x":-20,"y":80,"wires":[{"id":"6d65619b.8360a"}]}],"out":[],"env":[{"name":"message","type":"str","value":"Hello","ui":{"label":{"en-US":"Message"}}},{"name":"title","type":"str","value":"","ui":{"label":{"en-US":"Notification title"}}}],"color":"#DDAA99"},{"id":"8f27018e.a9918","type":"api-call-service","z":"3c8ad50a.81cbba","name":"Send notification","server":"8501408e.93b69","version":1,"debugenabled":true,"service_domain":"notify","service":"mobile_app_galaxy_s9","entityId":"","data":"{\"message\": $env('message'), \"title\": $env('title')}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":60,"wires":[[]]},{"id":"6d65619b.8360a","type":"time-range-switch","z":"3c8ad50a.81cbba","name":"Is it between 10 PM and 8 AM?","lat":"","lon":"","startTime":"22:00","endTime":"08:00","startOffset":0,"endOffset":0,"x":210,"y":80,"wires":[[],["d710e0e9.28
@bogdanbujdea
bogdanbujdea / todoist
Created October 20, 2020 17:39
Todoist API payload
msg.headers = {};
msg.method = "POST";
msg.url = "https://api.todoist.com/sync/v8/sync";
var taskId = "4271193756";
msg.payload = "token=<insert your token here>&commands=%5B%7B%22type%22%3A%20%22item_update_date_complete%22%2C%20%22uuid%22%3A%20%22" +
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}) + "%22%2C%20%22args%22%3A%20%7B%22id%22%3A%20" + taskId + "%7D%7D%5D"
msg.headers["content-type"] = "application/x-www-form-urlencoded"
@bogdanbujdea
bogdanbujdea / configuration.yaml
Last active October 20, 2020 17:59
Configuring a variable using home-assistant-variables
var:
latest_hashnode_article_id:
friendly_name: 'Latest article ID'
icon: 'mdi:blogger'
@bogdanbujdea
bogdanbujdea / hashnode
Last active October 20, 2020 17:18
Query for retrieving ids of Hashnode articles
{
user(username: "bogdan") {
publication {
posts(page: 0){
cuid,
title
}
}
}
}
@bogdanbujdea
bogdanbujdea / ugly-html.cs
Created October 19, 2020 22:04
Creating an HTML file with StringBuilder
private static void AddResultsFromVotes(StringBuilder html, string name, decimal voteCount, Dictionary<string, int> dictionary, int cancelledVotes)
{
var sum = dictionary.Sum(c => c.Value);
var index = 1;
html.Append($"<br/>");
html.Append($"<h2>Voturi {name}</h2><br />");
html.Append($"Total voturi {name}: {voteCount}<br />");
html.Append($"Total voturi anulate in {name}: {cancelledVotes}<br />");
voteCount -= cancelledVotes;
var countedPercentage = Math.Round(sum / (decimal)voteCount * 100, 2);
@bogdanbujdea
bogdanbujdea / nodered.json
Created October 19, 2020 20:59
Call service with JSONata
[{"id":"9ca1657d.057fd8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"7cca5834.d24008","type":"api-call-service","z":"9ca1657d.057fd8","name":"Change office lightstrip","server":"8501408e.93b69","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.office_lightstrip","data":"{\t \"brightness\": msg.data.new_state.attributes.brightness,\t \"rgb_color\": msg.data.new_state.attributes.rgb_color\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":120,"wires":[["1489ac11.df6254"]]},{"id":"b8f1a35c.90226","type":"server-state-changed","z":"9ca1657d.057fd8","name":"Bedroom lightstrip changed","server":"8501408e.93b69","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.bedroom_lightstrip","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type"