Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
@alpenzoo
alpenzoo / js_debug_options.js
Created October 3, 2024 20:21
JS debugging options: 1. naming your script; 2. Chrome to open your script in the debugger by adding debugger; statement in your script and reloading the page with Dev Tools open. Once this line is hit your code will be opened in the debugger.
<script>
...
debugger;
...
//# sourceURL=name_this_script.js
</script>
@alpenzoo
alpenzoo / test.php
Created July 5, 2024 14:54
ANSI sanitizing user input by removing unsupported Unicode characters for a Latin1 encoded PostgreSQL database.
<?php
function sanitizeLatin1($input) {
$output = '';
$unsupportedChars = [];
// Loop through each character in the input string
for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
$char = mb_substr($input, $i, 1, 'UTF-8');
// Convert the character to Latin1 encoding
@alpenzoo
alpenzoo / gist:b5fb71ea5357c8aef650740cedc088ce
Created June 25, 2024 09:56
PHP merge array variations
<?php
// Existing array
$arr = array(1, 2, 3);
// New element to be added at 'zero' => 0
// Create an array using the new element
$temp = array('one');
$temp2 = array("hhhhhh");
@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 = '';
@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 / 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 / cookie-manager.js
Last active June 14, 2023 13:09
Cookie manager script for a list of values.
<?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 / 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