Skip to content

Instantly share code, notes, and snippets.

View UplinkCoder's full-sized avatar

Stefan Koch UplinkCoder

View GitHub Profile
@UplinkCoder
UplinkCoder / endian.h
Last active January 24, 2022 11:55
header-only endian conversion macros
#ifndef __ENDIAN_H_
#define __ENDIAN_H_
#include <stdint.h>
#define NTOHL HTONL
#define NTOHS HTONS
#if !defined(ENDIAN_IS_LITTLE) && !defined(ENDIAN_IS_BIG)
# if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
#include <stdio.h> // for fopen, fread, fwrite and fclose
#include <string.h> // for memset and strcmp
int main(int argc, char* argv[])
{
if (argc != 3)
{
fprintf(stderr, "Usage: %s <src_file> <dest_file>\n", argv[0]);
return 1;
}
/*
Copyright (c) 2012, Canal TP
This is an example file, do whatever you want with it! (for example if you are in Paris, invite us for a beer)
A slightly more advanced example : we want to use OSM data to extract a graph that represents the road network
Build the example with (we're to lazy to make it compatible with older standards):
g++ example_routing.cc -O2 -losmpbf -lprotobuf -std=c++0x -o routing
To run it:
./routing path_to_your_data.osm.pbf
*/
GNU nano 5.8 t.c
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <arm_acle.h>
static const uint32_t crc32Table[256] = {
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL,
0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
static assert(Foo.tupleof.length == 1);
struct Foo {
int a;
static if(Foo.tupleof.length == 1) {
int b;
static assert(Foo.tupleof.length == 3); // ok
}
static if(Foo.tupleof.length == 1) {
import core.reflect.reflect;
import core.reflect.transitiveVisitor;
/+
pragma(msg, () {
string [immutable(ulong)] cmap;
return nodeToString(nodeFromName("func", ReflectFlags.Functionbody), &cmap);
} ());
+/
VariableDeclaration getVd(const Node node)
{
@UplinkCoder
UplinkCoder / hasStringUda.d
Created October 20, 2021 13:11
Simple implementation of metaprogramming tool
bool hasStringUDA(const Declaration d, string s)
{
foreach(attr;d.attributes)
{
if (auto string_literal = cast(StringLiteral) attr)
{
if (string_literal.string_ == s)
return true;
}
else if (auto te = cast(TupleExpression) attr)