Skip to content

Instantly share code, notes, and snippets.

@CoHyper
CoHyper / index.php
Last active February 20, 2025 17:51
PHP Charts.php
<?php
/**
* This file is part of
* pragmaMx - Web Content Management System.
* Copyright by pragmaMx Developer Team - http://www.pragmamx.org
*
* pragmaMx is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@CoHyper
CoHyper / index.php
Last active January 12, 2025 21:46
PHP stringKuerzenMitSuffix
<?php
function stringKuerzenMitSuffix(string $stringToCut, int $maxLength, string $suffix = '...'): string
{
$prefixLength = max(0, $maxLength - strlen($suffix));
$cutString = substr($stringToCut, 0, $prefixLength);
$cutSuffix = substr($suffix, 0, $maxLength - $prefixLength);
return $cutString . $cutSuffix;
}
@CoHyper
CoHyper / index.html
Last active November 5, 2024 19:16
HTML Accordion
<script>
var content = "<p>Here is first content...!</p>";
var content2 = "<p>Here is second content...!</p>";
var isOpen = content === content2 ? "open" : "";
var html = [
'<details id="msDetails" ',
isOpen,
"><summary>aaSection title</summary>",
content,
"</details>",
@CoHyper
CoHyper / index.js
Last active November 5, 2024 19:07
JS Random Color
/**
* Diese Funktion generiert Farben und prüft dabei die Kontrastanforderungen, was sie für die meisten Anwendungsfälle geeignet macht, in denen eine gute Lesbarkeit gewährleistet werden muss.
*
* @copyright 2019-04 Sven Hedström-Lang <svenhlang@gmail.com>
* @param {string[]} existingColors - Array aus bereits vergebenen Farben
* @param {string} [textColor="#000000"] - Optional, Default: "#000000"
* @returns {string} - Ausgabe eines Hexcolor, das noch nicht existiert
* @example
* const existingColors = ['#fff9ed', '#e7a9c6', '#d9d7ef', '#dcdda4', '#f1b19e'];
* generateContrastingColor(existingColors);
@CoHyper
CoHyper / index.sql
Last active August 5, 2024 19:51
SQL multi table without join
## Wichtig, das die beiden Tabellen, in der gleichen Reihenfolge haben
### Jetzt werden Beide Tabellen angezeigt ohne eine JOIN-Verknüpfung
SELECT
uname AS anzeige,
email AS wert
FROM users
WHERE email != ''
UNION
SELECT
@CoHyper
CoHyper / index.js
Last active August 5, 2024 19:40
JS get Object keys
var obj = { id: "1", name: "irgendwas", title: "überschrift" };
var tmpObj = {};
// Iteriere durch die Schlüssel des obj
Object.keys(obj).forEach(function (column) {
if (!tmpObj.hasOwnProperty(column)) {
tmpObj[column] = "";
}
});
@CoHyper
CoHyper / index.js
Last active August 6, 2024 23:48
JS Object sort
/**
* Zum Einfügen eines neuen Objekts an einer bestimmten Position
*
* @param {object} obj
* @param {number} position
* @param {object} newEntry
* @returns {object}
*/
function insertObjectAtPosition(obj, position, newEntry) {
var newObj = {};
@CoHyper
CoHyper / index.html
Last active July 31, 2024 17:25
HTML CSS Unicode Ascii-Zeichen
<!DOCTYPE html>
<html lang="en">
<head>
<!-- https://www.compart.com/de/unicode/ -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Buttons</title>
<style>
button {
display: flex;
@CoHyper
CoHyper / index.html
Created July 27, 2024 13:01
JSON to HTML
<!DOCTYPE html>
<html>
<head>
<title>json to html</title>
<script>
var msJsonUtility = {
htmlToJson: function (htmlString) {
const tempDiv = document.createElement("div");
tempDiv.innerHTML = htmlString;
const element = tempDiv.firstChild;
@CoHyper
CoHyper / index.sql
Last active July 25, 2024 21:22
SQL JOIN
SELECT
departments
FROM
users
WHERE
departments != ''
AND departments IN (
SELECT
BN_BEREICH
FROM