Skip to content

Instantly share code, notes, and snippets.

View leonardfactory's full-sized avatar
Inventing

Leonardo Ascione leonardfactory

Inventing
View GitHub Profile
// 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
@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 (
@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"
/**
* Just a snippet, but it should work
*/
const {
roundedHeight,
height,
width
} = this.props;
const heightSq = Math.pow(roundedHeight - height, 2);
<?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();
@leonardfactory
leonardfactory / sample-fp.js
Last active September 2, 2016 11:13
Data types in Flow
// Definition
export type Primitive = { type: string; };
// 'Factory'
export function Primitive(type:string) {
return {
type: string;
}
}
@leonardfactory
leonardfactory / .eslintrc.json
Created July 21, 2016 13:10
.eslintrc.json
{
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": [
"react",
"flowtype"
],
"rules": {
"react/sort-comp": 0,
"key-spacing": [2, { "align": "colon" }],
@leonardfactory
leonardfactory / flow-knex.jsx
Created July 13, 2016 14:04
Flow - Knex typing
// Flow definition
declare module 'knex' {
declare class SchemaBuilder {
...
createTable(name:string, fn:() => void): this;
}
declare class TableBuilder {
...
}
@leonardfactory
leonardfactory / ES6 Dev Notes.md
Last active July 11, 2016 20:29
Un insieme di note per la configurazione di un ambiente di sviluppo per ES6, sia frontend che backend.

ES6 Dev Notes

Un insieme di note per la configurazione di un ambiente di sviluppo per ES6, sia frontend che backend. Perché per quanto Webpack sia un labirinto, con un filo di arianna la strada si può trovare.

Webpack

Configurazione in ES6 (con Babel)

Per utilizzare ES6 nel config di Webpack è necessario:

  • Chiamare il file webpack.config.babel.js (per far riconoscere a webpack che è necessario chiamare il babel-loader).
# v1.
$ flow autocomplete --json --strip-root src/app/components/_test/test2.js 20 10 < src/app/components/_test/test2.js
{"result":[]}
$ flow autocomplete --strip-root src/app/components/_test/test2.js 20 10 < src/app/components/_test/test2.js
extended string
method () => void
prop number