Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)V
Posts
16
Comments
45
Joined
2 yr. ago

  • I coded this along with my girlfriend who's learning python, but not motivated to share her solution. The program reads from stdin, because I usually invoke it like so: runhaskell Main.hs < input or runhaskell Main.hs < example. I think this is quite handy because I don't have to change the source code to check the example input again.

    I struggled with Part 3, where I suddenly forgot I could've simply used mod, which I ended up doing anyway. I immediately recognized that Part 3 needs Mutable Arrays if I care to avoid Index hell, which is not what I wanted to with Haskell but oh well.

     haskell
        
    {-# OPTIONS_GHC -Wall #-}
    {-# LANGUAGE PatternSynonyms #-}
    module Main (main) where
    
    import qualified Data.Text as Text
    import qualified Data.Text.IO as TextIO
    import Control.Monad ((<$!>), forM_)
    import Data.Text (Text, pattern (:<))
    import qualified Data.List as List
    import qualified Data.Array.MArray as MutableArray
    import Control.Monad.ST (runST, ST)
    import Data.Array.ST (STArray)
    
    commaSepLine :: IO [Text.Text]
    commaSepLine = Text.split (== ',') <$!> TextIO.getLine
    
    readInstruction :: Text -> Int
    readInstruction ('R' :< n) = read . Text.unpack $ n
    readInstruction ('L' :< n) = negate . read . Text.unpack $ n
    readInstruction _ = undefined
    
    myName :: (Foldable t, Ord b, Enum b, Num b) => b -> t b -> b
    myName maxPosition = List.foldl' (\ pos offset -> min (pred maxPosition) . max 0 $ pos + offset) 0
    
    parentName1 :: [Int] -> Int
    parentName1 = List.sum
    
    newSTArray :: [e] -> ST s (STArray s Int e)
    newSTArray xs = MutableArray.newListArray (0, length xs - 1) xs
    
    swap :: (MutableArray.MArray a e m, MutableArray.Ix i) => a i e -> i -> i -> m ()
    swap array i0 i1 = do
      e0 <- MutableArray.readArray array i0
      e1 <- MutableArray.readArray array i1
      MutableArray.writeArray array i0 e1
      MutableArray.writeArray array i1 e0
    
    parentName2 :: [Text] -> [Int] -> Text
    parentName2 nameList instructions = runST $ do
      names <- newSTArray nameList
      arrayLength <- succ . snd <$> MutableArray.getBounds names
      forM_ instructions $ \ offset -> do
        let arrayOffset = offset `mod` arrayLength
        swap names 0 arrayOffset
      MutableArray.readArray names 0
    
    main :: IO ()
    main = do
      names <- commaSepLine
      _ <- TextIO.getLine
      instructions <- fmap readInstruction <$> commaSepLine
    
      let namesLength = length names
      print $ names !! myName namesLength instructions
      print . (names !!) . (`mod` namesLength) $ parentName1 instructions
      print $ parentName2 names instructions
    
      
  • Somewhat, I'm quite motivated but it's part of my studies.

  • Briesiges Wetter ist die beste Wetter-App, ändere meinen Verstand.

  • I also like watching Doctor Who, how did you manage to make a cute dalek? :d

  • The extension is called Burn-My-Windows and I always look forward to it when booting into GNOME because it feels so ✨fancy✨

  • I stumbled over Gradience just yesterday but I tought it was archived sometime last year, is it still working accordingly?

  • Unfortunately not :/ But I do have rainbow-gradient window borders.

  • I suppose you're mainly concerned about LibAdwaita-Apps?

  • I was surprised to learn that

    • a) macOS only recently added Left/Right-tiling natively (without extensions, just like GNOME does)
    • b) they leave gaps when you tile them so that it looks like you messed up the tiling somehow
  • Thank you for the detailed answer, especially the explanation 'in more words' and the link helped me understand what happens in this Monoid instance.

  • Thanks a lot for the recommendation, I did enjoy the read!

  • I was wondering about encryption (is this what you're talking about?) because these algorithms change so frequently I'd be surprised if they had anything back then considered 'secure' by now.

  • You could wrap the entirety of your file in a monster macro but you'd still have to assign the macro result to a variable you need to register, which doesn't sound viable to me at least.

    Maybe you can use a script that would extract all the trait implementations and create the boilerplate glue code for you, something like this:

     bash
        
    grep --recursive --only-matching "impl PluginFunction for \w*" functions/ | sed --quiet "s/functions\/\(.*\)\.rs:impl PluginFunction for \(\w*\)/crate::functions::\1::\2{}.register(\&mut functions_map)/p"
    
    
      

    I tried to recreate your situation locally but it may not match perfectly, maybe you'll have to adjust it a little. When I run it on my file tree which looks like this

     
        
    functions
    ├── attr.rs
    ├── export.rs
    └── render.rs
    
    1 directory, 3 files
    
    
      

    where every file has a content like this

     rust
        
    // comment
    
    pub struct MyAttrStructName {}
    
    impl PluginFunction for MyAttrStructName {
    
    }
    
      

    Then I receive the following output:

     rust
        
    crate::functions::attr::MyAttrStructName{}.register(&mut functions_map)
    crate::functions::export::MyExportStructName{}.register(&mut functions_map)
    crate::functions::render::MyRenderStructName{}.register(&mut functions_map)
    
      
  • You can use backreferences \1 \2 etc. but you can also give them names explicitly.it looks like this: (?<name>inner-regex)Some flavors support it, kotlins doesn't apparently.

  • I don't actually know whether POSIX grep would support named groups :o

  • Ich bin leider jetzt furchtbar neugierig, wo die Vorlage herkommt, wonach kann ich bei knowyourmeme o.ä. suchen?