Thread: [KT] NBUtil: Make your kotlin easier

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1 [KT] NBUtil: Make your kotlin easier 
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    639
    Thanks given
    243
    Thanks received
    117
    Rep Power
    260
    This was created in Kotlin 1.3, so I cannot guarantee compatability with any kotlin version released beforehand

    I have had some down-time of not being able to work on my project because I had to undergo surgery, and I can't bring my desktop to the hospital as far as I know, so I decided to make use of my laptop and write these because I will be using them all in my project: [Only registered and activated users can see links. ]

    I have already found use cases for nearly all of them in my project, so I am releasing hem in hopes that others may find them useful and can learn from them!
    Here's a numbered list of utils.
    1. RandomUtil includes
      • Random collection generation
      • Collection shuffling (in place and not in place)
      • Random number ranges (RandomIntRange(0, 10, false) will only produce all numbers 0 through 9)
      • Random number progressions (RandomIntProgression(0, 10, 2) will only produce 0, 2, 4, 6, 8 and 10)
      • String shuffling and String random generator
      • Random Tables (essentially List.random()) and Weighted Tables (can take outside weights)
      • Memoized Weighted Tables (remembers all given outside weights for sped up access)
      • A Universal Random class (you have to provide the sources). I don't really see the point in this one, but someone somewhere would find it useful.
    2. BoolUtil includes
      • Space-minded alternative to BooleanArrarray, DenseBoolList. Uses 1 bit per Boolean but identical operation.
      • API-level copy/replace with BooleanArray, List<Boolean> and Array<Boolean>
      • MutableDenseBoolList is a space-minded alternative to MutableList<Boolean>
      • Destructuring Number to Boolean. Ex: val (bool1, bool2, bool3) = longValue // Long can have up to 64 destructured values
    3. NumberUtil inclues:
      • converting primitive numbers to and from ByteArrays
      • Primitive number vector classes as well as interfaces so you can make your own
      • Checking if primitive numbers are even or odd
    4. StringUtil includes:
      • String manipulation
      • String translation to\from user given translation tables
      • English checking functions
      • Capitalization, symbolic and numeric checking functions
    5. TagUtil
      • Create your own tag language and write it directly in your IDE
    6. DelegateUtil
      • Minimize custom setter/getter boilerplate with variable delegates!
    7. ColorUtil
      • Convert to and from RGB, CMYK, HSL and HSV color formats!


    Link: [Only registered and activated users can see links. ]

    Spoiler for old link:

    Old git link with all utils: [Only registered and activated users can see links. ]
    Last edited by nbness2; 06-12-2019 at 12:59 PM. Reason: Added ColorUtil
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Forum Moderator

    Corey's Avatar
    Join Date
    Feb 2012
    Posts
    1,160
    Thanks given
    835
    Thanks received
    817
    Rep Power
    3378
    You should throw this in a github repo, nobody downloads code from a mediafire link, that's not how you share code - i.e. I want to browse the code but cant be arsed downloading a zip and manually looking at the code through an IDE/editor
    Last edited by Corey; 11-15-2018 at 10:19 PM.

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    639
    Thanks given
    243
    Thanks received
    117
    Rep Power
    260
    Quote Originally Posted by Corey View Post
    You should throw this in a github repo, nobody downloads code from a mediafire link, that's not how you share code - i.e. I want to browse the code but cant be arsed downloading a zip and manually looking at the code through an IDE/editor
    [Only registered and activated users can see links. ]
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #4  
    Forum Moderator

    Corey's Avatar
    Join Date
    Feb 2012
    Posts
    1,160
    Thanks given
    835
    Thanks received
    817
    Rep Power
    3378
    Quote Originally Posted by Nbness2 View Post
    [Only registered and activated users can see links. ]
    Access denied. GitHub is better

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  6. #5  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    639
    Thanks given
    243
    Thanks received
    117
    Rep Power
    260
    Quote Originally Posted by Corey View Post
    Access denied. GitHub is better
    woops forgot i set all my stuff to automatically be private when i put it up on bitbucket. id use github but bitbucket lets me do private stuff for free so i just use that instead
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #6  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    639
    Thanks given
    243
    Thanks received
    117
    Rep Power
    260
    Changes to Tags and TagBuilders
    • No more specifying when to use newlines. Newlines are now ALWAYS added BEFORE a string (+"string") when using builder syntax. I decided to go with this rather than explicitly specifying automatic newlines because it honestly makes more visual sense.
    • Because of the above change, NewlineIdentifier class (the gay ass bool wrapper) has been removed
    • One-liner tags are easier to create. Now you would use something like listItem("http://www.google.com") rather than listItem { -newlineBefore; -newlineAfter; +"http://www.google.com/" }
    • The above change was enabled by adding an initialization parameter to FullTagBuilder as well as adding a few .invoke constructors to TypedTag
    • Fixed a bug with FullTag.toString(String) putting the given string in both the tag AND making it the tagged text. oops lol.
    • Updated main post bbcode using the newer syntax. Shouldn't be able to see a difference!

    Gist link to DSL for this comment (requires updated Tags and TagBuilder which can be found at the bottom of the main post): [Only registered and activated users can see links. ]
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #7  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    639
    Thanks given
    243
    Thanks received
    117
    Rep Power
    260
    Bigger than normal update on this project. I've been working on this for a joint college project. NBX updates soon hopefully.
    One thing I did across the whole project was document a lot. It might not be the best, but some documentation is better than none.

    TagUtil
    • Tags, TagBuilders, and my BBCode example is now in its own folder, TagUtil.
    • BBCode examples also now better reflect the upgrades to the DSL
    • Updated features making the TagBuilder in to a slightly better DSL.
      • You can now specify a tag you want to wrap for every added string immediately inside the current block by using "outerTag { wrapTag = tagName }" before adding strings. Example: [Only registered and activated users can see links. ]
      • This is useful so you dont have to copy paste a tag before every line for something like a spoiler full of images, or a list full of list items.
      • 2 new unary operators for adding strings. (+) will function as normal, (!) will add the string but not wrap the string with any tags (if wrapTag is given), (-) will continue the text on the previous line with NO wrapped tag. Example: [Only registered and activated users can see links. ]
      • The line continuation (-) operator works best with tags that open but don't close, such as listItem (in BBCode, listItem ->
      • text)


    RandomUtil
    • Ths RandomUtil is very similar on the inside to my other RandomUtil, nearly identical on the outside.
    • It is more simple on the inside because I didnt butcher it with useless reflection and special boi abstraction.
    • Still gives identical (within margin of error bc random) results
    • Upgraded WeightedTable so it performs slightly better as well as is a bit more neat looking.
    • With RandomUtil, there are also extensions to primitive types and String.
    • Added MemoWeightedTable. You can use custom weights and custom items with these. They memoize the hashcodes of the custom arrays used so they perform better when used more than once.


    TextUtil
    • String.rpad and String.lpad both do ALMOST the same thing as String.padStart and String.padEnd, except they don't chop the string off at the specified length
    • String.remove removes all exact instances of the given input string and returns the new "cleaned" version
    • String.translate uses TranslationTables (also included). String.translate(TranslationTable) maps all instances of any character in the given TranslationTable's inChars to that characters outChars index match
    • You can also use TranslationTable.translateString(String) to achieve the same result
    • You can also reverse translate using String.reverseTranslate(TranslationTable) and TranslationTable.reverseTranslateString(String)


    All I did with ColourUtil was remove the initializer in DefaultColour and make DefaultColour extend Colour

    MatrixUtil
    • MatrixUtil contains Matrices for all the primitive types.
    • You can add, multiply and subtract matrices with scalars and eligible matrices. cbf to do number array inverses because I can barely do that shit on a paper (and the way I got it working in code was terribly inefficient for larger than 5x5 arrays). Boolean array inverse just inverses all the boolean values though
    • You can transpose the matrices
    • I tried to make a Generic Matrix but there was an UnsupportedOperationException related to reified type params and inlining. wtf mang
    • I am going to keep working on Generic Matrix to somehow get this dumb bitch to work, and it will support custom addition, custom subtraction, custom scalar multiplication and custom dot products. Eventually.
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  9. #8  
    Registered Member
    Join Date
    Mar 2018
    Posts
    45
    Thanks given
    15
    Thanks received
    1
    Rep Power
    12
    Quote Originally Posted by Corey View Post
    You should throw this in a github repo, nobody downloads code from a mediafire link, that's not how you share code - i.e. I want to browse the code but cant be arsed downloading a zip and manually looking at the code through an IDE/editor
    I've never in my life wanted to go through code while using git, why would you even say that? gl using search macros on git lol...
    Reply With Quote  
     

  10. #9  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!


    S Quare Quxx's Avatar
    Join Date
    Jun 2007
    Posts
    8,884
    Thanks given
    1,860
    Thanks received
    4,712
    Rep Power
    5000
    Quote Originally Posted by harley_rae_ann View Post
    I've never in my life wanted to go through code while using git, why would you even say that? gl using search macros on git lol...
    git != github... github > downloading zips



    Reply With Quote  
     

  11. Thankful users:


  12. #10  
    Registered Member
    Join Date
    Mar 2018
    Posts
    45
    Thanks given
    15
    Thanks received
    1
    Rep Power
    12
    Quote Originally Posted by S Quare Quxx View Post
    git != github... github > downloading zips
    either way im not reading code on a site webpage by webpage.
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 21
    Last Post: 12-07-2017, 09:08 AM
  2. Replies: 20
    Last Post: 10-30-2012, 10:35 PM
  3. Replies: 4
    Last Post: 05-16-2007, 07:50 AM
  4. Replies: 7
    Last Post: 05-14-2007, 08:19 PM
  5. Replies: 6
    Last Post: 05-09-2007, 12:35 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •