Skip to content

Instantly share code, notes, and snippets.

http://stackoverflow.com/a/35199727

A second method I have found which greatly reduces the size of compressed gzipped data is to first convert the data to the float16 (half-precision) format and back again to float32. This produces a lot of zeros in the output stream which can shrink file sizes by around 40-60 per cent after compression. One subtlety is that the maximum float16 value is rather low, so you may want to scale your data first, e.g. in python

import numpy as np
import math
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#define streq(a, b) (!strcmp((a), (b)))
#ifndef __USE_GNU
#define __USE_GNU
#ifndef __STDINT_H_INCLUDED
#define __STDINT_H_INCLUDED
#include <limits.h>
#if !defined(UINT8_MAX) && defined(UCHAR_MAX) && (UCHAR_MAX) == 0xffU
typedef unsigned char uint8_t;
typedef signed char int8_t;
# define UINT8_MAX UCHAR_MAX
# define INT8_MAX CHAR_MAX
@andersonsp
andersonsp / quickcg.cpp
Last active December 31, 2018 15:03
Lode's Computer Graphics Tutorial - Raycasting
/*
QuickCG 20071121
Copyright (c) 2004-2007, Lode Vandevenne
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
@andersonsp
andersonsp / pascals.pas
Last active July 15, 2019 16:47
pascal-s pretify project
{******************************************************************************
* *
* Pascal-s entered from wirth's Pascal-s document and converted for *
* ISO 7185 use. *
* *
* The original environment of pascal (CDC computer) used a special access *
* method where the input file was split into "segments" and special methods *
* were used to access these segments. I have changed things to open the file *
* "input.pas", and compile the program from there. Input and output then *
* occur from the simulated program normally. Very few changes were made to *
int parse_expression(State *st, Lexer *lx, Scope *sc, Tree *ast, int lv) {
int root = ast_parse(st, lx, ast, 0, 1);
// int ty = ast_node_type(st, ast, sc, root);
Node *node = &ast->node[root];
if(node->tag == S_PRIM && node->val == S_EQUAL) { // assignment
node = &ast->node[node->child]; // left hand side
if(node->tag != S_ID) rg_error0(node->pos, "expected identifier"); // should evaluate to a var or selector
Object *obj = rg_sym_get(st, rg_sym_find(st, node->val, sc->tx));
if (!obj) rg_error(node->pos, "undefined symbol '%s'", spool_str(st, node->val));
@andersonsp
andersonsp / zepl.c
Last active September 5, 2019 16:48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
enum {
CW_LIT, CW_COMPILE, CW_CALL, CW_JMP,
CW_DEF, CW_IMM, CW__TOK, CW__EXEC, CW_EXIT, CW_ECHO,
CW_LAST
};
@andersonsp
andersonsp / mesh_c_io_export.py
Created October 21, 2019 13:13
Blender 2.8 OpenGL Buffer Exporter
# roxlu - 2019-08-04 - Blender 2.8
# ------------------------------------------------
# Very basic script that exports the vertices of the selected object
# to a .h and .cpp that you can use into your graphics app directly.
# Vertices are rotated to Y-up, -Z forward, following common OpenGL.
#
#
# Version:
# ------------------------------------------------
# v0.0.0 - 2019-08-04: First release
// Uncompressed version of
// https://gist.github.com/munificent/b1bcd969063da3e6c298be070a22b604
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#include <stdbool.h> // 2008-2019
const int HEIGHT = 40;
const int WIDTH = 80;
@andersonsp
andersonsp / ULID.scala
Created August 5, 2020 18:46
Simple Binary ULID implementation in Scala
package io.andersonsp.ulid
import scala.util.{Failure, Success, Try}
import java.security.SecureRandom
// The components are encoded as 16 octets. Each component is encoded with the Most Significant Byte first (network byte order).
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | 32_bit_uint_time_high |