Skip to content

Instantly share code, notes, and snippets.

@JamWils
JamWils / UnityPhysicsRayCastTest.cs
Last active September 13, 2023 09:27
This is some sample code on how to test Unity Physics properly, this uses version 1.0.14. This sets up a sphere collider and draw a ray through the center of it along the y-axis. Please note the `LocalTransform` component, this needs to be included for the collider to work properly in a unit test.
// Original credit: https://forum.unity.com/threads/testing-systems-performing-raycasts.1031335/
public class BaseSystemTest : ECSTestsFixture {
protected EntityManager entityManager;
protected SystemHandle physicsWorldSystem;
protected SystemHandle collisionWorldSystem;
[SetUp]
public override void Setup() {
base.Setup();
@JamWils
JamWils / gist:397a73e64b8aeb56e9c484e94b8c1d82
Last active August 6, 2021 19:49
Golang: Interface vs Struct

Golang: Interface vs Struct

Some one asked me the question, how do you decide when to make an interface vs just instantiating a struct?

Honestly, this is not a perfect answer, but here are some simple guidelines that I would follow when creating an interface or just creating a simple struct.

Let's start with a simple object Person. There is nothing astronomical about the object and it contains some simple information. Here there isn't much to create

type Person struct {
@JamWils
JamWils / index.js
Created January 25, 2018 14:45
Stack Overflow Help
// For help with question at https://stackoverflow.com/questions/48427217/nodejs-reading-file-does-not-work
const fs = require('fs');
const path = require('path');
console.log('beforereadfile');
fs.readFile(path.join('.', '/test.json'), 'utf8', function (err, data) {
if (err) {
console.log('Error loading client secret file: ' + err);
# Delete all exited containers
docker rm $(docker ps -q -f status=exited)
# Delete all images with no tags
docker rmi $(docker images -q -f "dangling=true")
# Plugins -> Network
docker info
# Create a new network
@JamWils
JamWils / Git Aliases
Last active June 15, 2020 17:28
Git aliases I use on a day-to-day basis
git config --global alias.s "status -s"
git config --global alias.bc="branch --sort=-committerdate"
git config --global alias.lg "log --oneline --decorate --graph"
git config --global alias.lgb "log --graph --oneline --decorate --first-parent"
// Calling log for branch
git lgb <branch_name>
const client = require('firebase-tools');
client.database.set('/', './mockData/db.json', {
project: 'my-test-project',
token: process.env.FIREBASE_TOKEN,
cwd: './'
});
const json = mockDataSchema.schema();
const jsonFormatted = JSON.stringify(json);
fs.writeFile("./mockData/db.json", jsonFormatted, (err) => {
if (err) {
return console.log(chalk.red(err));
} else {
console.log(chalk.green("Mock data generated."));
}
});
exports.schema = function () {
let parent = {}
parent.users = createUsers(3, 7);
return parent;
}
function randomIntInc(low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
}
function createUsers(low, high) {
let items = {};
const generatedItems = randomIntInc(low, high);
for (let i = 0; i < generatedItems; i++) {
const item = {}
@JamWils
JamWils / chanceSample.js
Last active June 8, 2017 19:00
Small Chance Sample
const item = {}
item.uid = chance.guid();
item.email = chance.email();
item.profileImageUrl = chance.avatar();
item.username = chance.name();