Thread: [KT] I wrote some misc utils that you may find useful (and wrote this post with one)

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 [KT] I wrote some misc utils that you may find useful (and wrote this post with one) 
    Super Donator

    Nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    526
    Thanks given
    200
    Thanks received
    78
    Rep Power
    148
    This was created in Kotlin 1.3, so I cannot guarantee compatability with any kotlin version released beforehand
    Hey guys, nbness here. Today, I'm writing all this whole post with a basic wrapper DSL included with the rest of this download, which will also include this post as an example in "BBCodeExample.kt"
    Spoiler for code examples:


    this is regular FF0000 text

    this red Comic Sans MS text

    this is size 6 regular text
    this is size 6 fixedsys text
    and this is size 6 blue fixedsys text

    this is a google search for: [Only registered and activated users can see links. ] using the google tag
    this is a wikipedia article on birds using the wikipedia tag: [Only registered and activated users can see links. ]
    here is some 00ff00 left-aligned text
    Here is some uncoloured centered text

    Here one sentence using right-aligned text
    Here is another sentence using right-aligned text in the same tag
    here is a link to my rune-server user page using the user tag -> nbness2
    Here is super text on thesame line as regular aswell as sub text
    Heres a real slapper of a song, im just using this video as an example of the video tag i swear to scu im not a weeb oh fuck what will my waifu say when she finds out

    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 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. BoolUtil includes
      • Alternative BoolArray (BooleanArray) that uses 1 bit per boolean rather than 1 byte, so space is saved using large boolean arrays but comes at the cost of performance.
      • BooleanArray operates identical to BooleanArray and Array<Boolean> in terms of set/get and initialization
      • this also includes a very small amount of other misc boolean-collection related functions
    2. ColourUtil includes
      • 140 default colours to pick from (parsed frrom [Only registered and activated users can see links. ]
      • )
      • You can also make your own colours if you want to, of course
    3. NumberUtil inclues:
      • converting primitive numbers to and from ByteArrays
      • Converting primitive numbers to hex
      • Checking if primitive numbers are even or odd
    4. TextUtil includes:
      • String manipulation
      • English checking functions
      • Capitalization, symbolic and numeric checking functions
    5. DelegateUtil
      • This is a flexible variable delegate that you can do quite much with, the limit is your imagination!

    Spoiler for pictures:

    Default colours

    Delegate example

    To and From ByteArray. Number's primitive subclasses (Int, Short, etc.) all have their own .toByteArray that output the same thing as Number.toByteArray, but I couldn't do the same Number.fromByteArray because Number doesn't have a companion object and it would've looked ugly as shit


    BoolArray. This stores the bool values in bits rather than bytes, so instead of 64 bytes per 64 booleans its 8 bytes per 64 booleans (uses long for boolean storage). BoolArray works identically to BooleanArray and Array<Boolean> in terms of get/set and initialization, havent gone too deep to make it copy paste-able in every case though it should be in most cases

    DSL example

    Git link: [Only registered and activated users can see links. ]
    Python Framework (soon to be revived, early 2019): [Only registered and activated users can see links. ]!
    NBX: [Only registered and activated users can see links. ]!
    My Kotlin Utils library: [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  2. #2  
    Developer

    Corey's Avatar
    Join Date
    Feb 2012
    Posts
    1,023
    Thanks given
    759
    Thanks received
    665
    Rep Power
    2569
    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. #3  
    Super Donator

    Nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    526
    Thanks given
    200
    Thanks received
    78
    Rep Power
    148
    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. ]
    Python Framework (soon to be revived, early 2019): [Only registered and activated users can see links. ]!
    NBX: [Only registered and activated users can see links. ]!
    My Kotlin Utils library: [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  4. #4  
    Developer

    Corey's Avatar
    Join Date
    Feb 2012
    Posts
    1,023
    Thanks given
    759
    Thanks received
    665
    Rep Power
    2569
    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  
     

  5. #5  
    Super Donator

    Nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    526
    Thanks given
    200
    Thanks received
    78
    Rep Power
    148
    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
    Python Framework (soon to be revived, early 2019): [Only registered and activated users can see links. ]!
    NBX: [Only registered and activated users can see links. ]!
    My Kotlin Utils library: [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  6. #6  
    Super Donator

    Nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    526
    Thanks given
    200
    Thanks received
    78
    Rep Power
    148
    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. ]
    Python Framework (soon to be revived, early 2019): [Only registered and activated users can see links. ]!
    NBX: [Only registered and activated users can see links. ]!
    My Kotlin Utils library: [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  7. #7  
    Super Donator

    Nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    526
    Thanks given
    200
    Thanks received
    78
    Rep Power
    148
    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.
    Python Framework (soon to be revived, early 2019): [Only registered and activated users can see links. ]!
    NBX: [Only registered and activated users can see links. ]!
    My Kotlin Utils library: [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Mar 2018
    Posts
    26
    Thanks given
    10
    Thanks received
    0
    Rep Power
    16
    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  
     

  9. #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,868
    Thanks given
    1,859
    Thanks received
    4,676
    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  
     

  10. Thankful users:


  11. #10  
    Registered Member
    Join Date
    Mar 2018
    Posts
    26
    Thanks given
    10
    Thanks received
    0
    Rep Power
    16
    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 2 12 LastLast

Thread Information
Users Browsing this Thread

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

Similar Threads

  1. stuff you may find useful
    By Faris in forum Snippets
    Replies: 10
    Last Post: 03-26-2013, 03:24 PM
  2. Replies: 13
    Last Post: 07-21-2011, 06:43 PM
  3. Replies: 8
    Last Post: 12-02-2010, 01:35 PM
  4. (TuT) how to change the exp that you go up!!!(TuT)
    By goldkiller in forum Tutorials
    Replies: 16
    Last Post: 05-28-2008, 01:43 PM
  5. Replies: 31
    Last Post: 12-16-2007, 08:02 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
  •