Skip to content

Instantly share code, notes, and snippets.

View xealgo's full-sized avatar

Jason Welch xealgo

View GitHub Profile
@xealgo
xealgo / example.md
Last active February 17, 2024 23:33
Unity add custom data types to list in inspector

Motivation

I wanted the ability add custom types to a list on a scriptable object asset within the inspector. These types extend a common base and are standard C# classes. Normally Unity doesn't know about your standard C# classes unless you create a reference for each type or create some complex custom editor solution. Manually adding the types to the list will result in a Type Mismatch within the inspector. There are all sorts of use cases for this such as custom properties, creating an editor friendly strategy pattern system, etc. However, not being able to edit the fields is a real pain in the ass.

Fortunately unity provides two super useful attributes: [SerializeReference] and [ContextMenu].

Example:

@xealgo
xealgo / wmdf
Created February 21, 2020 08:23
Watch and render markdown files in the terminal
#!/bin/zsh
if [ -z "$1" ]; then
echo No filename specified;
exit;
fi
if ! fswatch_loc="$(type -p 'fswatch')" || [[ -z $fswatch_loc ]]; then
brew install fswatch
fi
package main
import "fmt"
type Ingredient struct {
Name string
Amount float64
}
type Ingredients interface {
@xealgo
xealgo / makefile
Created February 6, 2019 18:28
Make file I use in go projects
BUILD := $(shell date +%m%d%H%M%S)
BUILD_TIME := $(shell date +%d.%m.%y@%H:%M:%S)
BUILD_COMMIT := $(shell git rev-parse HEAD)
BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := "0.0.1"
default: build-dev
.PHONY: default build-dev dev run test vet lint fmt
@xealgo
xealgo / adblock-test.html
Created January 14, 2019 19:03
Simple adblock detection
<html>
<head>
<title>Ad Block Test</title>
<style>
.ad {
color: #333;
background: #fff;
width: 790px;
height: 130px;
text-align: center;
var DbConnectionFailure = errors.New("Failed to run query because a database connection was not established");
...
return errors.Wrap(DbConnectionFailure, err.Error())
...
if errors.Cause(err) == DbConnectionFailure {
...
}
// store/rdb/user.go
// User satisfies user store interface
type User struct {
db *rdb.DB
}
func New(db *rdb.DB) User {
return &User{db: db}
}
type Request struct {
ID int `json:"id"`
...
}
func (req *Request) Log() map[string]interface{} {
return map[string]interface{
"id": req.ID,
...
}
@xealgo
xealgo / country_iso.go
Created November 6, 2017 20:43
simple go map of countries and their 2/3 char ISO codes.
// CountryISOMap list of countries and their associated ISO codes.
// Note: I took the original list from http://www.nationsonline.org/oneworld/country_code_list.htm
// but removed a few duplicates.. you should definitely clean this out a bit more for your needs.
var CountryISOMap = map[string][]string{
"AFGHANISTAN": {"AF", "AFG"},
"ALAND ISLANDS": {"AX", "ALA"},
"ALBANIA": {"AL", "ALB"},
"ALGERIA": {"DZ", "DZA"},
"AMERICAN SAMOA": {"AS", "ASM"},
"ANDORRA": {"AD", "AND"},
@xealgo
xealgo / compression.go
Last active September 26, 2018 07:38
solution for withgoogle.com advanced challenge number 1
///////////////////////////////////////////////////////
// solution for the With Google code challenge.
// https://techdevguide.withgoogle.com/paths/advanced/compress-decompression/#code-challenge
// by xealgo
//
// TODO: currently doesn't allow for numbers to be treated as string values,
// only to denote repetitions as per the rule:
// * Digits are only to represent amount of repetitions.
// but adding it would be pretty trivial though.
///////////////////////////////////////////////////////