Skip to content

Instantly share code, notes, and snippets.

View marcelschmidtdev's full-sized avatar

Marcel Schmidt marcelschmidtdev

  • Wooga
  • Berlin, Germany
View GitHub Profile
#!/bin/bash
# This script opens a Wireguard VPN and is closing it after a Hyperbackup task has finished.
# It was tested with only one active backup task on a single remote target and Hyperbackup 4.1.1-3758.
#
# How it works:
# * Setup a new scheduled task in the control panel executing this script with correct parameters
# * Make sure it runs BEFORE your Hyperbackup tasks are started
# * Note: Verify if it's working. Unfortunately Hyperbackup officially doesn't support any hooks,
# therefore this is relying on parsing the log file with regex. It can break any time with a
@marcelschmidtdev
marcelschmidtdev / upd.php
Last active April 10, 2023 20:26
Fritz!Box DynDNS update script for Cloudflare
<?php
// Fritz!Box update URL: https://example.com/upd.php?key=<pass>&zone=<domain>&ipv4=<ipaddr>&a=[records to update]
// Replace [records to update] in the url.
// If you want to update multiple records of your zone, just add them comma separated: '&a=sub,sub2,*,@'
// Optionally you can update AAAA records by appending '&ipv6=<ip6addr>&aaaa=[records to update]' to the url.
// If no AAAA record is defined but ipv6 is used, it will update both ip4 and ip6 defined for A records.
// $_SERVER['REMOTE_ADDR'] no longer works as FritzOS 7.50 started using IPv6
$key = $_GET['key'] ?? NULL;
$zone = $_GET['zone'] ?? NULL;
@marcelschmidtdev
marcelschmidtdev / RemoveMissingScriptComponents.cs
Created December 18, 2017 14:49
Searching for components with missing scripts and removes them
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class RemoveMissingScriptComponents
{
@marcelschmidtdev
marcelschmidtdev / GameObjectTools.cs
Created October 23, 2017 17:08
Helper menu to really break Unity prefab instances (removes the Inspector prefab buttons)
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class GameObjectTools
{
private const string TempPrefabAssetPath = "Assets/tmp.prefab";
[MenuItem ("GameObject/Really Break Prefab Instance", true)]
public static bool ValidateBreakPrefabInstance ()
@marcelschmidtdev
marcelschmidtdev / ScrollRectExtension.cs
Created June 19, 2017 15:33
Center element of scroll list
using UnityEngine;
using UnityEngine.UI;
public static class ScrollRectExtensions
{
public static void SnapTo (this ScrollRect rect, Transform target)
{
rect.content.anchoredPosition = rect.transform.InverseTransformPoint (rect.content.position) - rect.transform.InverseTransformPoint (target.position);
}
}
// The Google Play receipt JSON comes with a payload, which contains a string of nested JSON structure.
// In order to deserialize that structure, apply this method to the raw JSON string BEFORE you
// deserialize it to an object.
public static string FixJSONFormat (string json)
{
return json.Replace (@"\\\", "").Replace (@"\""", @"""").Replace (@"""{", @"{").Replace (@"}""", @"}");
}
@marcelschmidtdev
marcelschmidtdev / IgnorableSerializerContractResolver.cs
Last active July 25, 2016 16:52
Ignore properties without using JsonIgnore attribute
/// <summary>
/// Special JsonConvert resolver that allows you to ignore properties. See http://stackoverflow.com/a/13588192/1037948
/// </summary>
public class IgnorableSerializerContractResolver : DefaultContractResolver {
protected readonly Dictionary<Type, HashSet<string>> Ignores;
public IgnorableSerializerContractResolver() {
this.Ignores = new Dictionary<Type, HashSet<string>>();
}
public abstract class Singleton<T> where T : new()
{
private static T mInstance;
public static T Instance
{
get
{
if (mInstance == null)
{
@marcelschmidtdev
marcelschmidtdev / GetNextItemInListOrArray
Last active November 18, 2023 17:23
Elegant way to get the next element in an array or list (circled)
//Assume we have 5 items in our list
List<Item> myList = new List<Item>(5);
//Assume our current active item is at index 2
public Item GetNextItem(Item item)
{
int currentIndex = myList.IndexOf(item);
int nextItemIndex = (currentIndex + 1) % myList.Count;
return myList[nextItemIndex];
}
@marcelschmidtdev
marcelschmidtdev / RecursiveBoundingBox.cs
Created March 30, 2016 00:44
Gets all bounding boxes and returns a new one which encapsulate them all (Unity)
using UnityEngine;
using System.Collections;
public class RecursiveBoundingBox
{
//Gets all bounding boxes and returns a new one which encapsulate them all
//This is e.g. useful if you want to calculate the actual size of a gameobject
//Using "MeshRenderer" means it uses the data from "MeshFilter" applied to "Transform"
public static Bounds RecursiveMeshRendererBoundingBox (GameObject go)