Skip to content

Instantly share code, notes, and snippets.

@bawahakim
bawahakim / UnityWebRequestHttpClient.cs
Last active November 15, 2024 05:53
Allows using UnityWebRequest with an IHttpClient interface, for example with nswag
// Depends on UniTask to support cancellation token and GetAwaiter: https://github.com/Cysharp/UniTask
// Otherwise, the code can be adapted using https://gist.github.com/krzys-h/9062552e33dd7bd7fe4a6c12db109a1a
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
@bawahakim
bawahakim / gist:a348fad4ab352a03cd8a2d3cc0868959
Last active April 22, 2023 01:31
Simple Encryption in C#/Unity
// Copyright 2023 Hakim Bawa
// Licensed under the MIT License.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Summary: Simple local encryption that is based on the UDID of the device, which returns a base64 string that can be stored
// anywhere (e.g. PlayerPrefs). This can ensure that the encrypted data cannot be used on another device
@bawahakim
bawahakim / atan2.py
Created May 26, 2023 13:58
Atan2 for tflite
def atan2(y:float, x: float):
# Terms of 18 gives precision of 2 decimals equivalent of tf.atan2
def taylor_atan(x:float, terms: int = 18):
pi_half = math.pi / 2
original_x = x
flips = 0
# Handle x > 1 and x < -1 iteratively.
while abs(x) > 1:
x = 1 / x