Skip to content

Instantly share code, notes, and snippets.

View izackp's full-sized avatar

Isaac Paul izackp

View GitHub Profile
@izackp
izackp / APIRequest.kt
Last active June 19, 2019 19:09
(Code Saved For Later) Callback interface for android api requests without livedata. Not plugnplay but that shouldn't be a problem. It could probably be done with one less class...
package any
import android.util.Log
import any.model.AppException
import any.model.NetworkState
import any.LiveModelCallback2
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
@izackp
izackp / DataStructures.md
Last active October 22, 2021 19:15
List of Data Structures for User Configuration

Comment or DM me to add to the list:

See: http://seriot.ch/parsing_json.php - Parsing JSON is a minefield. Notice how all of these json parsers are not up to spec. If they can't get it to spec then imagine the possible security issues with a format as simple as JSON.

JSON - Extremely Popular and Supported. Relatively easy to read.
XML - Old and Ugly. Widely supported. Useful if you need namespaces.
YAML - Popular format with Ruby and other server stuff. Apparently, a pain to implement and known to be insecure.
TOML - Simple configuration format. Some similarities to json. Complex arrays of objects suck tho.
HOCON - Extremely flexibile version of json.
JSON5 - Another flexible version of json. Not as flexible as others, but it has most of the important features.

@izackp
izackp / ChangeGraphicsOSXSim.md
Created September 5, 2018 13:51
For some reason the iPhone SE simulator doesn't work on my laptop without changing the backing graphics driver

defaults write com.apple.CoreSimulator.IndigoFramebufferServices FramebufferEmulationHint 1

(1 = Metal, 2 = force use of OpenGL, 3 = OpenGL)

@izackp
izackp / CircularReferenceExample.md
Last active June 15, 2017 16:34
Circular Reference Reminder
NavController {
	->ViewController
}

ViewController {
	->Table {
		Row {
			Action->ViewController.OnClick
		}

}

@izackp
izackp / HypothenuseBenchmarks.cs
Last active December 4, 2022 12:06
Benchmarking Different Hypotenuse Algorithms
/*
Starting Speed Test for 100000000 iterations
Distance_Normal: 17187ms AvgErr: 0.00% MaxErr: 0.00%
Distance_Sqrt2: 585 ms AvgErr: 5.28% MaxErr: 8.24%
Distance_4142: 623 ms AvgErr: 5.28% MaxErr: 8.24%
Distance_4142_Cast: 3824 ms AvgErr: 5.28% MaxErr: 8.24%
Distance_4142_Int_Only: 584 ms AvgErr: 5.28% MaxErr: 8.24%
Distance_4142_Int_Only_Manual_Inlined: 666 ms AvgErr: 5.28% MaxErr: 8.24%
Distance_AShift1: 606 ms AvgErr: 8.84% MaxErr:11.80%
Distance_337: 613 ms AvgErr: 3.38% MaxErr: 5.52%
@izackp
izackp / ConfigCamera.cs
Last active April 4, 2017 16:59
Zoom While Maintaining Pixel Perfect Ratio
using UnityEngine;
public class ConfigCamera : MonoBehaviour {
public float Zoom = 1.0f;
float _pixelsPerUnit = 1.0f; //Set this to whatever you set for your texture
public float ScreenWidth; //For Debugging
public float ScreenHeight; //For Debugging
Rect _bounds;
@izackp
izackp / PBKDF2.cs
Last active September 6, 2016 19:34
PBKDF2 simplified interface in C# - To anyone reading this: just use the BCrypt library its simpler and safer.
using System;
using System.Security.Cryptography;
namespace Security
{
public static class PBKDF2
{
const int cSaltByteLength = 24;
const int cDerivedKeyLength = 24;
const int cIterationCount = 2;

Clean Code

Something to note: A lot of this is situational, and depends on the platform you are working and the accepted practices for that platform/language.

  • The goal when writing clean code is readability, not efficiency, not less lines.. only readability.

Variables

  • Meaningful/Searchable Names
@izackp
izackp / CollisionUpdater.cs
Created July 22, 2015 14:33
Example of moving objects and checking for collisions. However, it can be cleaned up a bit, and it does not do any stepping!! meaning instances jump from point a to point b. So fast objects such a bullets may jump past walls.
public class CollisionUpdater
{
List<IPhysics> components;
public CollisionUpdater ()
{
components = new List<IPhysics> ();
}
public void AddComponent (IPhysics newComp)
{
@izackp
izackp / Dictionary.cs
Created February 14, 2015 17:06
Serializer for a key as string only dictionary with Full Serializer library (used with unity). This works around the ugly produced dictionaries with key and value properties in the json. It also makes it easier for hand made json.
using FullSerializer;
using System.Collections.Generic;
[fsObject(Converter = typeof(DictionaryConverter))]
public class Dictionary<TValue> : Dictionary<string, TValue> {
}