Skip to content

Instantly share code, notes, and snippets.

View ravicious's full-sized avatar

Rafał Cieślak ravicious

View GitHub Profile
@ravicious
ravicious / _index.js
Created April 15, 2017 10:51
Flow JSON output example where the first message doesn't point to the current file
// @flow
import ReactDOM from 'react-dom'
var Foo = require('./foo.js')
// Foo is missing the `bar` prop here.
//
// When you open this file in vim-ale v1.2.0, it'll highlight the wrong line,
// since it takes the loc information of the first message
// under errors[0].message[0], which in this case points to `foo.js`,
// which is not the file opened in the current buffer.
@ravicious
ravicious / AutoSavingForm.md
Last active March 31, 2017 12:24 — forked from oyeanuj/AutoSavingForm.md
Auto-saving forms using Redux-Form – @oyeanuj solution piped through prettier

Here is how I ended up making this work. For more context and background on the discussion, I recommend reading conversation in ReduxForm#2169 (and chiming in with your learnings, etc).

So, as per the conversation there, I tried the 'many little forms' approach. I am sharing both my approach, and a crude abstracted out gist that can hopefully help out y'all.

Essentially, with this approach:

  1. You want to use each field as a little form which submits debounced onChange.
  2. For each field as a little form, you want to abstract that into a component which can be provided an input, as much as possible.
  3. Set autofocus for the first form.
  4. For debounced onChange, I used react-debounced-input.
// @flow
// https://flowtype.org/try/#0PTAEAEDMBsHsHcBQiCmAPADrATgF1LgJ4YqgBKKAtrLigCICGuDAPAKLbY4AqxKANKABqDaAFcUvEgD5QAXkShQAH1ABvUAGdmtAFygA5ADsaAQU0BrFABMDoAL6KV6rTpT6DcBtYCWRgOZ2jkqqGtpM7oaQDD7i2CgGgiicOPocXNhSpMHOYW4emmIAxkUompqJoABuohL6IuKSfA4A3MjoWHigkGJGRbg+sEagJrjmVtbsKZl8gg0SWdIAFACU+hTUtIzMUxlZc7VNMupO8bhi2MN5ER6j4zZBbY6omDj4PX0DQ6BevgG7PFmwkOi1W6yoNHoTFY6UBJAOjUWJyUZwuV1cN0Mvz8gVaiGeHTe3V6-UGw2isQuKABM3hwMRfGWyQyaWmWTW5AhW2hNP29IWjORoFRlxc4T0URicQSSWmeIJry6H1J30KJTKml5QPmRxQyxqjXqIL4HI2kO2MLZ2uNxzUpxQ51F1wlBjVpXKlQNEnlyGgDu6sFg4M2UJ22mwOME4ZxsjkWmK7s0SwMDHg8FAhBQDAAFgYVm1IIH5N0pVTk7BsyNA3mC0W49iAqta7Bi3dLDYm0A
export type RemoteData<ErrorType, ValueType> =
| { state: 'notAsked' }
| { state: 'loading' }
| { state: 'failure', error: ErrorType }
| { state: 'success', value: ValueType };
export function notAsked<ErrorType, ValueType>(): RemoteData<ErrorType, ValueType> {
@ravicious
ravicious / SSCCE.elm
Created November 13, 2016 19:00
A SSCCE for an issue with elm-lang/html. You can paste it to http://elm-lang.org/try.
import Html exposing (..)
import Html.Attributes exposing (..)
import Json.Encode
valueAttributes =
[ value ""
, property "value" (Json.Encode.string "")
, attribute "value" ""
]
$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :t foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
$ elm repl
---- elm-repl 0.17.1 -----------------------------------------------------------
:help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> List.foldl
@ravicious
ravicious / reproduction.rb
Created August 18, 2016 17:55
Reproduction of the issue with using the `primitive` method within the custom attribute class body.
# ruby reproduction.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
type alias TimesClicked = Int
type alias Count = Int
updateCount : Msg -> TimesClicked -> TimesClicked
updateCount msg count =
case msg of
Increment ->
if count < maxCount then count + 1 else count
Decrement ->
@ravicious
ravicious / keybase.md
Created October 4, 2015 12:02
Keybase.io verification

Keybase proof

I hereby claim:

  • I am ravicious on github.
  • I am ravicious (https://keybase.io/ravicious) on keybase.
  • I have a public key whose fingerprint is 0521 7C74 347E 6D6B 7882 728B FF5B 4F7D 53F3 19D9

To claim this, I am signing this object:

threads = concurrency_level.times.map { |i|
-> {
Thread.new do
begin
customers[i].buy_products([{quantity: 1, product: product}])
rescue Orders::CreateOrderService::Invalid
fail_occurred = true
end
end
}