Skip to content

Instantly share code, notes, and snippets.

View AnthonyCalandra's full-sized avatar

Anthony Calandra AnthonyCalandra

View GitHub Profile
---
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
@AnthonyCalandra
AnthonyCalandra / stackwalk64.cpp
Last active September 22, 2023 16:21
A working StackWalk64 (AMD)
#include <windows.h>
#include <processsnapshot.h>
VOID MyStackWalk(HANDLE hThread)
{
// TODO: make it intel-friendly too
STACKFRAME64 sfStackFrame{};
sfStackFrame.AddrPC.Offset = context.Rip;
sfStackFrame.AddrFrame.Offset = context.Rbp;
sfStackFrame.AddrStack.Offset = context.Rsp;
@AnthonyCalandra
AnthonyCalandra / is_narrowing_trait.cc
Created May 16, 2022 02:29
Type trait to see if calling a function with given arguments causes a narrowing conversion for any parameter.
#include <tuple>
#include <type_traits>
// Type trait to see if calling a function with given arguments
// causes a narrowing conversion for any parameter. Implementation
// currently only tested with C linkage functions (e.g. Windows API functions).
namespace detail
{
template <typename...>
#ifndef HASHMAP_HH
#define HASHMAP_HH 1
#include <memory>
#include <utility>
#include <functional>
#include <vector>
#include "hash_policy.hh"
template <
#lang racket
(define eval-mcl
(lambda (line [env '()])
(let* ([atom? (lambda (a) (or (number? a) (boolean? a)))]
[evaluated-pair? (lambda (ls) (pair? (eval-mcl ls env)))]
[evaluated-atom? (lambda (a) (atom? (eval-mcl a env)))]
[zip (lambda (ls1 ls2) (map cons ls1 ls2))])
(match line
[`(quote ,a) a]
#lang racket
;; Node: Number, Node | Null, Node | Null
(struct node (x left right) #:transparent)
;; height: Node | Null -> Number
(define height
(lambda (tree)
(if (null? tree)
-1
#ifndef HASH_POLICY_HH
#define HASH_POLICY_HH 1
#include <string>
template <typename KeyType>
struct SimpleHashPolicy {
static const unsigned int hash(const KeyType k, const unsigned int tableSize) {
return k % tableSize;
}
#lang racket
;; MTF: List[Any]
(struct mtf-list (list) #:transparent)
;; Examples:
;; (mtf 1 2 3) -> (mtf-list '(1 2 3))
;; (mtf 1) -> (mtf-list '(1))
;; (mtf) -> (mtf-list '())
(define-syntax mtf
#lang racket
;; Node: Number, Node | Null, Node | Null
(struct node (x left right) #:transparent)
;; bst-add: Node | Null -> Node
(define bst-add
(lambda (tree v)
(if (null? tree)
; Add the root node to an empty tree.