Skip to content

Instantly share code, notes, and snippets.

@hirrolot
hirrolot / tagless-final.rs
Last active December 2, 2024 20:28
Tagless-final encoding of a simple arithmetic language in Rust
trait Interp {
type Repr<T>;
fn lit(i: i32) -> Self::Repr<i32>;
fn add(a: Self::Repr<i32>, b: Self::Repr<i32>) -> Self::Repr<i32>;
}
struct Eval;
impl Interp for Eval {
@michaeloyer
michaeloyer / srtp.fsx
Last active July 1, 2024 03:15
F# SRTP Example
// SRTP: Statically Resolved Type Parameters
// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters
// SRTP Allows for pulling members out of types that where the member is named and typed the same
// In this example SRTP will be used to pull out the 'First: string' and 'Last: string' members
// from different types
// One example of SRTP in the F# Base Class Library is the (+) operator.
// You'll see that it has this type signature:
@andyraddatz
andyraddatz / ASCIIStringExtensions.cs
Last active May 27, 2025 07:35
C# String extension method to fold diacritics to ASCII characters
// IMPORTANT
using System.Text;
// This gist was created thanks to this comment from Alexander on StackOverflow:
// https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net#comment86833005_34272324
// This is a derivative work. The logic of this function comes from a switch statement found inside the
// Lucene.Net library. The documentation of the conversion of characters is quite impressive
// (thank you @NightOwl888 and @synhershko !!!):
// https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/ASCIIFoldingFilter.cs
@mavasani
mavasani / DiagnosticSuppressorDesign.md
Last active November 27, 2024 17:43
DiagnosticSuppressor

Feature Request

dotnet/roslyn#30172: Programmatic suppression of warnings

Provide an ability for platform/library authors to author simple, context-aware compiler extensions to programmatically suppress specific instances of reported analyzer and/or compiler diagnostics, which are always known to be false positives in the context of the platform/library.

Programmatically Suppressible Diagnostic

An analyzer/compiler diagnostic would be considered a candidate for programmatic suppression if all of the following conditions hold:

  1. Not an error by default: Diagnostic's DefaultSeverity is not DiagnosticSeverity.Error.
@mgeeky
mgeeky / xml-attacks.md
Last active May 29, 2025 12:17
XML Vulnerabilities and Attacks cheatsheet

XML Vulnerabilities

XML processing modules may be not secure against maliciously constructed data. An attacker could abuse XML features to carry out denial of service attacks, access logical files, generate network connections to other machines, or circumvent firewalls.

The penetration tester running XML tests against application will have to determine which XML parser is in use, and then to what kinds of below listed attacks that parser will be vulnerable.


@everget
everget / js_bitwise_hacks.md
Last active April 2, 2025 22:43
A comprehensive guide to advanced bitwise manipulation techniques in JavaScript, featuring concise code snippets demonstrating clever bit-level operations for solving various programming challenges.
@bishboria
bishboria / springer-free-maths-books.md
Last active May 10, 2025 04:28
Springer made a bunch of books available for free, these were the direct links
@tel
tel / ProfunctorLens.js
Last active October 23, 2023 20:32
Pure Profunctor Lenses in Javascript (redux)
/* eslint-disable new-cap */
/**
* Lens types.
* ===========
*
* a * b = {fst: a, snd: b}
* a + b = {index: Boolean, value: a | b}
*
* Iso s t a b = forall (~>) . Profunctor (~>) => (a ~> b) -> (s ~> t)
@kristopherjohnson
kristopherjohnson / List.swift
Last active August 29, 2015 14:09
Functional list implementation in Swift
public final class Box<T> {
public let value: T
public init(_ value: T) {
self.value = value
}
}
/// Immutable list of elements of type T
///
@mcfedr
mcfedr / recursion.asm
Last active April 8, 2016 11:24
Example of how V8 compiles recursion
;;; --- Skip lots of stuf ---
;;; <@19,#13> compare-numeric-and-branch
0x49252d6f 47 83f800 cmp eax,0x0
0x49252d72 50 0f843e000000 jz 118 (0x49252db6)
;;; <@20,#17> -------------------- B2 (unreachable/replaced) --------------------
;;; <@24,#24> -------------------- B3 --------------------
;;; <@27,#26> compare-numeric-and-branch
0x49252d78 56 83f802 cmp eax,0x2 ;; debug: position 81
0x49252d7b 59 0f842a000000 jz 107 (0x49252dab)