Skip to content

Instantly share code, notes, and snippets.

View ramidecodes's full-sized avatar
🔧
Building

Ramiro ramidecodes

🔧
Building
View GitHub Profile
@ramidecodes
ramidecodes / useFetch
Last active July 20, 2020 08:44
Custom React Hook for Fetching URLs
const useFetch = (url) => {
const cache = useRef({});
const [status, setStatus] = useState('idle');
const [data, setData] = useState([]);
useEffect(() => {
let cancelRequest = false;
if (!url) return;
const fetchData = async () => {
@ramidecodes
ramidecodes / get_file_list.py
Created July 10, 2019 15:59
Feturns a (flat) list of paths of all files of (certain types) recursively under a path
def get_file_list(path, extensions=['jpg', 'jpeg', 'png']):
'''returns a (flat) list of paths of all files of (certain types) recursively under a path'''
paths = [os.path.join(root, name)
for root, dirs, files in os.walk(path)
for name in files
if name.lower().endswith(tuple(extensions))]
return paths
@ramidecodes
ramidecodes / dirExistSync.js
Created February 1, 2018 15:35
NodeJS script for checking if a directory exist and create it
const fs = require('fs')
function dirExistSync(dirPath) {
try {
return fs.statSync(dirPath).isDirectory()
} catch (e) {
if (e.code === 'ENOENT') {
return false
} else {
throw e

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@ramidecodes
ramidecodes / php-log-to-console.php
Created September 12, 2016 16:39
PHP Log to Console
function debug_to_console( $data ) {
if ( is_array( $data ) )
$output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
else
$output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";
echo $output;
}
@ramidecodes
ramidecodes / woocommerce_add_field_checkout.php
Last active June 19, 2016 16:33
Woocommerce filter to add custom field to checkout procces (Including Admin Area Details and Email)
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'k2r_custom_checkout_field_update_order_meta' );
function k2r_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['shipping_phone'] ) ) {
update_post_meta( $order_id, 'Shipping Phone', sanitize_text_field( $_POST['shipping_phone'] ) );
}
}
jQuery.fn.brightness = function() {
var bg_color, rgba, y;
bg_color = this.css('background-color');
if ((bg_color != null) && bg_color.length) {
rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
if (rgba != null) {
if (rgba[4] === '0') {
if (this.parent().length) return this.parent().brightness();
} else {
y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];
<style type="text/css">p {text-align:center;width: auto}</style>

Created by Christopher Manning

Gallery

Axle Eight [Fibbobaci](http://bl.ocks.org/d/1703449/#/[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169]43/0/1) [Florets](http://bl.ocks.

<style type="text/css">p {text-align:center;width: auto}</style>

Created by Christopher Manning

Gallery

Axle Eight [Fibbobaci](http://bl.ocks.org/d/1703449/#/[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169]43/0/1) [Florets](http://bl.ocks.

@ramidecodes
ramidecodes / the_excerpt_max_charlength
Created May 11, 2014 10:25
php-wp Limit the excerpt max characters
the_excerpt_max_charlength(140);
function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );