Skip to content

Instantly share code, notes, and snippets.

View debonx's full-sized avatar
🍕
Food processing

Emanuele De Boni debonx

🍕
Food processing
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / react-proptypes.js
Last active January 2, 2020 17:21
React: How to set propTypes stateless component.
import React from 'react';
export class BestSeller extends React.Component {
render() {
return (
<li>
Title: <span>
{this.props.title}
</span><br />
@debonx
debonx / react-stateless-functional-component.js
Created January 2, 2020 19:00
React: Stateless functional component example.
// Normal way to display a prop:
export class MyComponentClass extends React.Component {
render() {
return <h1>{this.props.title}</h1>;
}
}
// Stateless functional component way to display a prop:
export const MyComponentClass = (props) => {
return <h1>{props.title}</h1>;