Gray_code_element
Thursday, March 6, 2025
C# MIDI Programming
midi-dot-net
Discussion about programming C# MIDI
Create great MIDI 2.0 apps using Windows MIDI Services and C#
MIDI to CSV Sanford C# MIDI Library
Monday, February 10, 2025
SVG: Two arrows with text on the ends
Arrow with Text SVG Using Markers and Text tags
In this tutorial, we’ll see how to use the <marker>
and <marker>
elements in SVG to create an arrowhead and text at the end of a line.
SVG Code
Below is the code to create an arrow and text using an SVG marker:
<svg width="250" height="100" viewBox="0 0 250 100">
<defs>
<marker id="arrowhead" markerWidth="10" markerHeight="10" refX="5" refY="5" orient="auto">
<polygon points="0 0, 10 5, 0 10" />
</marker>
</defs>
<line x1="10" y1="50" x2="180" y2="10" stroke="black" stroke-width="2" marker-end="url(#arrowhead)" />
<text x="195" y="15" fill="red">50N 30°</text>
<line x1="10" y1="50" x2="50" y2="10" stroke="black" stroke-width="2" marker-end="url(#arrowhead)" />
<text x="60" y="15" fill="red">20N 45°</text>
</svg>
Live Example
Here’s how the arrow appears in the browser:
To experiment with SVG, along with CSS and JavaScrip, you can use:
SVG Line with Arrow head (marker)
How to Create an Arrowhead in SVG Using Markers
In this tutorial, we’ll see how to use the <marker>
element in SVG to create an arrowhead at the end of a line.
SVG Code
Below is the code to create an arrow using an SVG marker:
<svg viewBox="0 0 100 100" width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<defs>
<!-- A marker to be used as an arrowhead -->
<marker
id="arrow"
viewBox="0 0 10 10"
refX="5"
refY="5"
markerWidth="10"
markerHeight="10"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" />
</marker>
</defs>
<!-- A line with a marker -->
<line
x1="10"
y1="10"
x2="80"
y2="80"
stroke="black"
stroke-width="2"
marker-end="url(#arrow)" />
</svg>
Live Example
Here’s how the arrow appears in the browser:
Some notes on using the 'viewBox' property:
The
viewBox="minX minY width height"
determines how the internal coordinates (e.g.,x
,y
,width
,height
of the<rect>
) map to the actual display size (width
andheight
of the<svg>
element).
To experiment with SVG, along with CSS and JavaScrip, you can use:
How to Format Code Blocks in Blogger
How to Format Code Blocks in Blogger
Blogger’s default editor strips away some HTML formatting, but you can use Prism.js to style your code blocks.
Step 1: Add Prism.js to Your Blogger Theme
Go to Theme > Edit HTML and add the following before </head>
:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
Step 2: Use <pre><code>
Tags in Your Blog Post
When writing a new post in HTML mode, use the following format:
<pre><code class="language-batch">
@echo off
setlocal enabledelayedexpansion
for %%F in (*.zip) do (
set "foldername=%%~nF"
mkdir "!foldername!"
tar -xf "%%F" -C "!foldername!"
)
echo Extraction complete!
pause
</code></pre>
Step 3: Preview and Publish
Switch to Compose mode to check formatting. The code should appear in a gray-colored block.
Example Output:
@echo off
setlocal enabledelayedexpansion
for %%F in (*.zip) do (
set "foldername=%%~nF"
mkdir "!foldername!"
tar -xf "%%F" -C "!foldername!"
)
echo Extraction complete!
pause
Thanks to ChatGPT for this information
Extracting a series of zip files into folders with the names of each file
Batch File to Extract ZIP Files into Folders
If you have multiple ZIP files in a folder and want to extract each one into its own folder with the same name as the ZIP file, you can use a batch script.
Method 1: Using Windows tar
(Windows 10+)
Create a batch file and paste the following code:
@echo off
setlocal enabledelayedexpansion
for %%F in (*.zip) do (
set "foldername=%%~nF"
mkdir "!foldername!"
tar -xf "%%F" -C "!foldername!"
)
echo Extraction complete!
pause
Steps:
- Save the file as
extract_all.bat
in the folder containing your ZIP files. - Double-click the batch file to extract each ZIP file into a folder named after the ZIP filename.
Method 2: Using 7-Zip (More Reliable)
Prerequisite: Install 7-Zip and ensure it’s added to the system path or use the full path to 7z.exe
.
@echo off
setlocal enabledelayedexpansion
for %%F in (*.zip) do (
set "foldername=%%~nF"
mkdir "!foldername!"
"C:\Program Files\7-Zip\7z.exe" x "%%F" -o"!foldername!" -y
)
echo Extraction complete!
pause
Steps:
- Save as
extract_all.bat
in the folder containing the ZIP files. - Run the batch file.
How It Works
for %%F in (*.zip) do
→ Loops through all.zip
files in the folder.set "foldername=%%~nF"
→ Extracts the filename (without extension).mkdir "!foldername!"
→ Creates a folder with the same name.tar -xf
or7z.exe x
→ Extracts the ZIP file into the created folder.
Would you like any modifications, such as handling subdirectories or logging extraction results? Let me know in the comments!
Tuesday, February 4, 2025
Top Level Statements in C#
C# Top-Level Statements vs. Main Method
In C# 9 and later, you can use top-level statements, which eliminate the need for explicitly defining a Main
method. Your code uses this feature, so the Main
method is not required.
Why is Main
Not Required?
- Starting from C# 9, you can write top-level statements directly in a
.cs
file, and the compiler will implicitly generate aMain
method. - This feature is designed to make simple programs (like console applications) more concise.
How It Works:
- The compiler automatically wraps the code inside a generated
Main
method. - Your program starts executing from the first statement.
- Any
await
statements require an async context, which is automatically handled.
If Using Older C# Versions:
If you're using C# 8 or earlier, or if you prefer the traditional structure, you would need to explicitly define Main
like this:
using System;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Protocol;
class Program
{
static async Task Main()
{
Console.WriteLine("Starting MQTT Client...");
var mqttFactory = new MqttFactory();
var mqttClient = mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("broker.mqtt-dashboard.com", 1883)
.WithCleanSession()
.Build();
double Temperature = -5;
double WindSpeed = 10;
var Rand = new Random();
mqttClient.ConnectedAsync += async e =>
{
Console.WriteLine("Successfully connected to the MQTT broker.");
while (true)
{
double currentTemperature = Math.Round((Temperature + Rand.NextDouble()), 3);
double currentWindSpeed = Math.Round((WindSpeed + Rand.NextDouble()), 3);
var message = new MqttApplicationMessageBuilder()
.WithTopic("LRLBTopic")
.WithPayload(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new
{
Temperature = currentTemperature,
WindSpeed = currentWindSpeed,
})))
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
.Build();
await mqttClient.PublishAsync(message);
Console.WriteLine("Message published to topic: LRLBTopic");
Thread.Sleep(2000);
}
};
mqttClient.DisconnectedAsync += e =>
{
Console.WriteLine("Disconnected from the MQTT broker.");
return Task.CompletedTask;
};
try
{
await mqttClient.ConnectAsync(mqttClientOptions);
}
catch (Exception ex)
{
Console.WriteLine($"Error connecting to the MQTT broker: {ex.Message}");
return;
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
await mqttClient.DisconnectAsync();
}
}
Summary:
- C# 9+:
Main
is optional (uses top-level statements). - C# 8 or earlier:
Main
is required. - For explicit structure: You can still define
Main
if you prefer.
Your code will work fine as long as you are using C# 9 or later in your project. 🚀
Visual Studio Remove Blank spaces
- In window, press Ctrl+H (quick replace)
- Click "Use regular expressions"
- In Find, specify: ^\$\n
- leave Replace as blank
- Click "Replace All" All blank lines will be deleted.
Thanks to stockoverflow https://stackoverflow.com/questions/50042278/visual-studio-code-remove- blank-lines-from-code
This regular expression is used to identify and remove blank lines from text.
- ^: Matches the beginning of a line. Since we're using the `re.MULTILINE` flag in Python, each line in the text is treated as a separate unit.
- \s*: Matches zero or more whitespace characters (spaces, tabs, newlines).
- $: Matches the end of a line.
- \n: Matches a newline character.
In essence, this regular expression matches a line that:
- Starts with the beginning of the line.
- Contains zero or more whitespace characters.
- Ends with the end of the line.
- Is followed by a newline character.
Therefore, it effectively targets and matches blank lines that might contain spaces or tabs.
Thanks to Gemini for the explaination.
C# MIDI Programming
C# MIDI Toolkit midi-dot-net Discussion about programming C# MIDI Create great MIDI 2.0 apps using Windows MIDI Services and C# MIDI ...
-
In a regular annotation note, create a stack that looks the way you like. It will take a couple of trial and error attempts since there...
-
Getting into Equation Mode use <alt> and = to get into the equation editor. Radicals : $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$ ...