Skip to content

Instantly share code, notes, and snippets.

@squell
squell / fil_fail.c
Created April 10, 2026 12:46
Garbage in, garbage out.
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
/*
1. Compile this program with Fil-C to ./a.out
2. Execute: echo FILFAIL | ./a.out
@squell
squell / nan.c
Created April 14, 2025 19:12
Try and compile this with gcc and clang and see what assembly they emit
#include <math.h>
volatile _Bool b;
volatile int i;
void foo ()
{
b = NAN;
i = NAN;
}
@squell
squell / TypeCheckMe.hs
Created September 22, 2021 19:34
What could possibly go wrong?
data Combinators a = I a | K a a | S a a a
primes =
K
(S I I (S (K (S (S (K (S I I (S (S (K S)(S (K (S (K S)))(S (K (S (S (K S)(S S (S (S (K S)K))(K K)))))
(S (S (K S)(S (K K)(S (K S)(S (S (K S)(S (K K)(S (K S)(S (S (K S)(S (K K)(S I I)))
(K (S I (K K)))))))(K (S (K (S (S (K S)(S (K (S I))(S (K K)(S (K (S (S (K S)K)(S (S (K S)K)I)
(S (S I I)I (S (S (K S)K)I)(S (S (K S)K)))))(S I (K (K I)))))))))(S (K K)K)))))))(K (S (K K)
(S (S I (K (S (S (S (S (S S K (S I (K (K I))))(K (S (S (K S)K)I (S (S (K S)K)(S (S (K S)K)I))
(S (K (S (S I (K (K I)))))K)(K K))))(K K))(S (S (K S)(S (K (S I))(S (K K)(S (K (S (S (K S)K)))
bool validateChecksum()
{
std::filebuf buf;
buf.open(_path, std::ios::in | std::ios::binary);
uint32_t checksum = -1;
uint32_t actualChecksum = 0;
for(int c; ((c=buf.sbumpc()) != EOF); )
{
@squell
squell / not_so_private.cpp
Created December 13, 2015 17:34
Simpler access to private members.
// inspired by: http://bloglitb.blogspot.nl/2010/07/access-to-private-members-thats-easy.html
// but removed unnecessary machinery to make the trick work
#include <iostream>
using namespace std;
template<typename Ptr, Ptr value, Ptr& obj>
class rob {
static struct filler {
@squell
squell / auto_cast.cpp
Last active November 30, 2015 15:58
A better name might be "fuckit_cast" or "unholy_cast".
// explicit type conversion made easy!
template<class T>
struct auto_deref_t {
auto_deref_t(T t) : _obj(t) { }
template<class U>
operator U() const { return *(U*)_obj; }
auto_deref_t<auto_deref_t> operator*() const
{ return *this; }
const T _obj;
@squell
squell / tinysort.cpp
Last active October 29, 2015 23:13
Just another sorting algorithm.
void sort(int a[], size_t N)
{
if(N>1) do {
swap(&a[0], &a[1]);
sort(a+1, N-1);
} while(a[0]>a[1]);
}
@squell
squell / primes.sh
Last active August 29, 2015 14:15
Fork bomb of Eratosthenes
sieve() {
if read p; then
echo $p
while read n; do
if [ `expr $n % $p` != 0 ]; then
echo $n
fi
done | sieve
fi
}
@squell
squell / error.cpp
Last active August 29, 2015 14:14
clang++ -std=c++11 rejects this, g++ does not
#include <string>
struct foo {
operator const std::string()
{ return "hatsjekiedee"; }
};
int main()
{
std::string s;
@squell
squell / gist:63c83cdc87ffbae31b30
Created January 13, 2015 19:36
Rejected by Microsoft C++ (2)
template <class T> struct cont;
template<class T> struct proxy {
cont<T> data;
};
extern struct cont<char> foo; // gcc,clang,msvc fine with this
extern struct proxy<char> bar; // msvc not ok with this