Skip to content

Instantly share code, notes, and snippets.

View lenivene's full-sized avatar
🖖
Full-stack dev

Lenivene Bezerra lenivene

🖖
Full-stack dev
View GitHub Profile
@lenivene
lenivene / Constants.js
Created April 24, 2019 04:40
Constants React Native
import { Dimensions } from "react-native";
const { width, height } = Dimensions.get("window");
const Constants = {
useReactotron: true, // Debug
Language: "en",
fontFamily: "system font", // Default font
WordPress: { // No required
defaultDateFormat: "YYYY-MM-DD HH:mm:ss"
@lenivene
lenivene / functions.php
Created May 8, 2019 07:59
'recode' WordPress function - is_email()
<?php
/**
* Verifies that an email is valid.
*
* @param $email (string) (Required) Email address to verify.
* @return (string|bool) Either false or the valid email address.
*/
function is_email( $email ){
// Test for the minimum length the email can be
if ( mb_strlen( $email ) < 6 ) {
@lenivene
lenivene / is_date_valid.php
Last active June 11, 2019 16:41
Function PHP - Validate Date, returns TRUE if the date given is valid; otherwise returns FALSE.
<?php
/**
* Validate Date
*
* @return boolean Returns TRUE if the date given is valid; otherwise returns FALSE.
*/
function is_date_valid( $date, $format = 'Y-m-d H:i:s'){
if( ! isset( $date ) || isset( $date ) && ! is_string( $date ) )
return false;
@lenivene
lenivene / functions.php
Created May 21, 2019 18:16
Function in order to support previous versions of WordPress < 5.2
<?php
/**
* Function in order to support previous versions of WordPress
*/
if ( ! function_exists( 'wp_body_open' ) ) {
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
<?php
function count_months_in_time( $timestamp ){
$time_now = time();
$months = ( ( ( date( 'Y', $timestamp ) - date( 'Y', $time_now ) ) * 12 ) + ( date( 'm', $timestamp ) - date( 'm', $time_now ) ) );
return $months;
}
echo count_months_in_time( strtotime( date( '09/08/2019' ) ) );
@lenivene
lenivene / Pluck.js
Last active September 16, 2019 14:02
A simple pluck function.
module.exports = (object, ...keys) => {
const newObject = {};
keys.forEach(key => newObject[key] = object[key])
return newObject;
}
@lenivene
lenivene / hierarchy_tree.php
Last active September 16, 2019 14:03
PHP: Create a array tree from array list
<?php
/**
* Create a array tree from array list
*
* @param array ( Required ) The list to create tree
* @param string The name key parent. Ex: parent_id
* @param string The key to check child. Ex: ID
*
* @return array|false Returns array if the date given is not empty; otherwise returns FALSE.
*/
@lenivene
lenivene / array_sort_by_column.php
Created September 16, 2019 14:00
Array sort by column
<?php
/**
* Array sort by column
*
* @author Lenivene
* @param array List
* @param string|array Columns name or single column
* @param int Order BY ASC|DESC.
* I recommend you use constant, Ex: SORT_ASC = 4 ( int ) | SORT_DESC = 3 ( int )
*/
@lenivene
lenivene / code.php
Last active September 27, 2019 03:27
Get boolean false or true in value.
<?php
if( ! defined( 'FILTER_VALIDATE_BOOLEAN' ) ){
define( 'FILTER_VALIDATE_BOOLEAN', 258 );
}
$db_value = 1;
$bool_value = filter_var( $db_value, FILTER_VALIDATE_BOOLEAN );
var_dump( $bool_value );
<div class="components__Loader"></div>