Skip to content

Instantly share code, notes, and snippets.

View abelcallejo's full-sized avatar

Abel Callejo abelcallejo

View GitHub Profile
@abelcallejo
abelcallejo / README.md
Last active July 27, 2020 20:47
15-minute interval aggregation

15-minute interval aggregation

PHP

$midpoint = floor(($minutes+7)/15)*15;

JavaScript

midpoint = Math.floor((minutes+7)/15)*15;
@abelcallejo
abelcallejo / README.md
Last active June 11, 2021 02:37
Screen cheatsheet

Screen cheatsheet

Detaching

control + A and then immediately followed by D

Resuming a screen

screen -r
@abelcallejo
abelcallejo / README.md
Last active May 16, 2020 11:41
Default WordPress .htaccess

Default WordPress .htaccess

Hostname installation

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@abelcallejo
abelcallejo / README.md
Created May 9, 2020 12:09
Regex validation with PHP

Regex validation with PHP

ISO Date

<?php
preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", "1970-01-01");
?>
@abelcallejo
abelcallejo / README.md
Last active May 8, 2020 01:55
Getting the timezone offsets

Getting the timezone offsets

The difference between the generated time using:

  1. the Default timezone setting; versus
  2. the UTC timezone

JavaScript

new Date().getTimezoneOffset();

WordPress

@abelcallejo
abelcallejo / README.md
Last active October 20, 2023 21:29
Creating and managing nonce on Wordpress

Creating and managing nonce on Wordpress

Creating a raw nonce value

Action-based

$nonce = wp_create_nonce( 'my-action_'.$post->ID ); // 295a686963

HTML sample

@abelcallejo
abelcallejo / README.md
Last active April 18, 2020 08:52
Adding screen options on Wordpress

Adding screen options on Wordpress

functions.php

function register_submenu_screen() {
    global $pagenow;

    if( $pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page']=='integrations' ) {
        $screen = get_current_screen();
        add_filter( 'screen_layout_columns', 'embed_submenu_screen' );
@abelcallejo
abelcallejo / README.md
Last active April 12, 2020 06:41
Calculating the Easter date with PHP

Calculating the Easter date with PHP

get_easter_datetime()

function get_easter_datetime($year) {
    $base = new DateTime("$year-03-21");
    $days = easter_days($year);

    return $base->add(new DateInterval("P{$days}D"));
}
@abelcallejo
abelcallejo / README.md
Created March 22, 2020 04:07
Wordpress cheatsheet

Wordpress cheatsheet

User management

Getting the current user

echo get_current_user_id(); //1

Getting the data of a user