Skip to content

Instantly share code, notes, and snippets.

View ravicious's full-sized avatar

Rafał Cieślak ravicious

View GitHub Profile
@ravicious
ravicious / .zshrc
Created July 8, 2019 17:20
Time in ZSH prompt
RPROMPT="%{$fg[white]%}[%*]%{$reset_color%}"
# Reset the prompt before accepting the line.
# https://stackoverflow.com/a/35051172
function _reset-prompt-and-accept-line {
zle reset-prompt
zle .accept-line # Note the . meaning the built-in accept-line.
}
zle -N accept-line _reset-prompt-and-accept-line
[alias]
# Undoes last commit and leaves the files commited by it in the staging area.
undo-commit = reset --soft HEAD^
today = !git log --since=midnight --author=\"$(git config user.name)\" --color --graph --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr)%Creset' --abbrev-commit
yesterday = !git log --since="yesterday.midnight" --until=midnight --author=\"$(git config user.name)\" --color --graph --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr)%Creset' --abbrev-commit
# More succint version of `git status`.
st = status -sb
# It takes ages to type `rebase --continue`.
rc = rebase --continue
# My preffered version of `git log`.
@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 ->