Skip to content

Instantly share code, notes, and snippets.

@onionmk2
onionmk2 / Unity Black .js
Last active October 19, 2017 10:12
[docs.unity3d & local] Unity Black - a dark theme with JS/C# syntax highlighting
// ==UserScript==
// @name [docs.unity3d & local] Unity Black - a dark theme with JS/C# syntax highlighting
// @namespace https://greasyfork.org/en/users/10118-drhouse
// @version 1.1
// @description A beautiful dark theme with syntax highlighting (4 color schemes, JS & C#) that improves visual code samples and lowers screen glare.
// @include http://docs.unity3d.com/*
// @include https://docs.unity3d.com/*
// @include file://*Editor/Data/Documentation/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js
@onionmk2
onionmk2 / RGBCube_cginc.cginc
Created October 10, 2017 07:35
use cginc to write hlsl with VisualStudioHLSLTools
// RGBCube.shader
Shader "RGBCube" {
SubShader{
Pass{
CGPROGRAM
#include "Assets\RBGCube\RGBCube_cginc.cginc"
#pragma vertex vert
#pragma fragment frag
ENDCG
}
@onionmk2
onionmk2 / gist:bece8ea5f5d2ac19df2ec655fe66edd4
Last active October 10, 2017 07:33
save a transcript of KhanAcademy's video
const spans = $("ul[itemprop=transcript] li span[class='']");
const array = Array.from(spans);
const texts = array.map(t => t.textContent.replace(/\n/, '') + '\n');
const fileName = $("h1")[0].textContent;
const file = new File(texts, fileName, {
type: "text/plain",
});
const a = document.createElement("a");
@onionmk2
onionmk2 / abs.py
Created August 13, 2017 19:59
絶対値の方程式をsympyで
# http://www7b.biglobe.ne.jp/~h-kuroda/pdf/text_calculus.pdf 1.1(1)を解く
import numpy as np
from sympy import *
# real = trueがないと死ぬ。
# https://stackoverflow.com/questions/33188668/how-to-solve-absolute-value-equations-using-sympy
x = symbols("x", real=True)
f = np.absolute(x + 2) - 4
roots = solve(f, x)
@onionmk2
onionmk2 / eig.py
Last active August 11, 2017 21:09
固有値と固有ベクトル
import numpy as np
from numpy import linalg as LA # Linear algebra の意味。
A = np.array([
[3, -2],
[1, 0]
])
# LA.eig(A) は、「Aの固有値eigenvalues とAの固有ベクトルeigenvectors」を返す。
## なお、pythonは複数値を返せる関数が作れる。 https://hydrocul.github.io/wiki/programming_languages_diff/tuple/return-tuple.html
@onionmk2
onionmk2 / valueVsRef.cs
Last active August 1, 2017 15:35
値と参照。
void Main()
{
var x = 1;
Assign2ToValue(x);
x.Dump();
OutAssign3ToValue(out x);
x.Dump();
var y = new int[] { 4 };
@onionmk2
onionmk2 / WaitAnimation.cs
Last active July 22, 2017 22:33
wait until the animation finishes the <see cref="m_normalizedTime "/> part
using UnityEngine;
// ReSharper disable InconsistentNaming
///<summary>
/// wait until the animation finishes the <see cref="m_normalizedTime "/> part.
/// </summary>
/// <remarks>
/// original code is http://tsubakit1.hateblo.jp/entry/2016/02/11/021743. The credit goes to him.
/// </remarks>
/// <example>
public override TaskStatus OnUpdate()
{
var playerTransform = GetComponent<EnemyStore>().playerTransform;
var distanceFromPlayer = Vector3.Distance(playerTransform.position, transform.position);
// slow down until speed becomes zero.
if (distanceFromPlayer <= GlobalConst.maxRangeOfPlayerNear)
{
GetComponent<Animator>().applyRootMotion = false;