Skip to content

Instantly share code, notes, and snippets.

View pmcgee69's full-sized avatar

Paul McGee pmcgee69

  • Perth, Western Australia
View GitHub Profile
@DelphiWorlds
DelphiWorlds / AddingStrings.pas
Last active August 9, 2024 13:36
StringList value type alternative
type
StringList = TArray<string>;
StringListHelper = record helper for StringList
public
procedure Add(const AValue: string);
end;
{ StringListHelper }
@amakukha
amakukha / mostfreq.cpp
Last active August 7, 2022 18:01
Find k most frequent words in a file (fast implementation)
/*
* Solution of the Jon Bentley's k most frequent words problem using a prefix tree and
* a heap of size k. Worst case time complexity is O(N log k), where N is the total
* number of words.
*
* The problem is formulated in the Communications of the ACM 29,5 (May 1986), 364-369:
* "Given a text file and an integer k, you are to print the k
* most common words in the file (and the number of their
* occurrences) in decreasing frequency."
*
@fatcerberus
fatcerberus / monads4all.md
Last active October 19, 2024 07:42
Monads for the Rest of Us

Monads for the Rest of Us

by Bruce Pascoe - 1 May, 2019

"A monad is just a monoid in the category of endofunctors. What's the problem?" ~James Iry[^1]

The problem... is that there are several problems.

It's been said that monads bear a dreadful curse. Once you finally understand what they are, you begin to see them everywhere--but somehow become completely incapable of explaining them to anyone else. Many tutorial writers have tried to break the Great Curse--the Web is lousy with bold attempts and half successes that attest to this--and just as many have failed. Well, I'm here to address the elephant in the room[^2] and tell you that I intend to break the Great Curse once and for all.

There are basically two ways a monad tutorial tends to go. One is a paragraph or two of minimal descriptions of one or two common monads (Haskell's Maybe in particular is very popular), followed by a lot of intimidating Haskell syntax trying to explain--precisely--how it all fits together. This is well

@brilvio
brilvio / .gitlab-ci.yml
Created March 5, 2018 20:42
Gitlab-CI Delphi
stages:
- build
test:
stage: build
environment:
name: staging
script:
- git submodule update --init --remote #if you don't have submodules in your project you can remove this line
- SET BDS=C:\\Program Files (x86)\\Embarcadero\\Studio\\15.0
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 26, 2025 00:19
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@Brutt
Brutt / BlobToTImage
Created December 27, 2016 16:22
Load blob to TImage Delphi
procedure LoadImageFromDbToTImage(img: TImage; Field: string; id: integer);
var
memStream: TMemoryStream;
Graphic: Graphics.TGraphic;
bm: Graphics.Tbitmap;
begin
odsImages.Close;
odsImages.SetVariable('id', id); //ИД картинки
odsImages.Open;
/*
* Coroutines.
*
* To make a (fake) coroutine we use these macros. A coroutine method must be static,
* return bool and needs a parameter (Generator & generator).
*
* Generator must follow this schema:
* struct Generator {
* int line;
* float time;
@mcleary
mcleary / Timer.cpp
Last active April 29, 2025 17:37
C++ Timer using std::chrono
#include <iostream>
#include <chrono>
#include <ctime>
#include <cmath>
class Timer
{
public:
void start()
{
@subfuzion
subfuzion / curl.md
Last active May 8, 2025 13:29
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@twopoint718
twopoint718 / Reader.lhs
Last active April 21, 2024 11:15
An article about the Reader type (functor, applicative, and monad instances)
Okay, so I'll try and walk through the reader monad as best as I can. And
because I think it helps to de-mystify things a bit, I'll also go through
all of the "super classes" of monad: functor and applicative (because every
monad should also be an applicative and every applicative functor should be
a functor). This file is literate Haskell so you should just be able to
load it in the REPL or run it. It's also kinda/sorta markdown, so it should
render that way as well (but the code is formatted wrong).
> module Reader where