Skip to content

Instantly share code, notes, and snippets.

function calculate_median($arr) {
$count = count($arr); //total numbers in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
if($count % 2) { // odd number, middle is the median
$median = $arr[$middleval];
} else { // even number, calculate avg of 2 medians
$low = $arr[$middleval];
$high = $arr[$middleval+1];
$median = (($low+$high)/2);
}
@imneme
imneme / randutils.hpp
Last active March 28, 2024 20:43
Addresses common issues with C++11 random number generation; makes good seeding easier, and makes using RNGs easy while retaining all the power.
/*
* Random-Number Utilities (randutil)
* Addresses common issues with C++11 random number generation.
* Makes good seeding easier, and makes using RNGs easy while retaining
* all the power.
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Melissa E. O'Neill
*
@Antnee
Antnee / php7_structs.php
Last active September 30, 2017 01:22
PHP7 Structs
<?php
/**
* Ideas for how I'd like to see structs implemented in PHP7
*
* In this example, structs are more like lightweight objects that have no
* methods, just properties. They can be "instantiated" and all properties will be
* null until defined later, as per classes. It is however not possible to set a
* value to a property that was not defined in the struct originally.
*
* Structs can extend other structs, much like classes can. Properties can also
<?php
/**
* Given a URL, normalize that URL.
* @param String URL
* @return String Normalized URL
*/
function normalizeUrl($url)
{
$newUrl = "";
$url = parse_url($url);
@Saissaken
Saissaken / Update git fork with tags.sh
Last active May 21, 2024 19:20
Update git fork with tags
# Repo: someuser/myframework
# Fork: superteam/myframework
# Track:
git clone https://github.com/superteam/myframework.git
cd myframework
git remote add upstream https://github.com/someuser/myframework.git
# Update:
git fetch upstream
@rofirrim
rofirrim / minipool.hpp
Last active March 7, 2022 10:14
Very simple memory pool
#ifndef MINIPOOL_H
#define MINIPOOL_H
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
/*
@loretoparisi
loretoparisi / english_contractions_dataset.json
Last active June 17, 2023 01:49
List of English contractions from Wikipedia
{
"ain't": "am not / is not / are not / has not / have not / did not",
"amn't": "am not",
"aren't": "are not",
"can't": "cannot",
"'cause": "because",
"could've": "could have",
"couldn't": "could not",
"couldn't've": "could not have",
"daren't": "dare not / dared not",
@hnakamur
hnakamur / apt-key-add
Created May 12, 2021 04:59
Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#!/bin/bash
# apt-key-add - Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#
# example:
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key-add - nodesource
# instead of
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
#
set -e
if [ $# -ne 2 -o $UID -ne 0 ]; then