Skip to content

Instantly share code, notes, and snippets.

@AucT
AucT / textarea_ctr_enter_submit_form.js
Created Apr 25, 2022
Pressing ctr+enter inside textarea will requestSubmitForm.
View textarea_ctr_enter_submit_form.js
document.body.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && e.target.localName === 'textarea' && (e.metaKey || e.ctrlKey) && e.target.form) {
e.target.form.requestSubmit();
}
});
@AucT
AucT / IndexNow.php
Created Nov 14, 2021
indexnow php example bing
View IndexNow.php
<?php
class IndexNow
{
const LOG = true;
public static function submit(array $urls): void
{
$data = [
@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;