Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
working hard and fast

Daniel Lemire lemire

🚀
working hard and fast
View GitHub Profile
View writeutf16le.cpp
#include <fstream>
#include <iostream>
int main() {
char16_t output_buffer[] = u"hello world";
size_t len = sizeof(output_buffer) / sizeof(char16_t);
std::ofstream out("output.ut16.txt", std::ios::binary | std::ios::trunc);
out.write(reinterpret_cast<char *>(output_buffer), len * sizeof(char16_t));
std::cout << "wrote " << out.tellp() << " bytes" << std::endl;
out.close();
View rollyawpitch.py
from math import *
def convert_to_degree(x):
return [int(x[0] / (2 * pi) *360),int(x[1] / (2 * pi) *360),int(x[2] / (2 * pi) *360)]
def toangles(q):
sqw = q[3] * q[3]
sqx = q[0] * q[0]
sqy = q[1] * q[1]
sqz = q[2] * q[2]
@lemire
lemire / hacking.md
Last active Sep 7, 2021
hacking rcppsimdjson
View hacking.md

Here is how to test rcppsimdjson.

  • Install docker.
  • Grab rcppsimdjson from GitHub.

Next, you want to create a file called 'Dockerfile'. You may put this file inside the root rcppsimdjson repository.

The file may have the following content: (there are more examples at https://github.com/RcppCore/Rcpp/tree/master/docker/ci-3.4 )

@lemire
lemire / load.c
Created Mar 6, 2021
Simple C program to load a file
View load.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
perror("provide a file argument");
}
FILE *pFile = fopen(argv[1], "rb");
if (pFile == NULL)
perror("Error opening file");
View two_or_three.s
.globl _compute_two ; -- Begin function compute_two
.p2align 2
_compute_two: ; @compute_two
.cfi_startproc
; %bb.0:
Lloh0:
adrp x8, _M@PAGE
Lloh1:
ldr x8, [x8, _M@PAGEOFF]
tst x8, #0x7fffffffffffffff
View minecraft.sh
# Important: change spigot-1.16.1.jar to match the name of your jar file!
if ! screen -list | grep -q "minecraft"; then
cd /home/pi/minecraft
screen -S minecraft -d -m java -jar -Xms512M -Xmx1008M spigot-1.16.1.jar nogui
fi
@lemire
lemire / CMakeLists.txt
Last active Aug 17, 2020
One-cmake simdjson example
View CMakeLists.txt
# Copy this file as CMakeLists.txt in
# some directory. With a recent CMake
# (at least 3.15), in this directory do
#
# cmake -B build .
# cmake --build build
# ./build/repro
#
#
cmake_minimum_required(VERSION 3.15)
@lemire
lemire / fastaltmod.c
Created Jul 12, 2018
fast alternative to the modulo reduction (code sample)
View fastaltmod.c
#include <iostream>
#include <cstdint>
using namespace std;
// we are going to generate random numbers using
// an xorshift generator
static uint32_t xorshift_y;
View createsimd.c
namespace {
/**
* make_uint8x16_t initializes a SIMD register (uint8x16_t).
* This is needed because, incredibly, the syntax uint8x16_t x = {1,2,3...}
* is not recognized under Visual Studio! This is a workaround.
* Using a std::initializer_list<uint8_t> as a parameter resulted in
* inefficient code. With the current approach, if the parameters are
* compile-time constants,
* GNU GCC compiles it to ldr, the same as uint8x16_t x = {1,2,3...}.
@lemire
lemire / perfdocker.bash
Created May 3, 2020
Running perf under docker
View perfdocker.bash
docker run -it --privileged ubuntu bash
apt-get update
apt-get install linux-tools-generic
/usr/lib/linux-tools/5.4.0-28-generic/perf stat ls