Skip to content

Instantly share code, notes, and snippets.

View leonardfactory's full-sized avatar
Inventing

Leonardo Ascione leonardfactory

Inventing
View GitHub Profile
<?php
class PetsPlugin {
public boot() {
User::extend(function($model) {
// Evitiamo di salvare i 'pet_save_data' nel DB
$model->purgeable[] = ['pet_save_data'];
// Quando viene salvato un User, provvediamo a salvare anche il Pet correlato
$model->bindEvent('beforeSave', function($user) {
$pet = Pet::where('user_id', $user->id)->findOne();
/**
* Just a snippet, but it should work
*/
const {
roundedHeight,
height,
width
} = this.props;
const heightSq = Math.pow(roundedHeight - height, 2);
@leonardfactory
leonardfactory / redcarpet_pygments.rb
Created May 7, 2013 14:22
Custom Jekyll markdown converter allowing us to configure Pygments and other nice things like inline code styling.
# Jekyll v1 made internal markdown converters.
# Here we change the module, allowing our custom parser to be used.
module Jekyll
module Converters
class Markdown < Converter
safe true
pygments_prefix "\n"
pygments_suffix "\n"
@leonardfactory
leonardfactory / context-with-hooks.tsx
Last active February 20, 2019 21:56
React Apollo & Hooks
// Let's define our context...
const ThemeContext = React.createContext(...);
// This component is nested in a `ThemeContext.Provider` node..
function MyComponent(props: Props) {
// No more HOCs!
const theme = useContext(ThemeContext);
// It's a kind of magic
return (
// HOC. Conterrà sia le proprietà del connect che quelle del componente in se
interface Props {}
function Component(props: Props) {
return ...;
}
export const ComponentConnected = connect(...)(Component);
// Hook. I dati del `connect` sono interni al Componente