Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
@alpenzoo
alpenzoo / sort_array_by_attributes.php
Created December 12, 2022 11:18
sorts a multidimensional array by two or more attributes
function sort_array_by_attributes($array, ...$attributes)
{
// Create arrays of values to sort by
$sort_keys = [];
foreach ($attributes as $attribute) {
$sort_keys[] = array_column($array, $attribute);
}
// Add the array to be sorted as the last argument
$sort_keys[] = &$array;
@alpenzoo
alpenzoo / create_zip_stream.php
Created December 12, 2022 11:24
creates a ZIP file and return it as a stream:
function create_zip_stream($file_paths)
{
// Create a new ZipArchive object
$zip = new ZipArchive();
// Open a memory stream for the zip file
$zip_stream = fopen('php://memory', 'w+');
$zip->open($zip_stream, ZipArchive::CREATE);
// Add the files to the zip
@alpenzoo
alpenzoo / curl-smtp.php
Created January 11, 2023 16:45 — forked from hdogan/curl-smtp.php
Sending SMTP e-mail with curl/php
<?php
function read_cb($ch, $fp, $length) {
return fread($fp, $length);
}
$fp = fopen('php://memory', 'r+');
$string = "From: <[email protected]>\r\n";
$string .= "To: <[email protected]>\r\n";
$string .= "Date: " . date('r') . "\r\n";
$string .= "Subject: Test\r\n";
@alpenzoo
alpenzoo / letsencrypt-certbot.txt
Created April 20, 2023 05:12
Letsencrypt usage
#add another domain
certbot --expand -d subdomain.domain.com
#add another domain with SSL and 307 redirect
certbot --webroot -w /var/www/html certonly -d subdomain.domain.com 307 -d subdomain.NEWdomain.com
<?php
//php streaming proxy
header('Access-Control: allow <*>'); //xdomain ajax ftw
set_time_limit(24*3600);
$fp = fsockopen("192.168.1.149", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
@alpenzoo
alpenzoo / cookie-manager.js
Last active June 14, 2023 13:09
Cookie manager script for a list of values.
@alpenzoo
alpenzoo / boot.js
Created November 26, 2023 17:00 — forked from zeero/boot.js
/*\
title: $:/boot/boot.js
type: application/javascript
The main boot kernel for TiddlyWiki. This single file creates a barebones TW environment that is just sufficient to bootstrap the modules containing the main logic of the application.
On the server this file is executed directly to boot TiddlyWiki. In the browser, this file is packed into a single HTML file along with other elements:
# bootprefix.js
# <module definitions>
@alpenzoo
alpenzoo / my-collate-sort.php
Created January 20, 2024 13:22
custom collate like sort function PHP
function compare_by_alphabet($str1, $str2) {
$alphabet = "AaÀàÁáÂâÅåÃãÄ䯿BbCcÇçDdÐðEeÈèÉéÊêËëFfGgHhIiÌìÍíÎîÏïJjKkLlMmNnÑñOoÒòÓóÔôÕõÖöØøPpQqRrSsߊšTtUuÙùÚúÛûÜüVvWwXxYyŸÿÝýZzŽžÞþ0123456789";
$l1 = mb_strlen($str1);
$l2 = mb_strlen($str2);
$c = min($l1, $l2);
for ($i = 0; $i < $c; $i++)
{
$s1 = mb_substr($str1, $i, 1);
@alpenzoo
alpenzoo / grab_emails.pl
Created January 30, 2024 12:23 — forked from DamianZaremba/grab_emails.pl
Perl script for grabbing emails from an IMAP folder
#!/usr/bin/perl
use strict;
use Mail::IMAPClient;
use IO::Socket;
use IO::Socket::SSL;
use Time::ParseDate;
use Data::Dumper;
# Config stuff
my $mail_hostname = '';