Skip to content

Instantly share code, notes, and snippets.

@1-800-jono
1-800-jono / customNumber.js
Last active October 8, 2019 18:05 — forked from kmelve/customNumber.js
Custom Number Select input component for Sanity.io
import CustomNumberSelect from './customNumberSelect'
export default {
name: 'sizes',
type: 'number',
inputComponent: CustomNumber,
options: {
list: [
{title: 'xsmall', value: 1},
{title: 'small', value: 2},
@1-800-jono
1-800-jono / add-prefix.sh
Created January 10, 2019 17:49
Add prefix to files in a directory
for file in *.png; do mv "$file" "prefix-we-want-$file"; done;
@1-800-jono
1-800-jono / create-list-of-files-that-contain.sh
Created November 19, 2018 15:02
Create a list of files that contain a specific string.
grep -rl "string" "/path/to/files" | xargs basename > list-of-files.txt
const pathPrefixes = {
blog: 'blog',
features: 'features',
authors: 'blog/authors',
'blog-categories': 'blog/category'
}
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
@1-800-jono
1-800-jono / clone-array.js
Created September 12, 2018 15:40
Deep clone array for immutability
const newArray = myArray.map(a => Object.assign({}, a));
@1-800-jono
1-800-jono / find-distance-between-two-objects.js
Created July 5, 2018 19:39
Find distance between to objects in 3D.
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)
);
@1-800-jono
1-800-jono / random-array-item.js
Created July 5, 2018 19:20
Get random item from array in JS
nameArray = ['Mike', 'Tom', 'Jose'];
randomArrayItem = Math.floor(Math.random() * nameArray.length);
@1-800-jono
1-800-jono / AddEditTalent.js
Last active July 5, 2018 19:13
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.
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();
@1-800-jono
1-800-jono / limit-text.php
Created June 12, 2018 17:38
PHP - Limit words function.
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;
}
@1-800-jono
1-800-jono / add-checked-values-to-array-jquery.js
Created April 12, 2018 14:37
Add all checkbox checked values to array using jQuery
//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);
});
});