Skip to content

Instantly share code, notes, and snippets.

@divinity76
divinity76 / autoindex.php
Last active April 9, 2024 12:16
autoindex php
<?php
declare(strict_types=1);
/**
* returns a plain string array of path to all files in a directory, and subdirectories,
* but does not return directories themselves. (meaning if a directory is empty, it will not be included at all)
*
* @param string $dir
* @param bool $realpath
@divinity76
divinity76 / rector.php
Created March 4, 2024 15:09
rector.php example
<?php
declare(strict_types=1);
return (static function (\Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig->paths([
'/home/hans/projects/php-ml/',
]);
$rectorConfig->sets([
\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82,
@divinity76
divinity76 / merge_csv.php
Created March 2, 2024 08:08
csv merger script
<?php
declare(strict_types=1);
function fix_encoding(string $str): string
{
//return $str;
return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
}
@divinity76
divinity76 / bogostress.cpp
Created February 29, 2024 08:06
bogostress.cpp
#define _GNU_SOURCE
#include <iostream>
#include <pthread.h>
#include <chrono>
#include <vector>
#include <unistd.h>
#include <sched.h>
#include <stdexcept>
#include <climits>
#!/usr/bin/php
<?php
declare(strict_types = 1);
// require_once ('hhb_.inc.php');
hhb_init ();
if ($argc !== 3) {
fprintf ( STDERR, "usage: %s timestamp url\n", $argv [0] );
fprintf ( STDERR, "example: %s 20091012061648 http://www.p4w.se\n", $argv [0] );
die ( 1 );
}
@divinity76
divinity76 / ubu_1804_amdgpu_compute_mode_linux.php
Last active February 8, 2024 19:07
sets "compute mode" on AMD GPU's in linux
#!/usr/bin/env php
<?php
declare(strict_types = 1);
// this does NOT work on my ubuntu 20.04, look at the other files for a 20.04 version
if (posix_geteuid () !== 0) {
die ( "error: this script requires root privileges, re-run it as root." );
}
$amdgpu_dir = '/sys/bus/pci/drivers/amdgpu';
$dirs = array_filter ( array_map ( 'trim', glob ( $amdgpu_dir.DIRECTORY_SEPARATOR.'*', GLOB_NOSORT | GLOB_ONLYDIR | GLOB_MARK ) ), function (string $str) {
return (is_writable ( $str."power_dpm_force_performance_level" ) && is_writable ( $str.'pp_compute_power_profile' ));
@divinity76
divinity76 / Dockerfile
Created February 8, 2024 14:27
Dockerfile reproduce example
# see https://github.com/php/php-src/issues/12450
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get -y full-upgrade;
RUN apt-get -y install apt-utils
RUN apt-get -y install golang build-essential git autoconf bison re2c make cmake automake libtool libpsl-dev libpsl5
RUN bash -c 'set -e;\
git clone -b curl-8_6_0 --single-branch --depth 1 https://github.com/curl/curl.git; \
cd curl; \
@divinity76
divinity76 / b3instructions.php
Created January 25, 2024 05:20
blake3 portable vs optimized
<?php
declare(strict_types=1);
/**
* better version of shell_exec(),
* supporting both stdin and stdout and stderr and os-level return code
*
* @param string $cmd
* command to execute
@divinity76
divinity76 / resource_limits.cpp
Created January 22, 2024 01:13
test system resource limits (ram allocation, open file handles, concurrent threads)
#include <iostream>
#include <fstream>
#include <thread>
#include <vector>
#include <string>
#include <cstdlib>
char **global_argv;
void testMemory() {
std::cout << "Starting Memory Test" << std::endl;
std::vector<char*> allocations;
@divinity76
divinity76 / file_duplicates.php
Last active January 20, 2024 21:24
file duplicate finder
<?php
declare(strict_types=1);
function clearLine()
{
echo "\033[2K\r";
}
$dirs = array(
"."
);