Skip to content

Instantly share code, notes, and snippets.

View andylshort's full-sized avatar

Andrew Lamzed-Short andylshort

View GitHub Profile
@andylshort
andylshort / live_dict.py
Created April 13, 2020 16:20
python curses library - interactive dictionary search
import sys
import curses
def filter_words(words, start):
return list(filter(lambda s: s.startswith(start), words))
if __name__ == "__main__":
words = []
with open("words.txt", "r") as f:
words = [l.strip() for l in f.readlines()]
@andylshort
andylshort / flask_cal.py
Created April 13, 2020 16:19
iCalendar via Flask
from flask import Flask, send_file, make_response, jsonify
from icalendar import Calendar, Event
from datetime import datetime, timedelta
from pytz import UTC
import atexit
import json
import os
import tasks
@andylshort
andylshort / jit_fail.cpp
Created April 3, 2020 16:04
Minimal failing example of ClangJIT and Kokkos/mdspan
#include <experimental/mdspan>
#include <iostream>
#include <cstdlib>
#include <array>
namespace stdex = std::experimental;
template<const int x, const int y>
[[clang::jit]] void
kernel(stdex::mdspan<double, x, y>& f)
@andylshort
andylshort / Ackermann.cs
Created July 30, 2019 18:35
Ackermann C#
static int Ackermann(int m, int n)
{
if (m == 0)
{
return n + 1;
}
else if (n == 0)
{
return Ackermann(m - 1, 1);
}
@andylshort
andylshort / WorkDays.cs
Created July 11, 2019 19:58
Get work days between two dates
private double GetWorkDays(DateTime Start, DateTime End)
{
double WorkDays = 1 + ((End - Start).TotalDays * 5 - (Start.DayOfWeek - End.DayOfWeek) * 2) / 7;
if (End.DayOfWeek == DayOfWeek.Saturday) WorkDays--;
if (Start.DayOfWeek == DayOfWeek.Sunday) WorkDays--;
return WorkDays;
}
@andylshort
andylshort / ReservedFileNameTool.cs
Created October 29, 2018 16:48
Windows has reserved filenames, this prevents clashes and problems
using System.IO;
/// <summary>
/// Contains logic for detecting reserved file names in Windows.
/// </summary>
static class ReservedFileNameTool
{
/// <summary>
/// Reserved file names in Windows.
@andylshort
andylshort / Coin.cs
Created October 29, 2018 16:44
Coin flipper
using System;
namespace Coin
{
class Program
{
static void Main(string[] args) => Console.WriteLine(new Random().Next(0, 1000) % 2 == 0 ? "Heads" : "Tails");
}
}
@andylshort
andylshort / RockPaperScissorsLizardSpock.cs
Created October 29, 2018 16:39
Small C# implementation of RSPLS
using System;
using System.Threading;
namespace RockPaperScissorsLizardSpock
{
class Program
{
static void Main(string[] args)
{
int[,] WinMatrix = new int[5, 5]
@andylshort
andylshort / Product Key.vbs
Created April 3, 2018 20:18
Get Windows Product Key
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
@andylshort
andylshort / RPN.java
Created March 28, 2018 19:06
Simple Reverse Polish Notation Implementation
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Stack;
public class ReversePolish {
private ReversePolish() { }