Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / console-writeline-no-output.md
Created December 6, 2022 10:37
wpd .net 6.0 application doesnt show console.writeline, but in wpd .net 4.8 application it works (VS2022)

QUESTION: .net 6.0 application doesnt show console.writeline, but .net 4.8 does work

ANSWER chatGPT

The Console.WriteLine method is used to write a line of text to the console window in a .NET application. In .NET 6.0, the Console.WriteLine method will only write to the console window if the application is a console application, not if it is a Windows Forms or WPF application. This is because console applications have a console window where the output from Console.WriteLine is shown, but Windows Forms and WPF applications do not have a console window.

If you are using .NET 6.0 and your application is a Windows Forms or WPF application, the Console.WriteLine method will not write anything to the console window, and you will not see any output from Console.WriteLine in the Output panel in Visual Studio.

To see the output from Console.WriteLine in a Windows Forms or WPF application in .NET 6.0, you can do one of the following:

  • Use the Debug.WriteLine method instead of Console.WriteLine. The output
@unitycoder
unitycoder / Calc.compute
Created December 6, 2022 13:35
Compute shader, send values, get results
#pragma kernel CSMain
StructuredBuffer<float> _Reader;
RWStructuredBuffer<float> _Writer;
[numthreads(1,1,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
_Writer[id.x] = sqrt(_Reader[id.x]);
}
@unitycoder
unitycoder / Gimbal.cs
Last active April 11, 2023 15:20
using quaternions in UNITY in order to avoid gimbal lock
// https://forum.unity.com/threads/problem-using-quaternions-in-unity-in-order-to-avoid-gimbal-lock.1370154/
Quaternion currentRotation = Quaternion.identity;
currentRotation = currentRotation * Quaternion.AngleAxis(_rotX, transform.up) ;
currentRotation = currentRotation * Quaternion.AngleAxis(-_rotY, transform.right);
currentRotation = currentRotation * Quaternion.AngleAxis(_rotZ, transform.forward) ;
_camera.transform.rotation = currentRotation;
@unitycoder
unitycoder / LittleEndian_vs_BigEndian.md
Last active December 7, 2022 18:20
Little Endian vs Big Endian (binary example)

// by chatGPT

In a binary representation of data, the "endianness" of a system refers to the order in which the individual bytes of the data are stored in memory. In a "little endian" system, the least significant byte (the one with the lowest value) is stored at the lowest memory address, and subsequent bytes are stored in increasing order of significance. In a "big endian" system, the most significant byte is stored at the lowest memory address, and subsequent bytes are stored in decreasing order of significance.

Here's an example to illustrate the difference between little and big endian. Suppose we have the following 16-bit binary number:

1100 0010 0011 0101

In a little endian system, this number would be stored in memory as two consecutive bytes, with the least significant byte (0011 0101) at the lowest memory address, and the most significant byte (1100 0010) at the next memory address:

@unitycoder
unitycoder / BigBlend.shader
Last active December 9, 2022 20:15
Blend 5 textures using vertex color red value
// chatGPT
// This code will blend the colors of the textures together based on the vertexColor.r value,
// resulting in a smooth gradient between the textures.
// You can adjust the clamp function in each mix call to fine-tune the blending between the textures.
// Sample the colors of the five textures at the corresponding points
vec4 color1 = texture(texture1, uv);
vec4 color2 = texture(texture2, uv);
vec4 color3 = texture(texture3, uv);
vec4 color4 = texture(texture4, uv);
@unitycoder
unitycoder / Huffman-Encoding.md
Created December 9, 2022 11:55
Huffman Encoding (Simple Example)

// by chatGPT

Huffman coding

Huffman coding is a type of data compression algorithm that is used to encode data in a way that uses fewer bits than the original representation. It is based on the idea of assigning shorter bit strings to the more common data values, and longer bit strings to the less common values, in order to reduce the overall length of the encoded data.

Here is a simple example of how Huffman coding works:

Suppose we have the following data values and their frequencies:

@unitycoder
unitycoder / getip.py
Created December 9, 2022 14:40
Python get external IP using ipify
// by chatGPT (tested)
import urllib.request
# Use the urllib module to make a HTTP GET request to a web service that returns the IP address of the client
response = urllib.request.urlopen('https://api.ipify.org')
# Read the response data and convert it to a string
data = response.read()
ip_address = data.decode('utf-8')
@unitycoder
unitycoder / MandelbrotJob.cs
Created December 10, 2022 11:25
AI Burst Mandelbrot
// https://forum.unity.com/threads/ai-burst-mandelbrot.1372359/
using UnityEditor;
using UnityEngine;
using Unity.Jobs;
 
using Unity.Jobs;
using Unity.Collections;
 
public struct MandelbrotJob : IJobParallelFor
{
@unitycoder
unitycoder / GeocodingExample.cs
Last active December 10, 2022 14:26
c# Get Latitude Longitude for Address using Google Geocoding API
// by chatGPT
// To get the latitude and longitude for a given address in C#, you can use the Geocoding API.
// The Geocoding API is a service that provides geocoding and reverse geocoding of addresses.
// Here is an example of how you can use the Geocoding API in C# to get the latitude and longitude for a given address:
// In this example, the apiKey variable should be replaced with your own API key,
// which you can obtain from the Google Cloud Console. The address variable should be replaced with a valid address.
// After making the request to the Geocoding API,
// the response is parsed and the latitude and longitude are extracted from the JSON data.
// The latitude and longitude are then printed to the console.
@unitycoder
unitycoder / HighscoreFetch.php
Last active May 2, 2024 18:42
PHP top 10 highscore script (save name and score)
<?php
// Replace with your own database credentials
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "highscores";
try {
// Create a new PDO connection
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);