Skip to content

Instantly share code, notes, and snippets.

View michaelbartnett's full-sized avatar

Michael Bartnett michaelbartnett

View GitHub Profile
@michaelbartnett
michaelbartnett / gh-goto-commit.js
Last active August 29, 2015 14:25
I usually want a link to a commit-relative blob rather than a branch-relative blob. Gimme a bookmarklet for that.
(function () {
function getCommitHash() {
var commitLink = document.querySelectorAll('.commit-title a.message')[0];
return commitLink.pathname.split('/').slice(-1)[0];
}
function replaceBranchWithCommit(branchURL, commitHash) {
return branchURL.replace(/\/blob\/[^\/]+\//, '/blob/' + commitHash + '/');
}
@michaelbartnett
michaelbartnett / UnityLifetime.cs
Created July 14, 2015 16:31
Not sure if this is useful.
[Flags]
public enum UnityLifetime
{
Nothing = 0x00,
Awoke = 0x01,
Started = 0x02,
Destroyed = 0x04,
}
@michaelbartnett
michaelbartnett / makegif.sh
Created July 2, 2015 04:39
Script to turn a video file into a gif with ffmpeg, sips, and gifsicle
#!/usr/bin/env bash
# Turn a video into a gif
# Written with help from:
#
# http://chrismessina.me/b/13913393/mov-to-gif
# http://www.lcdf.org/gifsicle/man.html
#
# It's not very robust.
// whoops
csharp> Action<Action> makeInvoker = (funarg) => new Action(() => funarg());
Mono.CSharp.InternalErrorException: (1,31): <InteractiveExpressionClass>.<Host>m__0(System.Action) ---> Mono.CSharp.InternalErrorException: (1,1): ---> System.NotImplementedException: The requested feature is not implemented.
at Mono.CSharp.AnonymousMethodBody.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ContextualReturn.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
@michaelbartnett
michaelbartnett / ytembedded.js
Last active August 30, 2016 20:58
Just show me the embedded video page. (bookmarklet)
// YTEMBEDDED
// The youtube page can't go full-window, and full-screen mode in browser is annoying.
// Solution: make it easy to go to a youtube video's embed URL.
//
// Tries to grab the current video time. If that fails, it looks for a ?t query parameter.
// Otherwise you just get to watch the video from the beginning.
(function () {
function extractQueryParams(search) {
return (search.slice(1).
split('&').
@michaelbartnett
michaelbartnett / output.log
Created May 29, 2015 07:04
omnisharp-roslyn restore package exception
zsh 1 [1] % ./build.sh
Downloading kvm as script to '/Users/michaelbartnett/.k/kvm'
Downloading kvm from 'https://raw.githubusercontent.com/aspnet/Home/master/kvm.sh'
=> Source string already in /Users/michaelbartnett/.bash_profile
=> Source string already in /Users/michaelbartnett/.zshrc
Type 'source /Users/michaelbartnett/.k/kvm/kvm.sh' to start using kvm
Downloading kre-mono.1.0.0-beta3 from https://www.nuget.org/api/v2
Installing to /Users/michaelbartnett/.k/runtimes/kre-mono.1.0.0-beta3
Adding /Users/michaelbartnett/.k/runtimes/kre-mono.1.0.0-beta3/bin to process PATH
@michaelbartnett
michaelbartnett / CharacterListScriptThing.cs
Created March 30, 2015 00:52
Finally. Handles.Label.
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class CharacterListScriptThing : MonoBehaviour
{
@michaelbartnett
michaelbartnett / NetsedLambdaFail.cs
Last active August 29, 2015 14:11
Unity3D compiler bug
// This function causes the error pasted below it:
public class GameDataDefinitionWebProvider
{
// skipping several things...
public IFuture<IEnumerable<GameDataDefinition>> FetchAll()
{
var result = new SimpleFuture<IEnumerable<GameDataDefinition>>();
@michaelbartnett
michaelbartnett / PrewarmAnimations.cs
Created December 8, 2014 20:37
Prewarming unity animations in order to prevent Animation.RebuildInternalState frame time sadness
public void PrewarmAnimations()
{
// Animation.RebuildInternalState causes massive frame spikes
// http://forum.unity3d.com/threads/animation-rebuildinternalstate-ms-spikes.123480/#post-1560774
// This iterates through the animations to read them into memory in order to try avoiding this.
int animationCount = 0;
foreach (var anim in animationRootObject.animation) {
animationCount++;
}
}
@michaelbartnett
michaelbartnett / GrossLinq.cs
Created October 23, 2014 02:18
monodevelop sigh
from assembly in AppDomain.CurrentDomain.GetAssemblies()
#if TEST
let typeList =
(new Func<Type[]>(() => {
Type[] result = null;
try {
result = assembly.GetTypes();
} catch (ReflectionTypeLoadException) {
if (assembly.FullName.StartsWith("MonoDevelop.NUnit")) {
// the MonoDevelop.NUnit assembly is screwed up