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 / react-password-form.js
Last active January 2, 2020 17:21
React: Password form component.
import React from 'react';
import ReactDOM from 'react-dom';
class Follow extends React.Component {
constructor(props) {
super(props);
this.state = {
password: 'huraji',
authorized: false
};
@debonx
debonx / sticky-bar.js
Created November 19, 2019 20:01
Sticky navigation bar in jQuery.
$(function(){
var position;
var width = $(window).width();
var position = $(this).scrollTop();
$(document).scroll(function() {
var currentScroll = $(this).scrollTop();
@debonx
debonx / gutenberg-woocommerce-blocks.php
Created November 19, 2019 09:38
How to filter Gutenberg WooCommerce blocks in WordPress.
add_filter( 'woocommerce_blocks_product_grid_item_html', 'filter_product_block', 10, 3);
function filter_product_block( $html, $data, $product )
{
$html = '<li class="wc-block-grid__product">
<div class="image-wrap">
<a href="' . $data->permalink . '" class="wc-block-grid__product-link">' . $data->image . '</a>
' . $data->button . '
</div>
<h3><a href="' . $data->permalink . '">' . $data->title . '</a></h3>
' . $data->badge . '
@debonx
debonx / unlucky-numbers.php
Created November 15, 2019 11:35
Filter out unlucky numbers from a sequence.
<?php
/**
* Filter out unlucky numbers from a range
*/
$n = 50;
/**
* Imperative approach
*/
@debonx
debonx / dynamic-spaces.scss
Created November 13, 2019 16:03
SCSS / SASS dynamic margin and padding classes in rem, using @Mixins. Can be customised as needed.
$spaces: 20;
@mixin margin($size) {
margin: $size + rem;
}
@mixin margin-top($size) {
margin-top: $size + rem;
}
@mixin margin-left($size) {
margin-left: $size + rem;
}
@debonx
debonx / guess-what.php
Created November 10, 2019 17:19
Guessing game in php.
<?php
$play_count = 0;
$correct_guesses = 0;
$guess_high = 0;
$guess_low = 0;
echo "I'm going to think of numbers between 1 and 10 (inclusive). Do you think you can guess correctly?\n";
function guessNumber() {
@debonx
debonx / magic-8ball.php
Created November 10, 2019 16:44
Good old 8 ball.
<?php
function magic8Ball()
{
echo "Ok, what's your question?\n";
$question = readline(">");
echo "\nHmm so question your queston is ${question}... I have consulted the spirit world.\nHere is your answer: ";
$magicN = rand(0, 19);
switch($magicN){
case 0:
@debonx
debonx / the-sorting-hat.php
Created November 10, 2019 09:47
The PHP sorting hat.
<?php
$gryffindor = 0;
$hufflepuff = 0;
$ravenclaw = 0;
$slytherin = 0;
//$answer1, $answer2, $answer3;
echo "================\nThe Sorting Hat!\n================\n\n";
@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,
@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 )