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
|
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: NBX
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.
- 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 andString
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.
- BoolUtil includes
- Space-minded alternative to
BooleanArrarray
,DenseBoolList
. Uses 1 bit perBoolean
but identical operation.- API-level copy/replace with
BooleanArray
,List<Boolean>
andArray<Boolean>
MutableDenseBoolList
is a space-minded alternative toMutableList<Boolean>
- Destructuring
Number
toBoolean
. Ex:val (bool1, bool2, bool3) = longValue // Long can have up to 64 destructured values
- 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
- StringUtil includes:
- String manipulation
- String translation to\from user given translation tables
- English checking functions
- Capitalization, symbolic and numeric checking functions
- TagUtil
- Create your own tag language and write it directly in your IDE
- DelegateUtil
- Minimize custom setter/getter boilerplate with variable delegates!
- ColorUtil
- Convert to and from RGB, CMYK, HSL and HSV color formats!
Link: https://bitbucket.org/nbutil/
Spoiler for old link:
Last edited by nbness2; 06-12-2019 at 12:59 PM. Reason: Added ColorUtil
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.
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): https://gist.github.com/nbness2/f0fc...3670b6b84f8ac0
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: https://i.imgur.com/avRaZK0.png
- 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: https://i.imgur.com/xIgXweI.png
- 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.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |
Tags for this Thread |