Skip to content

Instantly share code, notes, and snippets.

@AucT
AucT / arrayToHtmlTable.php
Created Dec 31, 2020
Get html table from array of assoc arrays (simple result set from mysql tables)
View arrayToHtmlTable.php
<?php
function arrayToTable(array $rows, string $tableAttributes = ''): string
{
if (!$rows) {
return '';
}
$rowsHeaders = array_keys($rows[0]);
$table = "<table {$tableAttributes}><tr>";
foreach ($rowsHeaders as $rowsHeader) {
@AucT
AucT / php_interval_to_minutes_seconds.php
Created Dec 27, 2020
Convert php Interval (ISO8601) to seconds function, Convert php Interval (ISO8601) to minutes function
View php_interval_to_minutes_seconds.php
<?php
function ISO8601ToSeconds($ISO8601){
$interval = new \DateInterval($ISO8601);
return ($interval->d * 24 * 60 * 60) +
($interval->h * 60 * 60) +
($interval->i * 60) +
$interval->s;
}
function ISO8601ToMinutes($ISO8601){
View php-array-to-csv.php
<?php
/**
* Takes in a filename and an array associative data array and outputs a csv file
* @param string $fileName
* @param array $assocDataArray
*/
public function outputCsv($fileName, $assocDataArray)
{
ob_clean();
View Simple API.md

Simple API - a mix of rest and RPC

There are a lot of time when you need a ton of actions but rest API docs with noun doesn't help much, and implementing proper RPC style will need a lot of changes and will not work for simple HTML forms.

Simple API spec

  1. HTTP GET for queries. GET requests are made in REST style.
@AucT
AucT / bootstrap4-social-button-colors.css
Created Jan 13, 2020
css bootstrap 4 social buttons color
View bootstrap4-social-button-colors.css
.btn-google {
color: #fff;
background-color: #dc4639;
border-color: #dc4639;
}
.btn-google:hover {
color: #fff;
background-color: #cb3124;
border-color: #c02f22;
}
@AucT
AucT / decompact.php
Last active Dec 12, 2019
decompact - replace php compact with array
View decompact.php
<?php
function decompact(...$params)
{
$minimumParamsForNewLines = 4;
$newLine = "\n";
if (count($params) < $minimumParamsForNewLines) {
$newLine = '';
}
View pageGenerationTime.php
<?
$time_start = microtime(true);
//Your Content (i use sleep 2 seconds to for demo)
sleep(2);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo 'Page generated in: '.$time.' seconds';
View addYear.php
<?php
//Add 1 year
$future = date('Y-n-j', mktime(0,0,0, date('m'), date('d'), date('Y')+1));
echo $future;
@AucT
AucT / index.html
Created Dec 7, 2016
jquery Ajax example
View index.html
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Simple Ajax Send Form</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
@AucT
AucT / page_generation_time.php
Last active Sep 3, 2016
simple page generation time
View page_generation_time.php
<?php
$time_start = microtime(true);
//Your Content (i use sleep 2 seconds to for demo)
sleep(2);
$time_end = microtime(true);