Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
@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 / 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 / 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 / webworldwind-example.html
Created November 1, 2022 22:40 — forked from emxsys/webworldwind-example.html
A complete 3D virtual globe example - HTML, JavaScript and CSS - using ESA-NASA Web WorldWind, Bootstrap and KnockoutJS featuring a 3D globe view, 2D map projections, markers and place name finder. Simply download and open this HTML file in your browser to run the app, or see http://worldwind.earth/sample-app.html for a preview and write-up.
<!DOCTYPE html>
<html lang="en">
<!--
A sample framework for the ESA-NASA WebWorldWind web applications.
Author: Bruce Schubert
License: MIT
See: https://worldwind.arc.nasa.gov/web/
-->
<head>
<meta charset="utf-8">
"/*@ sourceMappingURL=" source mapping URL declaration is deprecated, "/*# sourceMappingURL=" declaration should be used instead.
//@ sourceMappingURL=jquery.min.map
to
//# sourceMappingURL=jquery.min.map
//@ sourceURL=<url>
to
//# sourceURL=<url>
@alpenzoo
alpenzoo / LICENSE.txt
Created September 30, 2022 09:31 — forked from hillerstorm/LICENSE.txt
Swedish social security number validator
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 Johan Hillerström <https://github.com/hillerstorm>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@alpenzoo
alpenzoo / slugify.sql
Created February 3, 2022 20:30 — forked from ianks/slugify.sql
Generating Slugs in Postgres
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
@alpenzoo
alpenzoo / detect_interval_overlaps.sql
Last active November 24, 2020 14:54
Detect overlapping intervals generating ranges and usage rating. Contains a bunch of various code found online. Thank you.
WITH
activities AS (
SELECT * FROM (
VALUES
('D', '2018-01-09 11:00:00'::timestamp, '2018-01-09 11:10:00'::timestamp, 1),
('A', '2018-01-09 10:00:00'::timestamp, '2018-01-09 12:00:00'::timestamp, 1),
('X', '2018-01-09 10:05:00'::timestamp, '2018-01-09 10:11:00'::timestamp, 1),
('B', '2018-01-09 14:00:00'::timestamp, '2018-01-09 16:00:00'::timestamp, 1),
('C', '2018-01-09 10:10:00'::timestamp, '2018-01-09 10:30:00'::timestamp, 1)
) AS act ("name", "start", "end", "count")
@alpenzoo
alpenzoo / sortMultidimensionalArray.php
Created November 12, 2020 23:23
Sort multidimensional array in PHP.
<?php
function sortMultidimensionalArray($arr, $attr){
// Comparison function
$compareTIME = function ($el1, $el2) use ($attr){
$datetime1 = strtotime($el1[$attr]);
$datetime2 = strtotime($el2[$attr]);
return $datetime1 - $datetime2;
};
@alpenzoo
alpenzoo / array_find.php
Created November 9, 2020 11:20
php function returns array filtered on multiple attributes values.
<?php
$arr= array(
array("an"=>2, 'fac'=>5000, 'sr'=>45),
array("an"=>4, 'fac'=>5001, 'sr'=>40),
array("an"=>2, 'fac'=>5000, 'sr'=>40),
array("an"=>2, 'fac'=>5001, 'sr'=>45)
);
$cond=array("an"=>2, 'fac'=>5001);