Skip to content

Instantly share code, notes, and snippets.

@divinity76
divinity76 / file_searcher.php
Created January 18, 2024 08:39
file searcher
<?php
declare(strict_types=1);
$dir = realpath(__DIR__ . '/..');
$files = shell_exec("find " . escapeshellarg($dir) . " -print0");
$files = explode("\x00", rtrim($files, "\x00"));
$files = array_filter($files, function ($filepath) {
if (!preg_match("/page/", $filepath)) {
return false;
@divinity76
divinity76 / php_inserter.php
Created January 18, 2024 08:27
php advanced code inserter
<?php
declare(strict_types=1);
$dir = realpath(__DIR__ . '/..');
$files = shell_exec("find " . escapeshellarg($dir) . " -print0");
$files = explode("\x00", rtrim($files, "\x00"));
$files = array_filter($files, function ($filepath) {
if(!preg_match("/page/", $filepath)) {
return false;
@divinity76
divinity76 / dreamhost.sh
Last active January 6, 2024 11:38
dreamhost account init script..
#fix unicode
[[ -z $(grep LANG ~/.bash_profile) ]] && echo '[[ -z "${LANG}" ]] && export LANG='\''en_US.UTF-8'\''' >> ~/.bash_profile
#make sure .bashrc is loaded on ssh login
[[ -z $(grep bashrc ~/.bash_profile) ]] && echo 'source ~/.bashrc' >> ~/.bash_profile
# create .local/bin
mkdir -p ~/.local/bin;
# install screenie
wget 'https://gist.github.com/divinity76/1a583968c997869b27a5ee2c1ed24259/raw/76453e61a92676386589fbb3f4ef0225ac98fb19/screenie.b64' -O- | base64 -d > ~/.local/bin/screenie ; chmod 0555 ~/.local/bin/screenie;
# install ncdu
wget 'https://github.com/divinity76/static_bin/blob/static_ncdu/ncdu?raw=true' -O ~/.local/bin/ncdu; chmod 0555 ~/.local/bin/ncdu;
@divinity76
divinity76 / 4chan_expand_all.js
Last active December 30, 2023 18:17
4chan expandAll - expand all thumbnailed images
// why max? firefox has issues if you try to click 100+ images at the same time (chrome doesn't, but firefox does, why? idk)
function expandAllImages(max=1){
let all=document.querySelectorAll("div.file:not(.image-expanded) img:not(.autoexpanded)");
max=Math.min(max,all.length);
for(let i=0;i<max;++i){
all[i].className+=" autoexpanded";
//all[i].parentNode.dispatchEvent(new MouseEvent("click", {ctrlKey: true}));
all[i].click();
}
return max;
@divinity76
divinity76 / bruteforce calculations.php
Last active December 26, 2023 11:02
hashes birthday paradox bruteforce
<?php
function same_random_bytes(int $length):string{
static $buf = "";
while(strlen($buf)<$length){
$buf .= chr((strlen($buf)*88)%256);
}
if(strlen($buf) < $length){
$buf.= random_bytes($length-strlen($buf));
}
# This xorg configuration file will start a dummy X11 server.
# move it to /etc/X11/xorg.conf
# don't forget apt install xserver-xorg-video-dummy;
# based on https://xpra.org/Xdummy.html
Section "ServerFlags"
Option "DontVTSwitch" "true"
Option "AllowMouseOpenFail" "true"
Option "PciForceNone" "true"
Option "AutoEnableDevices" "false"
@divinity76
divinity76 / misc PHP.php
Last active December 20, 2023 07:34
misc PHP copypasta
<?php
// find . -iname "*.php" -print0 | xargs -0 --max-args=1 --max-procs=$(nproc) '-I{}' sh -c 'php --syntax-check {} || true' | grep --invert-match "^No syntax errors detected in"
function json_encode_pretty($data, int $extra_flags = 0, int $exclude_flags = 0): string
{
// prettiest flags for: 7.3.9
$flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | (defined("JSON_UNESCAPED_LINE_TERMINATORS") ? JSON_UNESCAPED_LINE_TERMINATORS : 0) | JSON_PRESERVE_ZERO_FRACTION | (defined("JSON_THROW_ON_ERROR") ? JSON_THROW_ON_ERROR : 0);
$flags = ($flags | $extra_flags) & ~ $exclude_flags;
return (json_encode($data, $flags));
}
@divinity76
divinity76 / rsync_forever.php
Last active December 11, 2023 19:40
rsync dir indefinitely whenever it changes.. syncer
#!/usr/bin/env php
<?php
declare (strict_types = 1);
global $argc, $argv;
if ($argc < 3) {
echo ("Usage: {$argv[0]} 'FOLDER' rsync FOLDER foo@bar:server_folder arg1 arg2 arg3 etc\n");
exit(1);
}
/**
@divinity76
divinity76 / collisions.php
Last active December 6, 2023 01:14
hash collisions
<?php
declare(strict_types = 1);
ini_set("memory_limit", "-1");
$algo = "xxh64";
$dictionary = "crackstation.txt";
// MODE_dict_in_ram_hashes_in_ram($algo, $file);
MODE_dict_on_disk_hash_on_sqlite($algo, $dictionary);
@divinity76
divinity76 / php_to_shell.php
Created October 30, 2023 08:14
php script to shell command converter
#!/usr/bin/env php
<?php
declare(strict_types=1);
use function var_dump as d;
function dd(...$args)
{
$trace = debug_backtrace(0, 1)[0]; // odd, i really expected (0, 2)[1] ... but it works
$line = $trace['line'];
$file = $trace['file'];