Skip to content

Instantly share code, notes, and snippets.

Jonathan jonathanphz

Block or report user

Report or block jonathanphz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jonathanphz
jonathanphz / add-prefix.sh
Created Jan 10, 2019
Add prefix to files in a directory
View add-prefix.sh
for file in *.png; do mv "$file" "prefix-we-want-$file"; done;
@jonathanphz
jonathanphz / create-list-of-files-that-contain.sh
Created Nov 19, 2018
Create a list of files that contain a specific string.
View create-list-of-files-that-contain.sh
grep -rl "string" "/path/to/files" | xargs basename > list-of-files.txt
View gatsby-node.js
const pathPrefixes = {
blog: 'blog',
features: 'features',
authors: 'blog/authors',
'blog-categories': 'blog/category'
}
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
@jonathanphz
jonathanphz / clone-array.js
Created Sep 12, 2018
Deep clone array for immutability
View clone-array.js
const newArray = myArray.map(a => Object.assign({}, a));
@jonathanphz
jonathanphz / find-distance-between-two-objects.js
Created Jul 5, 2018
Find distance between to objects in 3D.
View find-distance-between-two-objects.js
var p1 = objectOne.position;
var p2 = objectTwo.position;
var distance = Math.sqrt(
(p1.x - p2.x) * (p1.x - p2.x) + (p1.z - p2.z) * (p1.z - p2.z)
);
@jonathanphz
jonathanphz / random-array-item.js
Created Jul 5, 2018
Get random item from array in JS
View random-array-item.js
nameArray = ['Mike', 'Tom', 'Jose'];
randomArrayItem = Math.floor(Math.random() * nameArray.length);
@jonathanphz
jonathanphz / AddEditTalent.js
Last active Jul 5, 2018
React JS file - this is a multi-step form. Upload a CV/Resume then it gets analyzed on the server for keywords. This keywords are sent back as a response and then it populates the proper fields accordingly. Using React.js and Apollo.
View AddEditTalent.js
import React, { Component } from 'react';
import { gql, graphql, compose } from 'react-apollo';
import request from 'superagent';
import LoadingFetch from '../helpers/LoadingFetch';
import SingleInput from '../forms/SingleInput';
class AddEditTalent extends Component {
constructor() {
super();
@jonathanphz
jonathanphz / limit-text.php
Created Jun 12, 2018
PHP - Limit words function.
View limit-text.php
function limit_text($text, $limit) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
@jonathanphz
jonathanphz / add-checked-values-to-array-jquery.js
Created Apr 12, 2018
Add all checkbox checked values to array using jQuery
View add-checked-values-to-array-jquery.js
//We need the window to load completely before using this function
jQuery(window).load(function() {
jQuery('.some-form').submit(function (e) {
e.preventDefault();
var checkedProfessions = jQuery('.checkbox-container input:checkbox:checked').map(function() {
return jQuery(this).val();
}).get(); //Converts to array
console.log(checkedProfessions);
});
});
@jonathanphz
jonathanphz / add_extra_post_type_to_loop.php
Last active Mar 26, 2018
WordPress: Add extra post types to main WP post loop. Add this code to functions.php file.
View add_extra_post_type_to_loop.php
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'custom_post_name' ) );
$query->set( 'order', 'ASC');
$query->set( 'posts_per_page', 3);
}
You can’t perform that action at this time.