Skip to content

Instantly share code, notes, and snippets.

View lordlycastle's full-sized avatar
🤙
Let it Fly!

lordlycastle

🤙
Let it Fly!
View GitHub Profile
# coding: utf-8
# In[14]:
import numpy as np
import pandas as pd
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
@lordlycastle
lordlycastle / combine_dicts.py
Last active January 9, 2019 13:10
function to combine dictionaries and list keys that are overwritten.
a = {1: -1, 2: -2}
b = {2: 2, 3: -3}
c = {3: 3, 4: -4}
d = {3: 3j, 5: -5}
def combine_dicts(*args):
"""Combines multiple dictionaries in one. Overwrites the value of keys if they occur in multiple dicts.
Value is taken from the """
x = args
@lordlycastle
lordlycastle / CheckForNull.cs
Created January 17, 2019 16:17
Function to remove null values from a main list and removes values from other relating lists at same index.
private void CheckForNull<T, T2>(ref List<T> listOfObjs, ref params List<T2>[] otherLists)
{
for (int i = listOfObjs.Count; i >= listOfObjs.Count; i--)
{
var o = listOfObjs[i];
if (o == null)
{
listOfObjs.RemoveAt(i);
foreach (List<T2> otherList in otherLists)
{
@lordlycastle
lordlycastle / CheckForNull.cs
Last active January 17, 2019 16:21
Function to remove null values from a main list and removes values from other relating lists at same index.
// Doesn't work bcz ref and params doens't work. I now this was a concious decision by developers.
// This doesn't work. But it is kinda what 'pythonic'.
private void CheckForNull<T, T2>(ref List<T> listOfObjs, ref params List<T2>[] otherLists)
{
for (int i = listOfObjs.Count; i >= listOfObjs.Count; i--)
{
var o = listOfObjs[i];
if (o == null)
{
listOfObjs.RemoveAt(i);
@lordlycastle
lordlycastle / doctors.py
Last active January 28, 2019 13:22
the american healthcare in a gist.
import time
from healthcare import private_healthcare as healthcare # no going back after this.
import AI2IF
class AIDoc(object):
base_charge = 200 # admin fee
min_patient_wait_duration = 60 * 10 # in seconds. 10 min.
def check_patients(self, patient):
time.sleep(min_patient_wait_duration + random.randint(1, 6) * 60)
# Example class
class Eg(object):
a = None
def __init__(self, a):
self.a = a
# look up dict to connect attribute to keys so I can get the relavent attr based on the key.
# issue is that it is easy to make mistake in string since there's no auto-complete and IDE checking.
# and obviously it's annoying to use. I
@lordlycastle
lordlycastle / DerivedClassesConundrum.cs
Last active March 5, 2019 10:58
Why are OOP so convoluted in .NET?
using System;
namespace Scripts
{
public class BaseProperty : Object
{
public int myInt = 1;
@lordlycastle
lordlycastle / StringEnumMap.cs
Last active April 12, 2019 12:28
String enums in C# with multiple string representation mapping.
/// <summary>
/// An abstract class which functions as string Enums.
/// Using it allows you to specify string value along with the usual int
/// for a enum option and convert between them.
/// It also allows you have potential string values. When converting to string
/// it will return the _stringRepresentation but any of the provided strings can
/// be used to convert from string to enum.
/// </summary>
/// <typeparam name="TEnum"></typeparam>
public abstract class StringEnumMap<TEnum> : IEnumerable<TEnum>, IComparable, IEquatable<TEnum>
public class ContinueOnFailTest
{
public struct MultiplyTestCase
{
public int result;
public (int, int) input;
}
public int Multiply(int x, int y) => x * y;
@lordlycastle
lordlycastle / JsonSerializationTester.cs
Last active February 2, 2024 17:36
Inspector window that can be used to test/see JSON deserialization. Requires [Odin](https://odininspector.com/). Get JSON Formatter from here: https://gist.github.com/lordlycastle/755a9d4e34600bc881fe70d3201e516e
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;