Skip to content

Instantly share code, notes, and snippets.

View james-world's full-sized avatar

James World james-world

View GitHub Profile
@james-world
james-world / Program.cs
Created February 19, 2026 10:21 — forked from tomhawkin/Program.cs
C# port of MicroGPT
// This is a C# port of @karpathy microgpt python script (https://gist.github.com/karpathy/8627fe009c40f57531cb18360106ce95)
// It's the closest I could get using C#.
// Use with caution as it could be wrong, but it does seem to get similar outputs
namespace MicroGpt;
public class Value(double data, Value[]? children = null)
{
private readonly Value[] _children = children ?? [];
private Action _backward = () => { };
@james-world
james-world / codingagent.cs
Last active December 17, 2025 13:26
This is a single-file application of a functional coding-agent (like e.g. Claude Code) using Microsoft Agent Framework in just 99 lines of code. See comments.
#!/usr/local/share/dotnet/dotnet run
#:package Microsoft.Agents.AI.OpenAI@1.0.0-preview.251113.1
#:package OpenAI@2.7.0
using OpenAI;
using Microsoft.Extensions.AI;
using System.ComponentModel;
using static System.Console;
var openAIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
@james-world
james-world / lucky_numbers.py
Created November 23, 2024 22:45
Calculate lucky numbers with no repeating digits in python.
def generate_lucky_numbers(limit):
# Start with a list of odd numbers up to 'limit'
numbers = list(range(1, limit + 1, 2))
idx = 1 # Start with the second number in the list (index 1)
while idx < len(numbers):
step = numbers[idx]
if step >= len(numbers):
break
# Remove every 'step'-th number from the list, starting from the 'step'-1 index
@james-world
james-world / getNext.js
Created August 21, 2020 23:35
CosmosDb stored procedure to generate the next number in a 7-digit non-repeating pseudo random sequence.
function getNext(name) {
var response = getContext().getResponse();
var result = __.chain()
.filter(function(doc) { return doc.id === name; })
.value({}, updateCounter);
if(!result.isAccepted) throw new Error("The call was not accepted");
var next;
@james-world
james-world / SODiscards.cs
Created July 10, 2020 08:57
Dangers of stand alone discards
void Main()
{
Test1(5);
Test2(5);
}
void Test1(int _)
{
_ = 2 + 2;
Console.WriteLine(_);
@james-world
james-world / FetchAll.ps1
Created April 23, 2020 15:53
Put these in a directory containing all your repos. Run FetchAll it to get latest remote changes for all repos in sub-directories, Run UpdateMain to update the main branch in all repos with main checked out and without local changes.
# Get latest remote changes for all repos in sub-directories
Write-Output "Fetching remote repositories..."
Get-ChildItem -Directory |
# Has a hidden .git directory (i.e. is a repository)
Where-Object { ( $_ | Get-ChildItem -Hidden ).Name -contains ".git" } |
# Has at lease one remote
Where-Object { Push-Location $_; (git remote).Count -gt 0; Pop-Location } |
# Fetch remote changes
ForEach-Object { Push-Location $_; "Checking $_..."; git fetch; Pop-Location; "`t...Done"; }
@james-world
james-world / FSharpTalk.md
Last active December 6, 2019 17:04
Notes from a talk on FSharp
@james-world
james-world / Get-GitIgnore.ps1
Created October 20, 2018 14:55
Powershell command to create a .gitignore file from .gitignore.io
function Get-GitIgnore {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string[]]
$Targets,
[string]
$OutputDirectory = "$PWD",
[string]
$Filename = ".gitignore",
@james-world
james-world / decorators.cs
Created April 2, 2017 12:47
Demostrates unexpected decorator behaviour in Auto 4.4.0
// Suitable for LINQPad with the Autofac nuget package
void Main()
{
ExpectedBehaviour();
UnexpectedBehaviour();
}
public void ExpectedBehaviour()
{
@james-world
james-world / LeakyGenerate.cs
Last active December 20, 2016 03:14
Demonstrate leakiness of Generate and recursive Schedule
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;