Skip to content

Instantly share code, notes, and snippets.

View matiasfha's full-sized avatar

Matías Hernández Arellano matiasfha

View GitHub Profile
@matiasfha
matiasfha / Menu.js
Created May 13, 2018 21:16
Flow union type
/* @flow */
import * as React from 'react'
type BaseMenuPropsT = {
icon: string | { img: string, ticker: number },
label?: string
}
type RenderT = { render: () => React.Node }
type ChildrenT = { children: () => React.Node }
type DataT = { data: Object }
@matiasfha
matiasfha / Router.js
Created May 13, 2018 21:07
Check props on componentWillMount
class Component extends React.Component {
componentWillMount() {
warning(
!(this.props.component && this.props.render),
"You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored"
);
warning(
!(
this.props.component &&
@matiasfha
matiasfha / Item.js
Created January 24, 2018 01:18
Item functional component
const Item = ( { item, handleItemClick, getItemClassName } ) =>
<div
key={item.id}
className={getItemClassName(item)}
onClick={handleItemClick(item)}
>
<div className="main">{item.lastName}, {item.firstName}</div>
<div className="secondary">
{item.company}
<span className="meta"> (hired: {item.hireDate})</span>
@matiasfha
matiasfha / DeleteFIleAndCloseBuffer.vim
Created January 23, 2018 12:40
Delete current file in vim and close the buffer.
" Delete the current file and close the buffer
function! DeleteFileAndCloseBuffer()
let b:choice = confirm("Delete file and close buffer?", "&Yes\n&No",1)
if b:choice == 1
call delete(expand('%:p')) | bdelete!
endif
endfunction
" Map to ;rm
nnoremap <silent> <leader>rm :call DeleteFileAndCloseBuffer()<CR>
@matiasfha
matiasfha / MoveSelectionToBuffer.vim
Last active January 19, 2018 19:32
MoveSelectionToBuffer is a command that allows you to move a block of text from the current buffer to a new buffer that will be saved in the same path as the original buffer with the name that is passed as argument. The original text will be removed and pasted in the new buffer. Flaws: I didn't find a way to call the command using a key mapping.
function! AddPathToName(name)
let b:path = expand('%:p:h')
let b:filename = join([b:path, a:name],'/')
execute "vnew ". b:filename
endfunction
"named vnew
command! -nargs=1 VN call AddPathToName(<f-args>)
function! MoveSelectionToBuffer(name)
@matiasfha
matiasfha / flatten.js
Created November 15, 2017 09:59
ES6 Flatten Array
const flatten = list => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
{
"flight_type":"domestic",
"num_passengers":1,
"pickup_datetime":null,
"flight_datetime":"2017-04-12T08:30:00-07:00",
"search_id":"703ea611fe4d420e831b3a5aa0ac598a",
"results":[
{
"result_id":"1b074ec7117f4291aa2278fecd057a88",
"total_price":{
{
"flight_type":"domestic",
"num_passengers":1,
"pickup_datetime":null,
"flight_datetime":"2017-04-12T08:30:00-07:00",
"search_id":"6d0da58c3afd4f59b1c71d353cdfa163",
"results":[
{
"result_id":"1b074ec7117f4291aa2278fecd057a88",
"total_price":{
module Components.Products.Model exposing (..)
type alias Product =
{id : Int
,image: String
,title: String
,description: String
,price: Int
,quality: String
}
module Model exposing (..)
import Routing
import Components.Productos.Model as Products
type alias Model =
{ route: Routing.Route
, products: Products.Model
}