Skip to content

Instantly share code, notes, and snippets.

View 3v0k4's full-sized avatar

Riccardo 3v0k4

View GitHub Profile
@3v0k4
3v0k4 / README.md
Last active March 31, 2023 11:06
git amend-files

If you like me have OCCD, obsessive-compulsive-commit-disorder, you create a ton of local commits and amend/squash/fixup stuff before a git push.

Unfortunately, git commit --amend only works if you are adding to the most recent commit. But if you want to add the current file(s) changes to the latest commit that changed them, you have to rebase manually and fix up.

No more.

This is what git amend-files does:

  • Finds all modified files in the working directory.
  • Gets the hash of the most recent commit that modified each file.
@3v0k4
3v0k4 / what-the-version.md
Last active February 17, 2022 08:28
Version ranges in different languages (Ruby, JavaScript, Rust)

What The Version aka WTV?

Version ranges in different languages: Ruby, JavaScript, Rust.

It's clear what >, >=, <, or <= mean. But what about those other cryptic symbols?

Npm (package.json)

Version Equal To Only Highlighted Result
input :: String
input =
"add 1 sub 6 add 3 2"
main :: Effect Unit
main = do
logShow $ runParser astParser input
-- (Right (Add 1 (Sub 6 (Add 3 2))))
logShow $ map generate $ runParser astParser input
-- (Right "(1 + (6 - (3 + 2)))")
generate :: Ast -> String
generate (Value i) = show i
generate (Node Add ast1 ast2) =
"(" <> generate ast1 <> " + " <> generate ast2 <> ")"
generate (Node Sub ast1 ast2) =
"(" <> generate ast1 <> " - " <> generate ast2 <> ")"
evaluate :: Ast -> Int
evaluate (Value i) = i
evaluate (Node Add ast1 ast2) =
data Ast
= Node Op Ast Ast
| Value Int
instance showAst :: Show Ast where
show (Node op ast1 ast2) = "(" <> show op <> " " <> show ast1 <> " " <> show ast2 <> ")"
show (Value i) = show i
data Op
= Add
| Sub
main :: Effect Unit
main = do
testDeposit
testWithdraw
testPrintStatementNoTransactions
testPrintStatementWithTransactions
testDeposit :: Effect Unit
testDeposit = do
timestamp <- nowDateTime
data Transaction
= Deposit Info
| Withdraw Info
derive instance eqTransaction :: Eq Transaction
instance showTransaction :: Show Transaction where
show (Deposit i) = show i
show (Withdraw i) = show i
data Transaction
= Deposit Info
| Withdraw Info
type Info =
{ timestamp :: DateTime
, amount :: Int
}
deposit :: Int -> StateT (Array Transaction) Effect Unit
@3v0k4
3v0k4 / Main.purs
Created February 18, 2019 20:17
Binary Search Tree in PureScript
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (logShow, log)
import Data.List (fromFoldable)
import Data.Array (replicate, concatMap)
import Data.String.Common (joinWith)
import Data.Foldable (foldMap)
import Data.Maybe (Maybe(..))
@3v0k4
3v0k4 / Main.purs
Last active December 31, 2018 08:26
AdventOfCode 2018 PureScript - Day 10
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (logShow)
import Data.List (List(..), fromFoldable)
import Data.Array ((..))
import Text.Parsing.StringParser.CodeUnits (anyDigit, char, string)
import Text.Parsing.StringParser (Parser, runParser, ParseError, fail)
import Text.Parsing.StringParser.Combinators (many1, many, optionMaybe)