Skip to content

Instantly share code, notes, and snippets.

View debonx's full-sized avatar
🍕
Food processing

Emanuele De Boni debonx

🍕
Food processing
  • adidas ///
  • Amsterdam
View GitHub Profile
@debonx
debonx / sleep-hours.js
Created July 28, 2019 09:03
Javascript ES6 basic script to calculate sleep hours.
const getSleepHours = day => 8;
const getActualSleepHours = () => getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + getSleepHours('Thursday') + getSleepHours('Friday') + getSleepHours('Saturday') + getSleepHours('Sunday');
const getIdealSleepHours = () => {
let idealHours = 8;
return idealHours * 7;
}
const calculateSleepDebt = () => {
@debonx
debonx / whale-speech.js
Created August 13, 2019 17:53
Example of converting regular sentences into whale language.
let input = 'Mi chiedi qual è stato il mio progresso? Ho cominciato a essere amico di me stesso.';
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];
for(i = 0; i < input.length; i++){
//console.log(i);
for(j = 0; j < vowels.length; j++){
if(input[i] === vowels[j]) {
if(vowels[j] === 'e' || vowels[j] === 'u') {
resultArray.push(vowels[j] + vowels[j]);
@debonx
debonx / mini-linter.js
Created August 18, 2019 20:21
Javascript mini linter.
let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey. The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side. An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson. Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';
let overusedWords = ['really
@debonx
debonx / meal-generator.js
Last active August 27, 2019 15:12
Practicing JS advanced objects through a meal generator. You'll get an appetizer, a main and a dessert. Is it enough?
// Creating Menu
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: []
},
get courses(){
return {
appetizers: this.appetizers,
@debonx
debonx / cursed-team.js
Created August 27, 2019 15:11
Team JS object for cursed players.
const team = {
_players: [
{
firstName: 'Carol',
lastName: 'Snitz',
age: 31
},
{
firstName: 'Julie',
lastName: 'Lingus',
@debonx
debonx / library-catalog.js
Created September 2, 2019 13:42
A javascritpt based class to catalog Media objects.
class Media {
constructor(title) {
this._title = title;
this._isCheckedOut = false;
this._ratings = [];
}
get title(){
return this._title;
}
get isCheckedOut(){
@debonx
debonx / school-classifier.js
Created September 3, 2019 11:39
Simple JavaScript class to classify schools.
class School {
constructor(name, level, numberOfStudents){
this._name = name;
this._level = level;
this._numberOfStudents = numberOfStudents;
}
get name(){
return this._name;
}
get level(){
@debonx
debonx / fancy-string.js
Created September 5, 2019 15:45
A fancy Javascript object to manipulate strings.
const FancyString = {};
FancyString.countCharacter = function(inputString, inputCharacter) {
let count = 0;
let string = inputString.toLowerCase();
let character = inputCharacter.toLowerCase();
for (let i = 0; i < string.length; i++) {
if (string[i] === character) {
count++;
}
}
@debonx
debonx / wc_product_image_thumbs.php
Last active September 5, 2021 12:05
WooCommerce snippet to customise Single Product image thumbs.
<?php /**
* Single Product Thumbnails
*
* @param array $args
* @param int $attachment_id
* @param string $image_size
* @param bool $main_image
* @return array
*/
function bones_gallery_image_html_attachment_image_params ( $args, $attachment_id, $image_size, $main_image )
@debonx
debonx / declarative-expenses.php
Last active November 9, 2019 11:33
Play with php built-in array_sum(), array_map(), array_filter() to calculate yearly savings from arbitrary taxes and income.
<?php
$annualExpenses = [
"vacations" => 1000,
"carRepairs" => 1000,
];
$monthlyExpenses = [
"rent" => 1500,
"utilities" => 200,