Skip to content

Instantly share code, notes, and snippets.

@enlacee
enlacee / geyt-number-weeeks-with-js.js
Created October 30, 2021 03:33
GET NUMBER WEEKS WITH JS
function parseDate(str) {
var mdy = str.split('-');
return new Date(mdy[0], mdy[1]-1, mdy[2]);
}
function datediff(first, second) {
// Take the difference between the dates and divide by milliseconds per day.
// Round to nearest whole number to deal with DST.
return Math.round((second-first)/(1000*60*60*24));
}
@enlacee
enlacee / wordpress-log-in-hook.php
Last active October 22, 2021 02:27
Save login of all users in WP (you must be create a table named wp_metrix)
<?php
/*
* track logIn (save data in table metric)
*/
add_action( 'wp_login', function($login, $user) {
if ( class_exists('\MinderOptions\Core\Chatbot') == true ) {
$keycode = 'sign_in';
$stringValue = time(); // save time in UNIX format
$userId = $user->ID;
$rs = \MinderOptions\Core\Chatbot::saveCodeMetricByREST($keycode, $stringValue, $userId);
@enlacee
enlacee / get-display-name.php
Last active October 19, 2021 05:10
get_display_name php wordpress
<?php
/**
* REF
* https://wordpress.stackexchange.com/questions/59435/how-to-get-current-user-name-by-user-id-in-buddypress
*/
function get_display_name($user_id) {
if (!$user = get_userdata($user_id))
return false;
return $user->data->display_name;
@enlacee
enlacee / deleteProducts.js
Last active October 19, 2021 02:41
deleteProducts.js
let IDS = [
["13a84e72-2d85-4852-9670-7adea92c8d4e", "1632326405429"],
["a010b860-7bd2-460e-8799-bc491670f294", "1632326405429"],
["1e543a6d-98e0-4150-b32a-097e688958b0", "1632326405429"],
["bc22a6e5-7545-40db-a0f6-3d63dc60be71", "1632326405429"],
["dcde6e06-3f84-4c4a-b6f3-f2787caf0677", "1632326405429"],
];
let dynamoObject = { "UE1NPRODTESTDBADYNH2H014": [] };
IDS.forEach(function(element, index) {
@enlacee
enlacee / delete-duplicate-data.md
Last active October 19, 2021 02:37
delete data duplicate in dynamo - create file JSON to process
@enlacee
enlacee / date-wordpress.php
Created October 11, 2021 04:05
date in wordpress
<?php
$current_date = date_i18n('Y-m-d');
@enlacee
enlacee / javascript.sort.js
Last active October 4, 2021 19:59
order object or array with .sort
/**
** Order values custom
** @ref with array = https://stackoverflow.com/questions/1069666/sorting-object-property-by-values
**/
let obj = [{ id: 33, date: 333 }, { id: 11, date: 111 }, { id: 22, date: 222 }, { id: 0, date: 0 }];
var sortable = [];
for (var index in obj) {
sortable.push([obj[index]['id'], obj[index]['date']]);
}
@enlacee
enlacee / plugin.php
Created July 12, 2016 07:27
plugin table wordpress
<?php
/**
* Custom AJAX List Table Example
*
* Custom AJAX List Table Example is a WordPress Plugin example of WP_List_Table
* AJAX implementation. It is a fork of Matt Van Andel's Custom List Table Example
* plugin.
*
* Plugin Name: Custom AJAX List Table Example
* Plugin URI: https://github.com/Askelon/Custom-AJAX-List-Table-Example
@enlacee
enlacee / Vagrantfile
Created September 8, 2020 16:46 — forked from happycollision/Vagrantfile
A nice little Vagrantfile that spins up a MySQL server and loads in the data from your .sql file sitting next to it.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This Vagrantfile (vagrantup.com) spins up a MySQL server with your data
# already loaded. Many of the settings below are the same suggestions you get
# from `vagrant init`.
#
# Just be sure that (if you want data loaded) you have your .sql file sitting
# in the directory that will be shared to the guest. Usually this is the folder
# that your Vagrantfile is in. The database and user will have the same name as