Skip to content

Instantly share code, notes, and snippets.

View Abacn's full-sized avatar

Yi Hu Abacn

View GitHub Profile
@Abacn
Abacn / NASE.java
Created November 21, 2023 21:21
NegativeArraySizeException when constructing large (>1GB) string in Java9+
package org.example;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
// In Java8: java.lang.OutOfMemoryError: Java heap space
// In Java9+: java.lang.NegativeArraySizeException: -1894967266
public class Main {
static byte[] generateData() {
@Abacn
Abacn / jdbcxlangdate.py
Created September 8, 2023 15:24
Beam Python Jdbc read write Date
# Code snippet for read/write Date logical type that currently unsupported in Beam Python
# without the need of cast, by implements your own LogicalType (DateType)
import datetime
from decimal import Decimal
import logging
import typing
from apache_beam.coders.row_coder import LogicalType
from apache_beam.typehints.schemas import MillisInstant
@Abacn
Abacn / jdbc_test_tool.py
Last active June 7, 2023 21:34
Utility for managing database tables
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@Abacn
Abacn / jdbcxlang.py
Last active June 7, 2023 22:08
Demo Codes for Apache Beam cross-language JDBCIO
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@Abacn
Abacn / Dnpluspbc.hpp
Last active November 21, 2019 22:59
Periodic boundary condition and minimum image in E8 lattice (8-dimensional dense packing)
/* Periodic boundary condition and minimum image in Dn lattice (n-dimensional dense packing, n>=4)
* Created by Yi Hu on 6/13/19.
* Refer to: J. Convay and N. Sloane, IEEE Trans Inform Theory 28, 227 (1982).
*/
#include <cstdint>
#include <cmath>
// Dimensionality DIM >= 4
#define DIM 8
@Abacn
Abacn / Dnpbc.hpp
Last active November 21, 2019 22:30
Periodic boundary condition and minimum image in D4 lattice (4-dimensional dense packing)
/* Periodic boundary condition and minimum image in Dn lattice (n-dimensional dense packing, n>=4)
* Created by Yi Hu on 6/13/19.
* Refer to: J. Convay and N. Sloane, IEEE Trans Inform Theory 28, 227 (1982).
*/
#include <cstdint>
#include <cmath>
// Dimensionality DIM >= 4
#define DIM 4
@Abacn
Abacn / qhulltest.cpp
Last active October 15, 2024 20:15
Calling qhull library in C++
/* Compiling command:
g++ -o Qhullex Qhullex.cpp -lqhullstatic_r -lqhullcpp
Note:
(1) this is the minimum example (user_eg3) in qhull package, also mentioned in http://www.qhull.org/html/qh-code.htm#cpp .
However, the version on the website (Dated 03/19/2019) is inconsistent with the source code and it does not pass the compiler
(2) libqhullstatic_r is the correct library to use.
* Linking to libqhull results in runtime error
"QH6248 qh_lib_check: Incorrect qhull library called. Caller uses reentrant Qhull while library is non-reentrant";
* Linking to libqhull_r results in runtime error
@Abacn
Abacn / qhulltest.cpp
Created March 19, 2019 18:58
Calling qhull library in C++
#include <iostream>
#include <libqhullcpp/Qhull.h>
#include <libqhullcpp/QhullFacetList.h>
#include <libqhullcpp/RboxPoints.h>
using namespace std;
using namespace orgQhull;
int main(void) {
RboxPoints rbox("100");
@Abacn
Abacn / poisson.cpp
Created November 21, 2018 03:22
Test C++11 Poisson distribution generator
// Test Poisson distribution generator
#include <stdio.h>
#include <time.h>
#include <random>
int main()
{
int ntest = 10;
double Nmin = 100000.;
@Abacn
Abacn / ellipse.cpp
Last active June 13, 2019 21:51
Minimum Distance of a point to the boundary of an ellipse
//
// ellipse.cpp
// EllipticalCylinder
//
// Created by Yi Hu on 4/6/18.
//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <nlopt.h>