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

[API] QuickTils [v4.1] Programs made quicker and easier!

Started by Dave-ee Jones, 10 May 2013 - 10:02 PM
Dave-ee Jones #1
Posted 11 May 2013 - 12:02 AM
QuickTils

v4.1



NOTE: Do not re-post as your own! Please PM me for allowance to change/modify functions and re-post as your own.


What is this API used for?
Well, this API is used for many different things. It has an in-built login system that you can easily setup yourself, it has very simple functions to help your GUI look better and many more useful things!

What is the full list of functions?
Here they are:

clean(x,y)
cursor(x,y)
color(color)
bColor(color)
skipLine(lines)
cPrint(string)
cWrite(string)
printCentered(string)
writeCentered(string)
existsFile(file)
writeFile(file,string)
pbGet(code,filename)
pbAdd(filename)
loginUser(textCol1,textCol2)
createUser(textCol1,textCol2,charTable)
fetchUserDetails(user,pass)
modifyUser(textCol1,textCol2)
removeUser(textCol1,textCol2)


Why don't you just download it and have a look at what it can do yourself?

CHANGELOG
Spoilerv 4.1:

Bug update for version 4!

- Fixed a few minor bugs
- Fixed pBGet and pBAdd


V 4:

New update!

- Re-wrote pBGet and pBAdd functions (please report any bugs to me)
- Made some minor adjustments
- Added 'svdragster' to the comments section

V 3.7:

New Update!

- Added function bColor (backgroundColor)
- Fixed pBGet function

V 3.62:

Bug fixes for v3.61!

- Fixed even more bugs in the clean function!

V 3.61:

Bug fixes for v3.6!

- Fixes bugs on the clean function

V 3.6:

Updates on the not-so-new in-built login system and the clean function!

- Made a code generator for the account creation (see for yourself)
- You can now set the cursor position when calling the clean function
- Other small changes that I cannot remember


V 3.5:

Updates on the new in-built login system!

- Renamed the function inputUser to loginUser
- Minor changes to the login GUI
- Made the function printCentered more centered


V 3.31:

Updates on the new in-built login system!

- Fixed some minor bugs with the modifyUser function
- Other small glitches and bugs


Downloads:

V 4.1:
Spoilerpastebin get Ur9tN2Ct QuickTils

V 4:
Spoilerpastebin get sXYiT99P QuickTils

V 3.7:
Spoilerpastebin get 1uRnjRMj QuickTils

V 3.61:
Spoilerpastebin get EHDvktDw QuickTils

V 3.6:
Spoilerpastebin get H5e6vAGt QuickTils

V 3.5:
Spoilerpastebin get sbjru7AR QuickTils

V 3.31:
Spoilerpastebin get fmPHWSbE QuickTils

V 3.3:
Spoilerpastebin get WXjtARrd QuickTils

V 3:
Spoilerpastebin get jyws6muJ QuickTils

V 2.3:
Spoilerpastebin get hHrAzh56 QuickTils

V 2.1:
Spoilerpastebin get fZWu3ux1 QuickTils

V 2:
Spoilerpastebin get xJnhyWZj QuickTils


Credit where it's due
Spoilersvdragster - for his help with HTTP functions (give this guy a raise!)

Suggestions List
Spoiler- Encryption/Decryption functions
- Create-a-menu functions
- String Utility functions
- Create-a-button functions
svdragster #2
Posted 11 May 2013 - 11:11 AM
For skipLine you could do

function skipLine(lines)
  local x, y = term.getCursorPos()
  term.setCursorPos(x, y+lines)
end
Dave-ee Jones #3
Posted 12 May 2013 - 06:17 PM
That's a pretty good idea actually…Thanks. Saves time and my fingers.
Dave-ee Jones #4
Posted 12 June 2013 - 06:43 AM
New update! This one fixes some GUI in the login system and fixes the printCentered function (wasn't entirely centered) and also fixed the removeUser function's colors.

Happy coding!
theoriginalbit #5
Posted 12 June 2013 - 06:59 AM
Your centered print/write functions are confusing me a little, why are you picking the max number between the `centered` position and the current cursors y position? o.O
This is how I would be inclined to do the functions:

function writeCentered(text, y) --# allowing the person to set the y position is helpful
  local w, h = term.getSize() --# the variables should be localized
  local _, cy = term.getCursorPos() --# the variables should be localized
  local xPos = math.floor((sw-#text)/2) + (#text % 2 == 0 and 1 or 0) --# calculate the center, and shift it when the text length is even an length as it looks better in the shifted position
  term.setCursorPos(xPos, y or cy)
  write(text)
end

function printCentered(text, y)
  --# why reinvent the wheel, we have a function that does this already, so just pass the string to that one with a new line character appended
  writeCentered(text..'\n', y)
end

Also I would suggest in your function `pbGet` instead of returning true, return the existence of the file, the pastebin program does not always succeed. So something like this would be better:

function pbGet(code, filename)
  if not fs.exists(filename) then
	shell.run("pastebin get "..code.." "..filename)
	return fs.exists(filename)
  end
  return false
end
Dave-ee Jones #6
Posted 15 June 2013 - 06:57 AM
Sorry the updates are coming slow, I havent had much time to work on it lately, with homework and all, but I'll do my best.

@theoriginalbit

The one I use works, and as long as it works and it is useful it can be used as a function. I don't understand why the y variable needs to be defined when you call the writeCentered/printCentered function, as this one works fine. The only problem was that it was 1 character bigger on one of the sides so I had to add a +1 on the x variable. It is also longer doing it the way you have done, and there is no benefit in making it longer apart from defining the y position, which is already done. You can just set the cursor before calling this function as well.
Dave-ee Jones #7
Posted 19 June 2013 - 04:07 AM
Sorry about the bugs in 3.6, I forgot to re-write the API's functions.
svdragster #8
Posted 29 June 2013 - 09:48 AM
Another tip, your pastebin codes aren't really safe. Someone could just write a virus and call it pastebin, and the api starts the virus!
If you want to make it safer, use the pastebin api and the http api :)/>
Dave-ee Jones #9
Posted 30 June 2013 - 12:51 AM
Another tip, your pastebin codes aren't really safe. Someone could just write a virus and call it pastebin, and the api starts the virus!
If you want to make it safer, use the pastebin api and the http api :)/>

What do you mean exactly?
svdragster #10
Posted 30 June 2013 - 06:27 AM
Instead of

shell.run("pastebin post "..file)
Use the Http.post and the "creating a paste" api.
Dave-ee Jones #11
Posted 01 July 2013 - 03:11 AM
I get you now! I was going to do that soon but I keep forgetting how to do it…
Don't you do something like this?

local variable = http.get("http://www.pastebin.com/"..code)
local variableContent = variable.readAll()
local file = fs.open(<filename>,"w")
file.write(variableContent)

(pBGet function)
svdragster #12
Posted 01 July 2013 - 01:02 PM
local variable = http.get("http://pastebin.com/raw.php?i="..code)
Dave-ee Jones #13
Posted 02 July 2013 - 04:16 AM
Ok thanks. So, with the pbAdd function would I use the API? How would you do it?


P.S Any more suggestions? :P/>
svdragster #14
Posted 02 July 2013 - 11:48 AM
I could give you the code, but that would be boring :3
You can look inside of the pastebin program on everyone computer at line 21 ;)/>
Dave-ee Jones #15
Posted 02 July 2013 - 06:03 PM
Yeah I did that yesterday (looked at the Pastebin put function) and didn't get much out of it…

Btw I tried my pBGet and it came up with the HTML code…Which is what I don't want.
svdragster #16
Posted 03 July 2013 - 01:14 PM
You need the

pastebin.com/raw.php?i=
or it will give you the html stuff.

Alright, for the putting:
You have to make a http.post to the url "http://pastebin.com/api/api_post.php".
But you have to add some stuff so pastebin will know what to post on pastebin.
The required parameters are on the website:
Creating A New Paste, [Required Parameters]
Include all the following POST parameters when you request the URL:

1. api_dev_key - which is your unique API Developers Key.
2. api_option - set as 'paste', this will indicate you want to create a new paste.

3. api_paste_code - this is the text that will be written inside your paste.

The parameters in lua:

local parameters = (
"api_dev_key="..key.."&amp;".. -- The key is "0ec2eb25b6166c0c27a394ae118ad829"
"api_option=paste&amp;"..
"api_paste_name="..text -- Text to put on pastebin.
)

Pastebin will respond the link, so if you want to get it, you need to do

local response = http.post(putUrl, parameters)

the parameters also could look like this:

parameters = "api_dev_key="..key.."&amp;".."api_option=paste&amp;api_paste_name="..text
Dave-ee Jones #17
Posted 04 July 2013 - 03:20 AM
Ok..cool. I got some of it but the rest was a bit weird to me…The pBGet function is easy though. :)/> Thanks.

EDIT: Speaking of which, I should go update QuickTils. Expect to see both the pB functions fixed…well, the pBGet one at least :)/>