This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

H4X0RZ Stuff // Newest: RandomUtils

Started by H4X0RZ, 14 July 2015 - 02:28 PM
H4X0RZ #1
Posted 14 July 2015 - 04:28 PM
NOTE: Uploading every new project to Backspace. The new scripts will be downloaded a bit different but still with pastebin.


Event Remapper
SpoilerInstallation

pastebin get 1NDQuiPy <name>

Usage


This code is based on my old event remapper, but the code is
completely rewritten.
Just load it as an API.
  Functions:

remapper.addRemap(expected,modifier)
  expected is a table representing the event you want to remap.
	example:
	  {"mouse_click",1,2,3} <- This will remap every left mouse click
	  at 2,3.
   You can also use nil as field for an argument to "ignore" it.
	  example:
	  {"mouse_click",nil,2,3} <- This will remap EVERY mouse click
	  at 2,3.
  modifier is a function which will get the original event (as table)
  as argument. You have to return a table which represents
  the remapped event.

  remapper.removeRemap(expected)

  expected has to be the same table as used for .addRemap

remapper.pullEvent(filter)

  Replacement for os.pullEvent(filter)

remapper.inject()

  If you don't want to use remapper.pullEvent you can call
  this function to override os.pullEvent
L33t Interpreter
SpoilerInstallation

pastebin get GwY6AuTb <name>

Usage

If you want to know how to write code in l33t, you should check this page out.

Example Script


Gr34t l33tN3$$?
M3h...
iT 41n't s0 7rIckY.

l33t sP33k is U8er keWl 4nD eA5y wehn u 7hink 1t tHr0uGh.
1f u w4nn4be UB3R-l33t u d3f1n1t3lY w4nt in 0n a b4d4sS h4xX0r1ng s1tE!!! ;p
w4r3Z c0ll3cT10n2 r 7eh l3Et3r!

Qu4k3 cL4nS r 7eh bE5t tH1ng 1n teh 3nTIr3 w0rlD!!!
g4m3s wh3r3 u g3t to 5h00t ppl r 70tAl1_y w1cK1d!!
I'M teh fr4GM4stEr aN I'lL t0t41_1Ly wIpE teh phr34k1ng fL00r ***j3d1 5tYlE*** wItH y0uR h1dE!!!! L0L0L0L!
t3lEphR4gG1nG l4m3rs wit mY m8tes r34lLy k1kK$ A$$

l33t hAxX0r$ CrE4t3 u8er- k3wL 5tUff lIkE n34t pR0gR4mm1nG lAnguidGe$...
s0m3tIm3$ teh l4nGu4gES l00k jUst l1k3 rE41_ 0neS 7o mAkE ppl Th1nk th3y'r3 ju$t n0rMal lEE7 5pEEk but th3y're 5ecRetLy c0dE!!!!
n080DY unDer5tAnD$ l33t SpEaK 4p4rT fr0m j3d1!!!!!
50mE kId 0n A me$$4gEb04rD m1ghT 8E a r0xX0r1nG hAxX0r wH0 w4nT2 t0 bR34k 5tuFf, 0r mAyb3 ju5t sh0w 7eh wAy5 l33t ppl cAn 8E m0re lIkE y0d4!!! hE i5 teh u8ER!!!!
1t m1ght 8E 5omE v1rus 0r a Pl4ySt4tI0n ch34t c0dE.
1t 3v3n MiTe jUs7 s4y "H3LL0 W0RLD!!!" u ju5t cAn'T gu3s5.
tH3r3's n3v3r anY p0iNt l00KiNg sC3pT1c4l c0s th4t, be1_1Ev3 iT 0r n0t, 1s whAt th1s 1s!!!!!

5uxX0r5!!!L0L0L0L0L!!!!!!!

At first this might look just like random text, but it will actually output "H3LL0 W0RLD!!!"
Poop Interpreter
SpoilerInstallation

pastebin get dftLnXKG <name>

Usage

You should check out this page.

Example
(Hello World)

eat eat eat eat eat eat eat eat eat
eat eat eat eat eat eat eat eat
POOP
puke puke puke
poop
eat eat eat eat eat eat eat
poop
poop
eat eat eat
poop
sniff
flush
eat eat eat eat eat eat eat eat eat
eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat
POOP
puke puke puke puke puke puke puke puke
poop
eat eat eat
poop
puke puke puke puke puke puke
poop
puke puke puke puke puke puke puke puke
poop
eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat eat
poop
sniff
Some Random Image API
SpoilerInstallation

pastebin get 6MduifaD

Usage

It's hard to explain how to use this… well, here is an example script, which should show you how this works, kinda.

os.loadAPI("drawing")
local data = {}
local W,H = term.getSize()
local img

local function generate()
for y = 1,H do
data[y] = {}
for x = 1,W do
local d = {}
d[1] = 2^math.random(0,15)
d[2] = 2^math.random(0,15)
d[3] = " "
data[y][x] = d
end
end

drawing.save(data,"data")

img = drawing.load("data")
end

for i = 1,100 do
sleep(.1)
generate()
drawing.draw(img)
end

It basically allows you to store images in smaller files. But, because it ALWAYS stores a background color, a foreground color and a text character it is only smaller if you actually use these three in the original image.

You should use this with a buffer API because drawing isn't optimized at all.

Credits
Lyqyd, Lignum, InDieTasten, KingofGamesYami and Bomb Bloke

BWT
SpoilerInstallation
Spoilerpastebin get u6dXUFrV bwt

Usage
SpoilerThis API is pretty easy to use (although the name doesn't say anything about what it does unless you know what BWT is :P/>).

All it does is sort a string you give it, allowing you to apply compression algorithms more effectively on the string it outputs. (Talking about compression like LZW)

The code BWT'd itself.
Spoiler


















  
nno)))oo)oooo)d)d))]c)d}" }}d}}))))))0rd)))))))d)d)dd
d)dd)dd

d
ddddd}ddd
)dllb)ltttt



)==r===)stiiir]]dsrrds]rdrb]]]ltttbt)=nctlnnrn==rnlrs)r))))l=)v=dllllllllln=rrrvvvvcrrrr===nlnn=dtclnnnnlnn=nnllln==nln=tnntn<nllnlnnnl)))=nnlo==n=gt======g*,!."(\t [(_,[ ,,,,,[,,(/mhrb)bbrrsrttsedbbbffrtbbtrtsstrTTgrdgtystsebtfdvsbrrilbrrclrtrdsldrttsrr"1ravrld"tr)d)=)di"r@ltii#b111rsd2v.la)rrlrisffmrrlrr1kkkk{s"-r)vt.egggtttte..( 9-   (z++(12345678;rrvrvvssr, ~		=					? <0|Gtllttb]%"\k"11kkk}:
(("TTttrrr,(  ppppcccccccccccccccccccccccc  hhheeehhhhtttcmttttuuuuuuuuuuuu,(uuatttttttttttaaaaiiii "e.   .   d ddoooooooooooooooooooooooonbtdddeeeerrr. aaannnnnnnnnnnn	((((nnnnnnnnnnnnnnnnnnnnnnneeeennnneeddeeennnnnnaaaac		ddllllssssllll, ttt, (tdhhh		  



  ,hhhwwtwvtttt vvvsssmggrrrrrrrrrrrrrrlllliii(,oooe:.		fff

		nnnnnnn_  f:cCCCCCCCtttcccgt   ,,,((ssss   hnlll	 ffhrrrrrttttttttttttttttaaaammlllmlli	[[[[jibbbaaaaaaaaaaaaaaaaaaaaaaaa,b,bbbbbbbbbbbbbbb	% ,pppppoookt

			lll..uugoiiileeooooooorriiiiroorooeirrrrrrrorrouuuuuuuuuuuueeeeeeeeeeeeeeeeeeeeeeeaaiieeeEEEioiiiii m((ooooe (ddddddddllllllllllllllllllllllll  ,rrrSiiiiiiiiiiiicriiiinc  ffffffffrSSSSsssss +PP+PpppprrnnrrTTrRRrlllll	sssssttt # ,ooptouuuutoottooooooooeeeeeeetutttttetuuttttttttuttttttaaaaaa			 .tttttuuuuuuuuuuuuu   wr  #  tt(eaaiiiiaaeeeqoooooooooaaarnorrrnnrronoooorr...rfffssss"xxxx. ( ,	,oooo,(,# ##((((((#(##((((((   . rr   r   ::::::t:t( ti oio tweeoonwrrriiiWWarre(i(owwwwwot oo  sssoooo   ((#((( .arttrrcccr   eccccccccccccaaaawddrrrsssssssssssssssssssssssssSSsssee	 iieeeeeeeeeeeeessssssssssSsSssnnffffffffffffcccccccctttttttttttttt ,,,,### (  OeOOu oo bbBBbbbbbbveeeewpxy[	  >{{{{{{\+

You just have to call

bwt.BWT("Some random string.","A character that does NOT appear in the string on the left")
And it will sort your string for you.

To revert it you just do

bwt.reverseBWT("bwt'd string","same character you chose when you bwt'd the string")
and your text is reverted back to how it originally was.

OO Utility
SpoilerInstallation
Spoilerpastebin get zDf5pMsK oo
Usage
SpoilerThis API/Utility is meant to make developing object oriented programs more easily.
You just have to run the program once at startup (or at least once before your actual program is run) and the computer is set up to work with code written for this Utility.

Writing a class is pretty easy:

--@Class Test
--@Extends BaseClass
--Note that these two comments are necessary, and not just decoration.
-- @Class is the name of your class, and @Extends is the class your class extends. If you don't want to extend a specific class, you have to use BaseClass.

function Test:new()
  local n = new() -- new is a local function returning a "fresh" object of the class, only containing the methods. You still have to add the variables
  n.text = "Standard"
  return n
end

function Test:set(text) --There are two ways of defining a method. Either use the colon-notation and lua will automatically add the self argument...
  self.text = text
end

function Test.get(self) --Or use the normal dot-notation and add self yourself. (doing it this way, you can name it whatever you want.)
  return self.text
end

When we have our Test class, we now can work with it:

dofile("path/to/utility")
import("path/to/class")

local test1 = Test:new()
local test2 = Test:new()

test1:set("This is a test")
test2:set("This is another test")

print(test1:get())
print(test2:get())

This utility also overwrites the type function, returning the class name when you give it a class, and an extendsFrom function is added, allowing you to easily check if an object's class extends an other class.

extendsFrom(test1,"BaseClass") --> true
extendsFrom(BaseClass,"Test") --> false
This allows you to, for example, only accept a special type of objects (only the objects extending from "Button" for example).

//Note: I*m kinda tired from formatting this thread. It really hurts when doing a simple mistake while changing the font size and that kind of stuff (it basically jumps between sentences etc.) going to just post the scripts without special font sizes.

RandomUtilities
SpoilerInstallation

Normal version
pastebin run PmBrnNG5 utilities-full

Minified version
pastebin run PmBrnNG5 utilities-full-min

What is this stuff?
This project is heavily inspired by Moses. I basically copied some function names and ideas but the code is all made by me.

The source can be found here. This API is built with Howl. It is separated into three modules (right now. "Core" doesn't count because it's ALLWAYS included in the built). "Table", "Array", and "CC" (which doesn't contain anything right now). When building you have to define which parts you want included using flags.

You want to add a new module or you have additions for an existing one? Just send me a pull-request!

How to use it?

(You have to use dofile to load this API)
Once ran you can find a global table _ which holds all the functions.

Because this utility is quiet large (right now it has 66 functions. IIRC) It could take some time for the full documentation to be up. I'm tired right now so I'll just dump every function available.

Core
Spoiler

--A list of every function
_.isEqual(obj1,obj2)
_.toBoolean(obj)
_.isCallable(obj)
_.isTable(obj)
_.isNil(obj)
_.isArray(obj)
_.isIterable(obj)
_.isString(obj)
_.isEmpty(obj)
_.isNumber(obj)
_.isNaN(obj)
_.isFinite(obj)
_.isBoolean(obj)
_.isInteger(obj)
_.once(func)
_.functions(obj)
_.clone(obj)
_.result(obj,method,...)
_.memoize(func,hash)
_.after(func,count)
_.compose(...)
_pipe(value,...)
_.times(num,func,...)
_.bind(func,value)
_.bindn(func,...)
_.tap(value,func,...)

Array
Spoiler

--also a function dump
_.toArray(...)
_.find(array,value,start)
_.reverse(array)
_.selectWhile(array,func,...)
_.dropWhile(array,func,...)
_.indexOf(array,value)
_.lastIndexOf(array,value)
_.push(array,...)
_.pop(array)
_.unshift(array)
_.pull(array,...)
_.removeRange(array,start,finish)
_.slice(array,start,finish)
_.first(array,n)
_.initial(array,n)
_.last(array,n)
_.nth(array,n)
_.difference(array,array2)
_.union(...)
_.unique(array)
_.isunique(array)
_.append(array,obj)
_.range(start,finish,increment)
_.rep(value,n)
_.concat(array,str)
_.split(str,pat)

Table
Spoiler

--And yet another function dump
_.each(table,func,...)
_.at(table,...)
_.count(table,value)
_.cycle(table,n)
_.map(table,func)
_.reduce(table,func)
_.mapReduce(table,func)
_.detect(table,value)
_.all(table,func)

Also there is one extra thing I really like. It's chaining.

_.chain(
  _.toArray("This","is","a","test")
  )
  .map(function(k,v)
	return key%2==0 and value:upper() or value
  end)
  .reduce(function(m,v)
	return m.." "..v
  end)
  .tap(print)
This will output

this IS a TEST

#EDIT: Yay \o/ this is my 700th post!
Edited on 26 October 2015 - 06:24 PM
H4X0RZ #2
Posted 24 July 2015 - 02:07 AM
I got some updates on this:
First: i thought the updater would help me with developing this, but at the end it just became a nightmare to work with it, so I decided to just upload everything to pastebin. (I don't think anyone cares about this :P/>/&amp;gt;)

Now, something I'm a bit proud of: I finished my l33t interpreter, which you can find in the OP.
It's nothing special, but It's my first (eso)lang I "ported" to CC. More esolangs will follow, because I really like them :3
Edited on 24 July 2015 - 12:42 AM
H4X0RZ #3
Posted 25 July 2015 - 07:45 AM
Another update:

I added the Poop Interpreter to the list.
H4X0RZ #4
Posted 11 August 2015 - 04:21 PM
Added my Image API
H4X0RZ #5
Posted 21 August 2015 - 10:49 PM
Added BWT and my OO Utility
H4X0RZ #6
Posted 26 October 2015 - 07:18 PM
Added RandomUtils
Creator #7
Posted 27 October 2015 - 04:13 PM
This is just a bunch a replies to yourself. Else, I like the poop interpreter.
H4X0RZ #8
Posted 27 October 2015 - 04:31 PM
This is just a bunch a replies to yourself. Else, I like the poop interpreter.
Yep. Maybe nobody cares about my stuff :D/>

Thanks!
Creator #9
Posted 27 October 2015 - 04:32 PM
Maybe they are so perfect nobody feel the need to respond?
H4X0RZ #10
Posted 27 October 2015 - 09:16 PM
Maybe they are so perfect nobody feel the need to respond?

+1

That joke really made my day. XD
Creator #11
Posted 27 October 2015 - 09:27 PM
Who said its a joke?