Skip to content

Instantly share code, notes, and snippets.

View pmcgee69's full-sized avatar

Paul McGee pmcgee69

  • Perth, Western Australia
View GitHub Profile
@sebfisch
sebfisch / gist:2235780
Created March 29, 2012 10:47
Laymans explanation of delimited continuations with examples of using them for exception handling and nondeterministic programming.

Delimited Continuations

Delimited continuations manipulate the control flow of programs. Similar to control structures like conditionals or loops they allow to deviate from a sequential flow of control.

We use exception handling as another example for control flow manipulation and later show how to implement it using delimited continuations. Finally, we show that nondeterminism can also be expressed using delimited continuations.

Exception Handling

@rkennedy
rkennedy / JclWideFormat.pas
Last active December 1, 2022 06:20
My Unicode-enabled Format function for Delphi. It was part of the JCL, but was removed in 2010 when the JCL dropped support for older Delphi versions. Newer versions already included a comparable function, although this version includes some extensions that Delphi doesn't have (see FORMAT_EXTENSIONS).Source: https://github.com/project-jedi/jcl/c…
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
@tobek
tobek / get-image-urls.js
Last active July 18, 2024 17:22
Save images from chrome inspector/dev tools network tab
/* open up chrome dev tools (Menu > More tools > Developer tools)
* go to network tab, refresh the page, wait for images to load (on some sites you may have to scroll down to the images for them to start loading)
* right click/ctrl click on any entry in the network log, select Copy > Copy All as HAR
* open up JS console and enter: var har = [paste]
* (pasting could take a while if there's a lot of requests)
* paste the following JS code into the console
* copy the output, paste into a text file
* open up a terminal in same directory as text file, then: wget -i [that file]
*/
@jsbattig
jsbattig / DelphiSwitchToFiber.pas
Last active July 28, 2023 18:55
Unit to properly SwitchToFiber() in Delphi without breaking exception handling
{
The idea of DelphiSwitchToFiber() function is to backup on a local variable in stack the
state of the Exception stack right before calling SwitchToFiber() and then restoring its state
right atfer returns from call to SwitchToFiber().
If SwitchToFiber() is used directly from within an Except or Finally block, and if there's an exception
raised after switching to another fiber, upon coming back the results will be unpredictable because
the exception stack will be completely unwinded and all raise exceptions destroyed.
In order to prevent this issue we must backup the Exception stack before the call to SwitchToFiber()
and restore it right after the call.
@breadchris
breadchris / Delphi.md
Last active May 24, 2021 17:59
Bsides Vancouver CTF 2015 - Delphi (200 ownable) Writeup

Delphi

files given:

  • delphi-07a5c9d07a4c20ae81a2ddc66b9602d0dcceb74b
  • libtwenty.so-4a3918b2efd9fbdfd20eeb8fa51ca76bc42eb2f2

TL;DR

  • Reverse Command Protocol
  • Integer Overflow
  • Metacharacter Injection
@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
@mcleary
mcleary / Timer.cpp
Last active March 27, 2024 02:42
C++ Timer using std::chrono
#include <iostream>
#include <chrono>
#include <ctime>
#include <cmath>
class Timer
{
public:
void start()
{
/*
* 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;
@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;
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active July 17, 2024 07:40
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