Skip to content

Instantly share code, notes, and snippets.

View NattyNarwhal's full-sized avatar
🐪
ML stands for metalanguage, not machine learning

Calvin Buckley NattyNarwhal

🐪
ML stands for metalanguage, not machine learning
View GitHub Profile
public static string TranslateString(this string original, Dictionary<char, char> mapping)
{
return new string(original.Select(c => mapping.ContainsKey(c) ? mapping[c] : c).ToArray());
}
for (int i = 2; i <= step; i++)
{
var rd = (c1.R > c2.R ? c1.R - c2.R : c2.R - c1.R) / i;
var gd = (c1.G > c2.G ? c1.G - c2.G : c2.G - c1.G) / i;
var bd = (c1.B > c2.B ? c1.B - c2.B : c2.B - c1.B) / i;
if (showDiff)
{
var nc = new RgbColor(rd, gd, bd);
bc.Add(nc);
}
const char esc = (char)0x1b;
// not all terms support this; in case not, a muxer like tmux or screen will approximate it
public string TrueColorEscaped(string obj, int r, int g, int b) {
// <ESC>[38;2;{r};{g};{b}m sets a true color color
// <ESC>[0m resets color
return String.Format("{0}[38;2;{1};{2};{3}m{4}{0}[0m", esc, r, g, b, obj);
}
foreach (var i in Enumerable.Range(0, 255))
@NattyNarwhal
NattyNarwhal / epoch.md
Last active December 13, 2016 16:37
PC Epochs

Dates are approximate. I’d argue 1996 and 2006 were smaller epochs mostly localized to the PC industry; but 2001 and 2011 had much larger rippling effects.

1977-1979: Apple II and VisiCalc

The Apple II and Commodore PET become popular in business with titles such as VisiCalc, the early computer spreadsheet. This proves the utility of PCs in that field. The Apple II also finds a niche in education with titles like the Oregon Trail.

1981-1983: Video Game Crash, IBM PC, Affordable Computers

The Commodore 64 and ZX Spectrum become very popular computers due to their decent set of features for a very low price. The IBM PC comes out and legitimizes the personal computing industry. Poor quality titles and overproduction cause the Atari 2600 and its competitors to collapse, creating a stigma around video game consoles.

1984-1987: Graphical Revolution

The Macintosh had introduced a bitmapped, easy to use system with a consistent HIG, and others followed. The Acorn Archimedes comes out in the UK, and its CPU,

@NattyNarwhal
NattyNarwhal / Game1.cs
Created October 17, 2017 14:27
smarting about XNA
// quick hack
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace MonoGameTest
{
public class Game1 : Game
{
diff --git a/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs b/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs
index 16e4366..12716af 100644
--- a/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs
+++ b/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs
@@ -6063,8 +6063,8 @@ namespace System.Net.Sockets {
bool ipv6 = true;
#if MONO
- ipv4 = IsProtocolSupported (System.Net.NetworkInformation.NetworkInterfaceComponent.IPv4);
- ipv6 = IsProtocolSupported (System.Net.NetworkInformation.NetworkInterfaceComponent.IPv6);
@NattyNarwhal
NattyNarwhal / powerpc_interp_tramp.patch
Created February 10, 2018 17:30
skeleton of POWER interpeter trampoline
diff --git a/mono/mini/mini-ppc.h b/mono/mini/mini-ppc.h
index 167f6ed..ff29d54 100644
--- a/mono/mini/mini-ppc.h
+++ b/mono/mini/mini-ppc.h
@@ -264,6 +264,8 @@ typedef struct MonoCompileArch {
#endif
#define MONO_ARCH_HAVE_OP_TAIL_CALL 1
+#define MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP
+
@NattyNarwhal
NattyNarwhal / asynccb.patch
Last active February 20, 2018 22:27
broken async callback setup patch
diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c
index 4101eaf..df5fdbd 100644
--- a/mono/mini/exceptions-ppc.c
+++ b/mono/mini/exceptions-ppc.c
@@ -811,6 +811,28 @@ mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), g
sp -= PPC_MINIMAL_STACK_SIZE;
*(unsigned long *)sp = MONO_CONTEXT_GET_SP(ctx);
MONO_CONTEXT_SET_BP(ctx, sp);
- MONO_CONTEXT_SET_IP(ctx, (unsigned long) async_cb);
+ mono_arch_setup_resume_sighandler_ctx(ctx, (unsigned long) async_cb);
@NattyNarwhal
NattyNarwhal / exception.cs
Last active March 1, 2018 14:39
gdb session
using System;
public class Offending {
public static int i;
static Offending() {
throw new Exception("Broken");
}
public static void Hello() {
@NattyNarwhal
NattyNarwhal / diff.patch
Created March 5, 2018 22:14
aaaaaaa i hate trampolines
diff --git a/mono/mini/tramp-ppc.c b/mono/mini/tramp-ppc.c
index bfbeca9..a1d39e5 100644
--- a/mono/mini/tramp-ppc.c
+++ b/mono/mini/tramp-ppc.c
@@ -241,10 +241,10 @@ guchar*
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
{
char *tramp_name;
- guint8 *buf, *code = NULL;
+ guint8 *buf, *code = NULL, *exception_branch;