
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Median and percentile for Active Record, Mongoid, arrays, and hashes
Supports:
:fire: Uses native functions for blazing performance
Add this line to your application’s Gemfile:
gem "active_median"
For MySQL, also follow these instructions.
Median
Item.median(:price)
Percentile
Request.percentile(:response_time, 0.95)
Works with grouping, too
Order.group(:store_id).median(:total)
Median
[1, 2, 3].median
Percentile
[1, 2, 3].percentile(0.95)
You can also pass a block
{a: 1, b: 2, c: 3}.median { |k, v| v }
MySQL requires the PERCENTILE_CONT
function from udf_infusion. To install it, do:
git clone https://github.com/infusion/udf_infusion.git
cd udf_infusion
./configure --enable-functions="percentile_cont"
make
sudo make install
mysql <options> < load.sql
Improve performance with SQLite with an extension. Download percentile.c and follow the instructions for compiling loadable extensions for your platform.
On Linux, use:
gcc -g -fPIC -shared -lsqlite3 percentile.c -o percentile.so
On Mac, use:
gcc -g -fPIC -dynamiclib -L/usr/local/opt/sqlite/lib -lsqlite3 percentile.c -o percentile.dylib
To load it in Rails, create an initializer with:
db = ActiveRecord::Base.connection.raw_connection
db.enable_load_extension(1)
db.load_extension("percentile.so") # or percentile.dylib
db.enable_load_extension(0)
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
To get started with development:
git clone https://github.com/ankane/active_median.git
cd active_median
bundle install
# Postgres
createdb active_median_test
bundle exec rake test
# SQLite
ADAPTER=sqlite3 BUNDLE_GEMFILE=gemfiles/sqlite3.gemfile bundle exec rake test
# MariaDB and MySQL (for MySQL, install the extension first)
mysqladmin create active_median_test
ADAPTER=mysql2 BUNDLE_GEMFILE=gemfiles/mysql2.gemfile bundle exec rake test
# SQL Server
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
docker exec -it <container-id> /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P YourStrong\!Passw0rd -C -Q "CREATE DATABASE active_median_test"
ADAPTER=sqlserver BUNDLE_GEMFILE=gemfiles/sqlserver.gemfile bundle exec rake test
# MongoDB
BUNDLE_GEMFILE=gemfiles/mongoid7.gemfile bundle exec rake test
FAQs
Unknown package
We found that active_median demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.