Skip to content

Instantly share code, notes, and snippets.

@khyperia
khyperia / UnityInertiaTensor.cs
Created February 7, 2023 14:06
Construct a matrix from unity's inertiaTensor and inertiaTensorRotation fields
// Returns the INVERSE inertia tensor in GLOBAL space (not local!)
// Returns a Matrix3x3, but there's no type for that, so waste some space with a Matrix4x4
// Equivalent to GetInertiaTensorGlobal(rb).inverse, but faster
private static Matrix4x4 GetInverseInertiaTensorGlobal(Rigidbody rb) {
Vector3 inertiaTensor = rb.inertiaTensor;
Vector3 inverseInertiaTensor = new(1 / inertiaTensor.x, 1 / inertiaTensor.y, 1 / inertiaTensor.z);
Matrix4x4 rotation = Matrix4x4.Rotate(rb.rotation * rb.inertiaTensorRotation);
// rotation is orthonormal, so inverse=transpose
return rotation * Matrix4x4.Scale(inverseInertiaTensor) * rotation.transpose;
}
using System.Collections;
using UnityEngine;
namespace UnityEngine
{
public interface ICustomYieldInstruction : IEnumerator
{
public bool keepWaiting { get; }
object IEnumerator.Current => null;
@khyperia
khyperia / nonzeroIndex.cs
Created October 11, 2019 14:00
creating an array that starts at 5
using System;
public class C {
public static void Main() {
var arr = Array.CreateInstance(typeof(int), new[]{5}, new[]{5});
Console.WriteLine(arr.Length);
for (var i = 5; i < 10; i++)
arr.SetValue(i * 2, i);
for (var i = 5; i < 10; i++)
Console.WriteLine(arr.GetValue(i));
}
khyperia@argon ~/me/jsparagus/rust/driver % cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `/home/khyperia/me/jsparagus/rust/target/debug/driver`
> 2+2
{
"Script": {
"directives": [],
"statements": [
{
"ExpressionStatement": {
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
email = khyperia@mozilla.com
name = Ashley Hauck
[commit]
gpgsign = false
diff --git a/moz.configure b/moz.configure
index 2484ad553645..b15ef790e420 100755
--- a/moz.configure
+++ b/moz.configure
@@ -645,14 +645,14 @@ def config_status_deps(build_env, build_project):
topsrcdir = build_env.topsrcdir
topobjdir = build_env.topobjdir
- if not build_env.topobjdir.endswith('js/src'):
+ if 'js/src' not in build_env.topobjdir:
class B {
constructor(x) {
console.log(x);
}
}
class C extends B {
}
new C("C"); // prints "C"
// prints 1, 2, 3, 4
function f(x) {
console.log(x);
}
class C {
static [f(1)] = f(3);
static [f(2)] = f(4);
}
@khyperia
khyperia / super.js
Last active June 25, 2019 15:50
Super calls in computed field keys
class C extends B {
field = 2;
constructor() {
class D {
[super()];
}
}
}
// ---
js> dis(class c{x=2;})
flags: CONSTRUCTOR
loc op
----- --
00000: functionthis # THIS
00001: setlocal 0 # THIS
00005: pop #
main:
00006: getgname ".initializers" # .initializers
00011: zero # .initializers 0