Skip to content

Instantly share code, notes, and snippets.

View lemire's full-sized avatar
🚀
working hard and fast

Daniel Lemire lemire

🚀
working hard and fast
View GitHub Profile
#include <immintrin.h>
int main() {
__m512i x = _mm512_set1_epi16(4);
__m512i m = _mm512_set1_epi32(~0u); // all-ones via *epi32* broadcast
// two word subtract-by-1; expected every lane == 2
__m512i y = _mm512_add_epi16(m, _mm512_add_epi16(m, x));
return _mm_extract_epi16(_mm512_castsi512_si128(y), 1) != 2;
}

Mission: Build a Master of Orion (1993) Clone in Modern C++

Project Name: Orion Reborn

Goal

Create a faithful yet modernized spiritual successor / clone of the original Master of Orion (the 1993 classic that coined the 4X genre) using C++23, raylib for rendering/input/audio, and Dear ImGui (via rlImGui) for the user interface.

The game should capture the elegant, addictive gameplay loop of the original while leveraging modern language features, clean architecture, and cross-platform ease.

Core Philosophy

@lemire
lemire / IpCountryLookup.java
Created March 30, 2026 22:12
IpCountryLookup - Reads a file of IP addresses and resolves each to a country using the free ip-api.com JSON API (no key required)
import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.stream.*;
import java.util.regex.*;
/**
const { Validator } = require('ata-validator');
// Define a JSON schema for a user object
const userSchema = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1 },
email: { type: 'string', format: 'email' },
age: { type: 'integer', minimum: 0 },
role: { type: 'string', default: 'user' }
import requests
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime, timedelta
username = "lemire" # use your GH username
GITHUB_TOKEN = '' # put your GH token
HEADERS = {
@lemire
lemire / compile-time-gperf-cpp.md
Created March 3, 2026 20:57
compile-time-gperf-cpp

Problem

Often, when parsing, you encounter a point where you want to check if a string is one out of a set, as quickly as possible. E.g., if you are parsing URLs, the string must start with a protocol, and there is a finite list of protocols. There are many such problems. Think about YAML files where a parameter must take one out of 3 or 5 values.

How do solve this classically?

If you have 5 strings (say http:, https:, file:, sftp:, ftp:), you may do 5 comparisons. This is obviously wasteful.

@lemire
lemire / simdjson_example.cpp
Created February 24, 2026 00:11
simdjson example
/*
This program serves as a comprehensive test suite for the consume_array and
consume_object functions, which are designed to parse specific JSON structures
using the simdjson library. The primary goal is to validate the parsing of
arrays and objects that contain a string, a double, and an optional integer
value. The test generates a large JSON array consisting of 200 elements: the
first 100 are sub-arrays, and the next 100 are objects. This allows for thorough
testing of both parsing paths under various conditions.
The consume_array function takes a simdjson ondemand::array and extracts three
@lemire
lemire / two_sum.py
Created February 10, 2026 18:00
Find two elements that sum to a given target in python
import numpy as np
np.seterr(over='ignore')
def set_two_sum(nums, target):
"""
Fast O(n) approach using a set to store seen numbers.
"""
seen = set()
for num in nums:
@lemire
lemire / onlinepython.html
Created February 9, 2026 18:25
online python
<div style="max-width: 1000px; margin: 0 auto; background-color: #ffffff; padding: 24px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);">
<h1 style="font-size: 24px; font-weight: bold; margin-bottom: 16px; color: #1f2937;">Laboratoire Python en ligne </h1>
<p style="margin-bottom: 16px; color: #4b5563;">
Modifiez ou utilisez le code Python ci-dessous, puis cliquez sur "Exécuter" pour afficher les résultats. Exemple :
</p>
<script src="https://cdn.jsdelivr.net/pyodide/v0.27.6/full/pyodide.js"></script>
<div style="margin-bottom: 24px;">
<h2 style="font-size: 18px; font-weight: bold; color: #374151; margin-bottom: 8px;">Exemple Python :</h2>
<pre style="background-color: #e6f4ea; padding: 12px; border: 1px solid #15803d; border-radius: 4px; font-family: monospace; font-size: 14px; color: #374151;">etudiants = [
@lemire
lemire / github.py
Created December 31, 2025 22:45
Get your GitHub activity for 2025
#!/usr/bin/env python3
# uv run lemire.py --token <your_github_token> --user <github_username>
#
# To generate a GitHub Personal Access Token:
# 1. Go to https://github.com/settings/tokens
# 2. Click "Generate new token (classic)"
# 3. Give it a name, e.g., "GitHub Search Script"
# 4. Select scopes: For public repositories, select "public_repo". For private, select "repo".
# 5. Click "Generate token"
# 6. Copy the token and use it as --token argument.