Skip to content

Instantly share code, notes, and snippets.


Markus Junginger greenrobot

View GitHub Profile
greenrobot / CBoxTest_box_relations.cpp
Created Jan 12, 2022
Example of how to put, query and remove many-to-many database relations using ObjectBox C API
View CBoxTest_box_relations.cpp
TEST_CASE("C-Box-relations", "") {
CTestEnv env;
obx_schema_id test_id = obx_store_entity_id(, "TestEntityCpp");
obx_id ta_id = env.putTestEntity(0, "ta");
obx_id tb_id = env.putTestEntity(0, "tb");
obx_id tc_id = env.putTestEntity(0, "tc");
greenrobot /
Created Jun 18, 2021
NVIDIA driver problems: install/update script expects gcc but system's default is clang
update-alternatives --set cc /usr/bin/gcc
update-alternatives --set c++ /usr/bin/g++
cc --version
c++ --version
apt install nvidia-driver-460
update-alternatives --set cc /usr/bin/clang
update-alternatives --set c++ /usr/bin/clang++
cc --version
greenrobot / IntSortSpeed-64vs32bit.cpp
Created Aug 1, 2020
Sorting 32 bit vs 64 bit integers: mini performance benchmark
View IntSortSpeed-64vs32bit.cpp
TEST_CASE("IntSortSpeed-64vs32bit") {
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_int_distribution<uint32_t> int32Dist;
int count = 100000000;
std::vector<uint32_t> v32;
std::vector<uint64_t> v64;
StopWatch stopWatch;
greenrobot /
Created Aug 28, 2019
ObjectBox example: Cache query and multi-threaded usage of cached query
package io.objectbox.test.stress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import io.objectbox.Box;
import io.objectbox.BoxStore;
import io.objectbox.query.Query;
greenrobot /
Created Mar 26, 2018
A "rescue" version of Box.removeAll() for DBs that reached their size limit.
* A "rescue" version of Box.removeAll() for DBs that reached their size limit.
* Removes data in multiple transactions of increasing size to minimize required additional disk space.
* <p>
* Note that this method is not transactional, so it might fail in between, with any number of objects removed.
* Thus, you should persistently track the state yourself, e.g. by setting a SharedPreferences flag to indicate
* that removal is in progress. If this methods fails, you can check this flag to retry at a later point.
* Only once this method succeeds, this flag should be cleared.
* <p>
* It's recommended to increase the max. DB size to ensure addition capacity is available for this method.
greenrobot /
Created Nov 1, 2017
ObjectBox Android sources
* Copyright 2017 ObjectBox Ltd. All rights reserved.
* Licensed 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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
greenrobot /
Created May 3, 2017
(Almost) Circular class dependencies in Java. What does this print?
package org.greenrobot;
import java.util.concurrent.atomic.AtomicInteger;
public class CircularStaticDependencies {
static AtomicInteger count = new AtomicInteger(1);
static class A {
static String a1 = "a" + count.getAndIncrement();
static String a2 = "a" + count.getAndIncrement() + B.b1;
greenrobot /
Last active Feb 28, 2017
ObjectBox MultithreadedRelationTest
package io.objectbox.relation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
greenrobot / gist:8feae5738d37231988b2
Created Apr 14, 2015
WordPress DB script to update references to uploaded files (pictures)
View gist:8feae5738d37231988b2
SELECT meta_value, SUBSTRING(meta_value FROM 9) meta_value FROM `wp_postmeta` where meta_key = '_wp_attached_file' AND meta_value like '2014/%'
# UPDATE wp_postmeta SET meta_value = SUBSTRING(meta_value FROM 9) where meta_key = '_wp_attached_file' AND meta_value like '2014/%'
greenrobot /
Created Nov 5, 2014
Prepares iOS picture files for Android: images are renamed to conform with Android naming rules, and puts them into the correct drawable folder (-mdpi, -xhdpi, or -xxhdpi)
mkdir drawable-mdpi
mkdir drawable-xhdpi
mkdir drawable-xxhdpi
shopt -s nocaseglob
for iosFile in *.{png,jpeg,gif}; do
if [[ ! -f $iosFile ]]