Skip to content

Instantly share code, notes, and snippets.

View skjalgsm's full-sized avatar

Skjalg Sturlasson Mæhre skjalgsm

View GitHub Profile
@skjalgsm
skjalgsm / aoc_main.rs
Created January 6, 2024 13:51
Advent of code main
mod day1;
mod day2;
use clap::Parser;
mod aoc_error;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long, default_value_t = 1)]
day: u8,
@skjalgsm
skjalgsm / day2_part2.rs
Created January 6, 2024 13:49
Advent of code day 1 part1 rust
use tracing;
use std::fs;
use miette::Result;
use crate::aoc_error;
use std::cmp::max;
pub fn run() {
let contents = fs::read_to_string("2023-day-02-part2")
.expect("Should have been able to read the file");
let result = calculate(contents);
@skjalgsm
skjalgsm / day2_part1.rs
Created January 6, 2024 13:48
Advent of code day 2 part1 rust
use tracing;
use std::fs;
use miette::Result;
use crate::aoc_error;
pub fn run() {
let contents = fs::read_to_string("2023-day-02-part1")
.expect("Should have been able to read the file");
let result = calculate(contents, 12, 13, 14);
match result {
@skjalgsm
skjalgsm / aoc-2023-day01-part2.rs
Created January 5, 2024 12:42
Advent of code day 1 part 2 rust
use tracing;
use std::fs;
use miette::Result;
use crate::aoc_error;
pub fn main() {
let contents = fs::read_to_string("2023-day-01-part2")
.expect("Should have been able to read the file");
let result = calculate(contents); //55172
match result {
@skjalgsm
skjalgsm / aoc-2023-day01-part1.rs
Last active January 5, 2024 12:43
Advent of code day 1 part1 rust
use tracing;
use std::fs;
use miette::Result;
use crate::aoc_error;
pub fn main() {
let contents = fs::read_to_string("2023-day-01-part1")
.expect("Should have been able to read the file");
let result = calculate(contents); //55172
match result {
@skjalgsm
skjalgsm / ReplaceGameObjectsWizard.cs
Created April 21, 2021 17:49
Replaces a gameobject with a prefab
public class ReplaceGameObjectsWizard : ScriptableWizard
{
private const string PrefsPath = "ReplaceGameObjects.PrefabPath";
public GameObject Prefab;
[MenuItem("GameObject/Replace GameObjects",false,0)]
static void CreateWizard ()
{
UnityEngine.Object[] objectsOfTypeAll = Resources.FindObjectsOfTypeAll(typeof(ReplaceGameObjectsWizard));
if (objectsOfTypeAll.Length == 0)
/// <summary>Only works on vertical scroll views</summary>
public class TableStickyRow : MonoBehaviour
{
[SerializeField]
RectTransform stickyPrefab = null;
//Todo: Set this in another way
[SerializeField]
private int stickyIndex;
public static class RPGItemUtility
{
private static readonly List<RPGItem> All = new List<RPGItem>();
private static bool IsLoaded;
private static TaskCompletionSource<bool> IsLoadingComplete;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Load()
{
IsLoadingComplete = new TaskCompletionSource<bool>();
@skjalgsm
skjalgsm / mac_sign.sh
Created February 26, 2020 09:40
Easy sign script for mac apps
#!/bin/bash
path="$1"
if [ "$path" = "" ] ; then
path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi
echo $path
appfile=`find "$path" -name "*.app" -exec basename {} \;`
echo $appfile
appDir=`find "$path" -name "*.app" -print`
static public int Max(int a, int b) {
a -= b;
a &= (~a) >> 31;
return a + b;
}
static public int Min(int a, int b) {
a -= b;
a &= a >> 31;
return a + b;
}