Skip to content

Instantly share code, notes, and snippets.

@Eczbek
Eczbek / lambdas.md
Last active April 11, 2025 19:03
article on lambdas

Abstract

A lambda expression is a shorthand notation for creating an unnamed callable object (also called a closure, or an anonymous function). A lambda can "capture" variables from its surrounding scope by value or by reference, allowing the body of the lambda to access or modify those variables without having to pass them as parameters. Unlike regular functions, lambdas are typically written in-line, combining the reusability of functions with direct access to local context. The lambda retains captured variables' state (for captures by value) or dynamically references them (for captures by reference), making lambdas ideal for short, context-dependent operations like custom comparisons, filters, or event handlers.

For example:

// Define a function in namespace scope
bool is_even(int x) {
	return x % 2 == 0;
}
std::string vtable_inator(const auto& any) {
struct h { void** name; };
return std::string(reinterpret_cast<char*>(reinterpret_cast<void**>(reinterpret_cast<const h*>(&any)->name[-1])[1]));
}
struct vtable_inator_able { virtual void nothing() final {}; };
struct Hello_world : vtable_inator_able {};
int main() {
template<typename... Fs>
struct visitor : Fs... {
using Fs::operator()...;
};
template<auto x>
using value = std::integral_constant<decltype(x), x>;
#define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
const a=-3/80,e=1,f=5,g=8/3,h=9/10,i=1,l=11/3,n=3,o=1/3,r=1,s=7/3,t=10/3,u=12/5,v=1,w=9/5,x=18/7,z=0;
z*e*r*o // 0
o*n*e // 1
t*w*o // 2
t*h*r*e*e // 3
f*o*u*r // 4
f*i*v*e // 5
s*i*x // 6
s*e*v*e*n // 7
@Eczbek
Eczbek / recursive_header_combiner_inator.js
Last active February 24, 2025 03:08
recursive-header-combiner-inator
// this code is terrible
// i hacked this together in like 10 minutes
// it doesn't even work well
// i'm not responsible for brain damanged incurred past this line
// ================================================================
import { readFile, writeFile } from 'node:fs/promises';
import { join, resolve, dirname } from 'node:path';
@Eczbek
Eczbek / jsfck.h
Created January 23, 2025 00:25
jsfck using the preprocessor (unoptimizing)
// characters
#define _space ([][_f+_l+_a+_t]+[])[_8]
#define _ecphoneme _Function(_r+_e+_t+_u+_r+_n+_quotation+_backslash+(_4)+(_1)+_quotation)()
#define _quotation _string[_f+_o+_n+_t+_c+_o+_l+_o+_r]()[_1+[_2]]
#define _octothorpe _Function(_r+_e+_t+_u+_r+_n+_quotation+_backslash+(_4)+(_3)+_quotation)()
#define _dollar _Function(_r+_e+_t+_u+_r+_n+_quotation+_backslash+(_4)+(_4)+_quotation)()
#define _percent _Function(_r+_e+_t+_u+_r+_n+_space+_e+_s+_c+_a+_p+_e)()([][_f+_l+_a+_t])[_2+[_1]]
#define _ampersand _Function(_r+_e+_t+_u+_r+_n+_quotation+_backslash+(_4)+(_6)+_quotation)()
#define _apostrophe _Function(_r+_e+_t+_u+_r+_n+_quotation+_backslash+(_4)+(_7)+_quotation)()
#define _parenthesis_open ([][_f+_l+_a+_t]+[])[_1+[_3]]
@Eczbek
Eczbek / operators.cpp
Created October 4, 2024 20:29
more logical and bitwise operators
template<auto f>struct A{template<class T>struct B{T x;
constexpr T operator&&(T y ){return static_cast<T>(f( x,y));}
constexpr T operator||(T y ){return static_cast<T>(f( x,y));}
constexpr T operator& (T y ){return static_cast<T>(f( x,y));}
constexpr T operator| (T y ){return static_cast<T>(f( x,y));}
constexpr T operator^ (T y ){return static_cast<T>(f( x,y));}
friend constexpr T operator&=(T y,B b){return static_cast<T>(f(b.x,y));}
friend constexpr T operator|=(T y,B b){return static_cast<T>(f(b.x,y));}
friend constexpr T operator^=(T y,B b){return static_cast<T>(f(b.x,y));}};
@Eczbek
Eczbek / resources.md
Last active March 24, 2025 12:34
C++ resources and a rearrangement of `learncpp.com`
@Eczbek
Eczbek / var_names.txt
Created September 7, 2024 22:42
variable names
flombigate
grongle
purghle
zimziquat
@Eczbek
Eczbek / nowindows.h
Last active September 15, 2024 15:27
Macros to disable generally unwanted stuff from <windows.h> (from Veeloxfire)
#define NOATOM
#define NOCLIPBOARD
#define NOCOLOR
#define NOCOMM
#define NOCTLMGR
#define NODEFERWINDOWPOS
#define NODRAWTEXT
#define NOGDI
#define NOGDICAPMASKS
#define NOICONS