Skip to content

Instantly share code, notes, and snippets.

@xanth
xanth / Manage-CodeTunnel.ps1
Last active May 17, 2026 10:49
VSCode Tunnel Windows Watchdog
#Requires -Version 5.1
<#
.SYNOPSIS
Manage the VS Code tunnel watchdog scheduled task (non-admin).
.DESCRIPTION
Wraps Watch-CodeTunnel.ps1 in a per-user scheduled task that runs at
logon and repeats every IntervalMinutes. All operations are non-admin:
the task is registered under the current user with limited run level,
and stop/start operate only on the current user's processes and task.
void Main()
{
var bom = "\uFEFF";
var baseString = "Hello World";
var withBom = bom + baseString;
var a = System.Text.Encoding.UTF8.GetBytes(EnsureBom(baseString));
var b = System.Text.Encoding.UTF8.GetBytes(EnsureBom(withBom));
public class ChangeDetector<TP, TPx>
{
private List<IPropertyChangedDetector<TP, TPx>> ChangedDetectors { get; } = new List<IPropertyChangedDetector<TP, TPx>>();
public ChangeResults Changes(TP tp, TPx tpx) => ChangedDetectors.Select(cd => cd.Changed(tp, tpx)).Map(cds => new ChangeResults(cds));
public ChangeDetector<TP, TPx> Add(IPropertyChangedDetector<TP, TPx> c)
{
ChangedDetectors.Add(c);
using System;
using System.Collections.Concurrent;
namespace Memoize
{
public class Memoize<TKey, TValue>
{
private readonly Func<TKey, TValue> retriever;
private readonly ConcurrentDictionary<TKey, TValue> cache = new ConcurrentDictionary<TKey, TValue>();
func buildPerson() -> Person?{
let manditory = [firstNameField.text, lastNameField.text];
if (manditory.reduce(ageField.text != nil, combine: {$0 && $1 != nil})){
return Person(firstName: firstNameField.text, lastName: lastNameField.text, age: (ageField.text).toInt()!, middleName: midleNameField.text);
}
else{
return nil;
}
}
@xanth
xanth / gist:eaf4c911f6eaa0070515
Last active August 29, 2015 14:07
Database Population Gone Funny

For a university project (Software Engineering) we have to as a group of 5 design and build a ordering system. Long story short we decided to go with Nodejs and the Sails framework.

After @OSN64 had done the heavy lifting it cam time to populate the DB so I made little module that populates the DB with all the entrees from wikipedia and chains some random food words I found on a blog and it resulted in this.

screenshot

I'm sure I haven't done things optimally but this was my quick and dirty way of filling the DB.

@xanth
xanth / gist:94eae1a7947cb80b6f75
Last active August 29, 2015 14:05
Why use chained functions in spreadsheets when you write JavaScript

But Why

I needed to get the value of several cells in one cell speratted by commas and the row number (multiple values also sperated by commas) is all that was provided.

A B C
1 ID Predecessors ID Predecessors
2 1
3 1.1 2
4 1.2 4, 2
@xanth
xanth / Rhys'_Minecraft_simple-start_script.md
Last active August 29, 2015 13:58
simple-start Minecraft server starter

Rhys' Minecraft simple-start script

I cleaned up my code and comment every non trivial line so you wont have too much trouble maintaining it. this was not intended to be cross platform however you may be able to use cygwin to run it under Windows.

#Setup

  • Make sure you have the dependencies.
  • Download the files below.
  • Place the addressbook, pswd and simple-start.sh files in the same directory as the minecraft_server.jar.
  • Directory may not have any spaces in its name.
Processor Information:
Vendor: GenuineIntel
CPU Family: 0x6
CPU Model: 0x3a
CPU Stepping: 0x9
CPU Type: 0x0
Speed: 3001 Mhz
4 logical processors
4 physical processors
HyperThreading: Unsupported