Skip to content

Instantly share code, notes, and snippets.

module Program
open System
open Funogram.Bot
/// Handles all Telegram events.
let update context =
context.Update.UpdateId
|> printfn "Received update: %i"
@worldbeater
worldbeater / Commands.fs
Last active March 17, 2019 20:34
Funogram Greetings Bot
module Program
open Funogram.Bot
open Funogram.Api
open ExtCore.Control
open System
/// Handler for '/hello'.
let onHello context =
maybe {
public sealed partial class FeedbackView : Page, IViewFor<FeedbackViewModel>
{
public static readonly DependencyProperty ViewModelProperty = DependencyProperty
.Register(nameof(ViewModel), typeof(FeedbackViewModel), typeof(FeedbackView), null);
public FeedbackView()
{
InitializeComponent();
ViewModel = new FeedbackViewModel(new UwpSender(), new Clock());
this.WhenActivated(disposables => { /* handle interactions, etc. */ });
public class ReactiveFodyViewModel : ReactiveObject
{
private readonly ObservableAsPropertyHelper<string> _greeting;
public string Greeting => _greeting.Value;
[Reactive]
public string Name { get; set; } = string.Empty;
public ReactiveCommand<Unit, Unit> Clear { get; }
public partial class FeedbackView : Form, IViewFor<FeedbackViewModel>
{
public FeedbackView()
{
InitializeComponent();
ViewModel = new FeedbackViewModel(new WinFormsSender(), new Clock());
this.WhenActivated(subscriptions =>
{
this.Bind(ViewModel, x => x.Title, x => x.TitleTextBox.Text)
.DisposeWith(subscriptions);
@worldbeater
worldbeater / StyleManager.cs
Last active August 1, 2023 21:53
StyleManager helper class, allowing to change Avalonia theme which a Window uses dynamically at runtime. See: https://medium.com/swlh/cross-platform-gui-for-dotnet-applications-bbd284709600
public sealed class StyleManager
{
public enum Theme { Citrus, Sea, Rust, Candy, Magma }
private readonly StyleInclude _magmaStyle = CreateStyle("avares://Citrus.Avalonia/Magma.xaml");
private readonly StyleInclude _candyStyle = CreateStyle("avares://Citrus.Avalonia/Candy.xaml");
private readonly StyleInclude _citrusStyle = CreateStyle("avares://Citrus.Avalonia/Citrus.xaml");
private readonly StyleInclude _rustStyle = CreateStyle("avares://Citrus.Avalonia/Rust.xaml");
private readonly StyleInclude _seaStyle = CreateStyle("avares://Citrus.Avalonia/Sea.xaml");
private readonly Window _window;
@worldbeater
worldbeater / cognitive-complexity.py
Last active March 26, 2025 14:17
Precise library for complexity assessment algorithm synthesis, see our paper "A Rule-Based Algorithm and Its Specializations for Measuring the Complexity of Software in Educational Digital Environments" @ https://www.mdpi.com/2073-431X/13/3/75
import ast
def check(rules, env, node, parent):
total, names = 0, []
for name, (spec, check, weight) in rules.items():
if isinstance(node, spec) and check(node, parent):
if score := weight(env, node) if callable(weight) else weight:
total += score
names.append(name)
return total, '+'.join(names)
@worldbeater
worldbeater / П1.py
Last active July 18, 2024 12:45
Sample programs for debugging intelligent static analysis tool which uses program representations based on Markov chains constructed from AST, see https://vestnik.rsreu.ru/ru/archive/2023/vypusk-86/1455-1995-4565-2023-86-96-109
# type: ignore
def query():
array = []
for i in range(10000):
array.append(i * 2)
def tree():
a = 10
nums = [] # A1
@worldbeater
worldbeater / enumerate-and-replace.vba
Last active December 25, 2024 17:51
A Visual Basic for Applications (VBA) code for finding all references (e.g. [42], [2—3, 4]) and increasing their numbers based on the preconfigured N and M values. Useful when inserting a new reference into the beginning of the bibliography of a large DOCX.
Sub Highlight(Phrase As String)
Application.ScreenUpdating = False
With ActiveDocument
With .Range
With .Find
.ClearFormatting
.replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindStop
@worldbeater
worldbeater / trs.py
Last active April 29, 2024 00:10
Simple term rewriting system (TRS) that is based on structural pattern matching, see https://peps.python.org/pep-0636 and https://inst.eecs.berkeley.edu/~cs294-260/sp24/2024-01-22-term-rewriting
def topdown(rule, expr):
match rule(expr):
case (spec, *args):
return (spec, *(topdown(rule, arg) for arg in args))
case expr:
return expr
def rewrite(rule, expr):
while (new_expr := topdown(rule, expr)) != expr:
expr = new_expr