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

Jesusthekiller's Programs || Guess the number minigame | Random string generator | cPrint | WCON

Started by jesusthekiller, 19 April 2013 - 07:24 AM
jesusthekiller #1
Posted 19 April 2013 - 09:24 AM







This thread is not being updated! For accurate info go to my website (link at the top).



APIs section:

cPrint - Adds color codes!

Spoiler

cPrint

No more term.setTextColor()!


What is it?
cPrint is an API which was originally created as past of uGUI for my OS, but it is powerful enough to be an standalone tool.

It allows to change text and background colors inside of a string - like Minecraft's color codes!

How to use it?

Color coding:
To set text color: "&amp;<color-code>"
To set background color: "$<color-code>"
To print "$" sign: Normal string: "\\$", Square bracket string: [[\$]]
To print "&amp;" sign: Normal string: "\\&amp;", Square bracket string: [[\&amp;]]

Functions:
cprint.cprint(string)
Prints color parsed string.
Returns: nothing

cprint.cwrite(string)
Prints color parsed string.
Returns: nothing

cprint.update()
Updates cPrint and palette
Returns: true on update, false on no update.

cprint.toCode(int)
Changes int to it's string-hexadecimal form.
Returns: string

cprint.cCode(string)
Turns color code to color
Returns: int

cprint.clear([bool])
Clears terminal and if bool is not equal to false (or unset) sets cursor pos to 1, 1

cprint.sb(int)
Wrapper for term.setBackgroundColor()

cprint.st(int)
Wrapper for term.setTextColor()

cprint.sc(int, int)
Wrapper for term.setCursorPos()

Colors:


	if code == "0" then return colors.white end
	if code == "1" then return colors.orange end
	if code == "2" then return colors.magenta end
	if code == "3" then return colors.lightBlue end
	if code == "4" then return colors.yellow end
	if code == "5" then return colors.lime end
	if code == "6" then return colors.pink end
	if code == "7" then return colors.gray  end
	if code == "8" then return colors.lightGray end
	if code == "9" then return colors.cyan end
	if code == "a" then return colors.purple end
	if code == "b" then return colors.blue end
	if code == "c" then return colors.brown end
	if code == "d" then return colors.green end
	if code == "e" then return colors.red end
	if code == "f" then return colors.black end


@up If you can't read it, it means you probably should look at the screenshot below :P/>

Versions:
SpoilercPrint:

--[[
	Version log:
	1.0:
	 * Initial release
	
	1.1:
	 * Added cwrite
	 * Added update
	 * cprint now adds "\n" to the end of the line
	 * Improved cCode
	 * Improved toCode
	 * Auto updater
	
	1.2:
	 * Added non-advanced computer support
	 * Bugfixes

	1.3:
	 * Even better non-advanced computer support
	]]--

Palette:

--[[
	Version log:
	1.0:
	 * Initial release
	
	1.1:
	 * Ported to cPrint 1.1
]]--

Screenshot (animated, woo!):

From demo app (palette):


Download:
Pastebin:
  • cPrint: pastebin get 2sxYu2Mq cprint
  • Palette (demo app): pastebin get Q6vtbpf6 palette
Code:
  • cPrint:
Spoiler
-- Do auto update?
local auto = true

--[[
	###INFO###
	* Language
	   Lua (ComputerCraft)
	  
	* Version
	   1.3
	  
	* Status
	   Working, not closed.
]]--

--[[
	cPrint API by Jesusthekiller
	This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
	More info: http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
]]--

--[[
	Big thanks to theorginalbit for help with cCode and toCode!
]]--

--[[
	Version log:
	1.0:
	 * Initial release
	
	1.1:
	 * Added cwrite
	 * Added update
	 * cprint now adds "\n" to the end of the line
	 * Improved cCode
	 * Improved toCode
	 * Auto updater
	
	1.2:
	 * Added non-advanced computer support
	 * Bugfixes

	1.3:
	 * Even better non-advanced computer support
]]--

local DO_NOT_TOUCH = 5

-- Updater func:

function update()
	if not http then
		error("HTTP API required!")
	end
	
	cprint("&amp;5Checking for &amp;4cprint &amp;5update...")
	
	local v = http.get("http://mindblow.no-ip.org/code/cprint/ver")
	
	if v == nil then
		error("nil response from update server! Check your internet connection!")
	end
	
	if tonumber(v.readLine()) <= DO_NOT_TOUCH then
		cprint("&amp;5No new updates!")
		return false
	end
	
	-- Install cPrint
	
	cprint("&amp;5Downloading &amp;4cPrint&amp;5...")
	
	local f = http.get(v.readLine())
	
	cprint("&amp;5Installing &amp;4cPrint&amp;5 as &amp;4cprint &amp;5in main directory...")
	
	local e = fs.open("cprint", "w") -- API Folder
	
	e.write(f.readAll())
	
	e.close()
	f.close()
	
	-- Install palette
	
	cprint("&amp;5Downloading &amp;4Palette&amp;5...")
	
	local f = http.get(v.readLine())
	
	v.close()
	
	cprint("&amp;5Installing &amp;4Palette&amp;5 as &amp;4palette &amp;5in main directory...")
	
	local e = fs.open("palette", "w") -- API Folder
	
	e.write(f.readAll())
	
	e.close()
	f.close()
	
	v.close()
	print("Done!")
	return true
end

function sc(x, y)
	term.setCursorPos(x, y)
end

function clear(move)
	sb(colors.black)
	term.clear()
	if move ~= false then sc(1,1) end
end

function sb(color)
	term.setBackgroundColor(color)
end

function st(color)
	term.setTextColor(color)
end

function cCode(h)
	if term.isColor() and term.isColor then
		return 2 ^ (tonumber(h, 16) or 0)
	else
		if h == "f" then
			return colors.black
		else
			return colors.white
		end
	end
end

function toCode(n)
	return string.format('%x', n)
end

function cwrite(text)
	text = tostring(text)
	
	local i = 0
	while true  do
		i = i + 1
		if i > #text then break end
		
		local c = text:sub(i, i)

		if c == "\\" then
			if text:sub(i+1, i+1) == "&amp;" then
				write("&amp;")
				i = i + 1
			elseif text:sub(i+1, i+1) == "$" then
				write("$")
				i = i + 1
			else
				write(c)
			end
		elseif c == "&amp;" then
			st(cCode(text:sub(i+1, i+1)))
			i = i + 1
		elseif c == "$" then
			sb(cCode(text:sub(i+1, i+1)))
			i = i + 1
		else
			write(c)
		end
	end
	
	return
end

function cprint(text)
	return cwrite(tostring(text).."\n")
end

if auto then update() end
  • Palette (demo app)
Spoiler
--[[
	###INFO###
	* Language
	   Lua (ComputerCraft)
	  
	* Version
	   1.1
	  
	* Status
	   Working, not closed.
]]--

--[[
	Palette program by Jesusthekiller
	This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
	More info: http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
]]--

--[[
	Version log:
	1.0:
	 * Initial release
	
	1.1:
	 * Ported to cPrint 1.1
]]--

if not fs.exists('cprint') then
	error('No cprint API in main directory')
end

os.unloadAPI('cprint')
os.loadAPI('cprint')

cprint.clear()
cprint.cwrite([[
$0&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;f	 $00$11$22$33
$1&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;f	 $44$55$66$77
$2&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;f	 $88$99$aa$bb$f   &amp;0 <-- All codes (&amp;716&amp;0)
$3&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;f	 $cc$dd$ee$f&amp;7f
$4&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$5&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;0	 Text color:	   \&amp;<code>
$6&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;0	 Background color: \$<code>
$7&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$8&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$9&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$a&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$b&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff$f&amp;0	 <-- All combinations (&amp;7256&amp;0)
$c&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$d&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$e&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$f&amp;00&amp;11&amp;22&amp;33&amp;44&amp;55&amp;66&amp;77&amp;88&amp;99&amp;aa&amp;bb&amp;cc&amp;dd&amp;ee&amp;ff
$f&amp;0\\&amp; = \&amp;, \\$ = \$   $f&amp;0+-- Animation with cPrint (&amp;710 FPS&amp;0)
&amp;7Press &amp;eQ &amp;7to exit. $f&amp;0V]])

local function wait()
	local e, k = nil
	while k ~= "q" do
		e, k = os.pullEvent("char")
	end
end

local function cols()
	local x, y = term.getSize()
	while true do
		for i = 0, 14 do
			cprint.sc(1, y)
			cprint.cwrite("$"..cprint.toCode(i).."&amp;f			  cPrint by Jesusthekiller			 ")
			sleep(0.1)
		end
	end
end

parallel.waitForAny(wait, cols)

License:
SpoilerTHIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Copy of this license.


WCON - Control computers over the internet!

Spoiler

WCON

Control your computers over the Internet!




What is it?:

WCON is an API (but not only) which allows you to download and upload data to WCON server.

You have 6 boolean registers (for redstone states) and 5 string registers (up to 5119 characters).

You can change all registers from in-game computer or from online control panel.

Note: HTTP API required.

How to get started?:

Get your software on your computer:
  1. Run "pastebin get jQLjRUnt install"
  2. Run "install"
Test it:
  1. Hook up some redstone or lamps
  2. Run "launch" in main directory.
  3. Login into control panel.
  4. Change redstone states and see what happens!
Changelog:
SpoilerVersion 2:
  • Added auto updater
  • Changed how stuff is located
  • Added getVersion() function
  • BETTER INSTALLER! YAAAY
Version 1.1:
  • Better password hashing on server side.
Version 1.0:
  • Initial release

API reference:
SpoilersendData(string state, int registry):

Sets given string registry to state.

Returns false at wrong registry, nil at communication error, true at success.

sendRsData(bool state, string side):

Sets given redstone registry to state.

Returns false at wrong side string, nil at communication error, true at success.

getData():

Gets string registers table.

Returns:
nil at server communication error,
"fatal: [ERROR CODE]" at WCON_FATAL_ERROR,
table (5 element, 1 to 5) at success.

getRsData():

Gets redstone registers table.

Returns:
nil at server communication error,
"fatal: [ERROR CODE]" at WCON_FATAL_ERROR,
table (6 element, 1 to 6) at success.

Each element in table corresponds to one side:
1 = top
2 = bottom
3 = right
4 = left
5 = back
6 = front

getSide(int side):

Converts side in int into side in string.

getServer():

Returns server address.

getId():

Returns ID.

getPassword():

Returns password.

getVersion():

Returns Version.

About security:
SpoilerPasswords are encrypted with SHA-256, than encrypted with SHA-256 again. It means it's basically impossible to crack password. It also means that no one can see passwords, even me.
They are stored in MySQL Database (with randomly generated password), which allows only localhost connections, not in a plain text file.

Screenshots (control pannel):
SpoilerHomepage:


Login:


Control panel:


Register:


Registration complete:

Legal notice:
SpoilerTHIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Copy of this license.




Programs section:


Debugging (Inactive for now):

Spoiler


Debugging

Debug your apps like a boss


I've quickly wrote this app after seeing this thread - I've thought this idea can be developed a bit more :)/>


What is does:
It basically logs apps and saves it to "debug_files/<app name>.log".

How to use:
	Usage:
	- debug run <program full path> [args]
	  Logs are saves in debug_files/<program name>.log
	- debug log <program name>
	  Prints a log
	- debug restore
	  Use if program was terminated or to manually restore write &amp; print functions

Where to get it:
  1. pastebin get 9YSN2Mht debug
  2. Code:
Spoiler

local args = {...}

--[[
	Backup for old functions
]]--

local fOld = {
	term = {
		write = term.write,
		clear = term.clear,
		setCursorPos = term.setCursorPos,
		clearLine = term.clearLine,
	},
	print = print,
	write = write,
	read = read,
}


local function addlog(t, i)
	if i == false then fLog.write(t)
	else fLog.write(t.."\n") end
	fLog.flush()
end

local function openlog()
	fLog = fs.open(debug_path, "w") -- Global...
end

local function closelog()
	fLog.close()
	fLog = nil
end

local function restore()
	term.write = fOld.term.write
	term.clear = fOld.term.clear
	term.setCursorPos = fOld.term.setCursorPos
	term.clearLine = fOld.term.clearLine
	print = fOld.print
	write = fOld.write
	closelog()
	debug_path = nil
	fs.delete("debug_files/.launch")
	print("\n\n\nDebbuging finished!")
end

local function mkfunc()
	-- Open log
	openlog()
	
	--[[
		All global override functions go here.
	]]--
	function term.writeNew(t)
		addlog(t)
		return fOld.term.write(t)
	end
	
	term.write = term.writeNew
	
	function read(t)
		term.write = fOld.term.write
		
		local r
		
		if t == nil then
			r = fOld.read()
		else
			r = fOld.read(t)
		end
		
		term.write = term.writeNew
		addlog("[read("..tostring(t)..") = "..tostring(r).."]")
		return r
	end
	
	function print(t)
		local r = fOld.print(t)
		addlog("[print("..tostring(t)..") = "..tostring(r).."]")
		return r
	end
	
	function write(t)
		local r = fOld.write(t)
		addlog("[write("..tostring(t)..") = "..tostring(r).."]")
		return r
	end
	
	function term.clear()
		local r = fOld.term.clear()
		addlog("[term.clear() = "..tostring(r).."]")
		return r
	end
	
	function term.setCursorPos(a, B)/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>
		local r = fOld.term.setCursorPos(a, B)/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>
		addlog("[term.setCursorPos("..tostring(a)..", "..tostring(B)/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>/>..") = "..tostring(r).."]")
		return r
	end
	
	function term.clearLine()
		local r = fOld.term.clearLine()
		addlog("[term.clearLine() = "..tostring(r).."]")
		return r
	end
end


if args[1] == "run" then
	debug_path = "debug_files/"..args[2]..".log" --Globalize args[2]
	
	term.clear()
	term.setCursorPos(1, 1)
	print("Debugging "..args[2]..".\n\nDo not terminate program, if you do, run \"debug restore\" to restore functions.\n\nPress any key to continue")
	
	local e = nil
	while(e ~= "char") do e = os.pullEvent("char") end --Wait for key
	
	term.clear()
	term.setCursorPos(1, 1)
	
	if(not fs.exists("debug_files")) then fs.makeDir("debug_files") end -- Check &amp; make "debug" dir
	
	mkfunc()
	
	local l = fs.open("debug_files/.launch", "w") -- Open temp launch file
	local s = "shell.run(\""..args[2].."\""-- Temp string
	
	for i = 3, #args do
		s = s..", \""..args[i].."\""
	end
	
	s = s..")"
	
	l.write(s)
	l.close()
	
	shell.run("debug_files/.launch") --Run app
	
	restore() -- Restore old functions
	return
end

if args[1] == "log" then
	if(not fs.exists("debug_files/"..args[2]..".log")) then print("No such file!") return end
	local f = fs.open("debug_files/"..args[2]..".log", "r") -- Open and print
	print(f.readAll())
	f.close()
	return
end

if args[1] == "restore" then
	restore() -- Restore
	return
end

print([[
	Usage:
	- debug run <program full path> [args]
	  Logs are saves in debug_files/<program name>.log
	- debug log <program name>
	  Prints a log
	- debug restore
	  Use if program was terminated or to manually restore write &amp; print functions
	  
	Debug by jesysthekiller, idea from urielsalis
	Version 1.1
]])
Changelog:
Spoiler
  • 1.0: Initial release
  • 1.1: Logging part of term.*, read, write, print


License:
SpoilerTHIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Copy of this license.





Code snippets:


Spoiler


Random string generator:

function makeString(l)
		if l < 1 then return nil end -- Check for l < 1
		local s = "" -- Start string
		for i = 1, l do
				s = s .. string.char(math.random(32, 126)) -- Generate random number from 32 to 126, turn it into character and add to string
		end
		return s -- Return string
end

Guess the number (game):


print("Guess the number! (1 - 100)")
local num = math.random(1, 100), g
while true do
  local g = tonumber(read())
  if type(g) == "number" then
	if g > num then print("Incorrect! Number is smaller") elseif g < num then print("Incorrect! Number is bigger") elseif g == num then break end
  else
	print("This is not a number!")
  end
end
print("Congratulations!")

Recursive list of all variables in _G


local f = fs.open("o", "w")

local function q(t, a) – Make list of table t with prefix a in file
for k, v in pairs(t) do
f.writeLine(a.."."..k..": "..type(v)) – Write to file
f.flush() – Flush it

if type(v) == "number" then
f.writeLine(" "..v) – Write number's value to file
elseif type(v) == "table" and k ~= "_G" then
q(v, a.."."..k) – Call itself if it's table and it's not _G
end
end
end

q(_G, "_G")

f.close()

print("Saved to file 'o'")








Tutorials:


Upcomming:
  • Pacman - Package manager for Computer Craft. Website
  • linuxOS - Goal: Bring linux experience to CC!
remiX #2
Posted 19 April 2013 - 10:22 AM
cPrint api is really useful. Nice work :)/>
jesusthekiller #3
Posted 19 April 2013 - 10:23 PM
I'm glad you like it :)/>
theoriginalbit #4
Posted 19 April 2013 - 10:27 PM
Nice. :)/> Seems everyone is going to the 'all-in-one' posts now :)/>

here is what I said about cPrint in its thread
Spoiler
Looks very nice! I have just 2 improvements…

here is an improvement to your cCode function

function cCode(h)
  return 2 ^ tonumber(h, 16)
end

and your toCode, could become

function toCode(n)
  return string.format('%x', n)
end
jesusthekiller #5
Posted 20 April 2013 - 06:07 AM
cPrint update!
  • Added cwrite
  • Added update
  • cprint now adds "\n" to the end of the line
  • Improved cCode
  • Improved toCode
  • Auto updater


You can disable auto updates check by changing 2nd cPrint line from
local auto = true
to
local auto = false


Massive thanks to theoriginalbit for help with cCode and toCode :D/>
theoriginalbit #6
Posted 20 April 2013 - 06:20 AM
Massive thanks to theoriginalbit for help with cCode and toCode :D/>
No problems :)/>
Oh I forgot to mention that if you wanted the cCode to default to white if the input was invalid just make it this

function cCode(h)
  return 2 ^ (tonumber(h, 16) or 0)
end
that way if tonumber returns nil it will default to 0 … 2 ^ 0 = 1 and 1 is colours.white…
jesusthekiller #7
Posted 20 April 2013 - 06:22 AM
-snip-
Oh I forgot to mention that if you wanted the cCode to default to white if the input was invalid just make it this

function cCode(h)
  return 2 ^ (tonumber(h, 16) or 0)
end
that way if tonumber returns nil it will default to 0 … 2 ^ 0 = 1 and 1 is colours.white…

It was my fail fuse left from testing. This will be included in next update tho :)/>
jesusthekiller #8
Posted 21 April 2013 - 04:50 AM
cPrint update!
  • Support for non-advanced computers
  • Bugfixes
theoriginalbit #9
Posted 21 April 2013 - 04:54 AM
Support for non-advanced computers
Where exactly? I was expecting to see

if term.isColor and term.isColor() then
 -- change text and bg colour here
end
jesusthekiller #10
Posted 21 April 2013 - 09:05 AM
-snip-
Where exactly? I was expecting to see

if term.isColor and term.isColor() then
-- change text and bg colour here
end

If color code ~= black then
  write as white
else
  write as black
end

;)/>
Orwell #11
Posted 22 April 2013 - 12:45 AM
I have to warn you that your wcon interface is vulnerable to sql injection. Another guy told you the same in the previous thread and you simply answered that it wasn't true. :P/> But it is… I can PM you the details if you like.
jesusthekiller #12
Posted 22 April 2013 - 12:53 AM
Duh, I'm too lazy to recode it…

Ok, I will.




*epic rage* DAMN YOU NOT WORKING NETBEANS!
Orwell #13
Posted 22 April 2013 - 01:14 AM
Duh, I'm too lazy to recode it…

Ok, I will.




*epic rage* DAMN YOU NOT WORKING NETBEANS!

Yeah, you should indeed. :P/> Passwords are rather useless if one can control any computer without them.
jesusthekiller #14
Posted 22 April 2013 - 01:24 AM
Yeah. My MySQLi just broke.
I need MySQLi with MySQLnd driver.
I hate this world.


I love world again :D/>
Got MySQLnd!
Espen #15
Posted 22 April 2013 - 02:46 AM
Support for non-advanced computers
Where exactly? I was expecting to see

if term.isColor and term.isColor() then
-- change text and bg colour here
end
Yeah, that's not necessarily needed for non-advanced computers, since they do have isColor() and it just returns false.
You only need to check for the existence of isColor if you're running the program on an older version of CC which didn't yet have advanced computers.

So strictly speaking, it'll not be compatible with older versions of CC, but the claimed "Support for non-advanced computers" is fullfilled. ^_^/>
jesusthekiller #16
Posted 22 April 2013 - 02:50 AM
Repaired SQL-Injection hole in WCON.


Whoever made "Ahoj" at their reg1 in WCON - You've made my day ;)/>
theoriginalbit #17
Posted 22 April 2013 - 02:50 AM
Yeah, that's not necessarily needed for non-advanced computers, since they do have isColor() and it just returns false.
You only need to check for the existence of isColor if you're running the program on an older version of CC which didn't yet have advanced computers.
Yeh its habit for me to type it that way, and its not like it would do any harm checking that anyway. Just printing the text without the colour formatters on a pre1.4 computer.

EDIT: Ahh found why I was so confused… the pastebin is still 1.1 not 1.2 … update your pastebin :P/>
Edited on 22 April 2013 - 12:53 AM
jesusthekiller #18
Posted 22 April 2013 - 02:56 AM
-snip-
EDIT: Ahh found why I was so confused… the pastebin is still 1.1 not 1.2 … update your pastebin :P/>

Oh, I've updated it, but I have not saved it :P/>
Espen #19
Posted 22 April 2013 - 02:56 AM
Yeh its habit for me to type it that way, and its not like it would do any harm checking that anyway. Just printing the text without the colour formatters on a pre1.4 computer.
I feel you, I do the same. Better safe than sorry when it comes to requirement-checks.
One can overdo it, I suppose. But trying to make your programs backwards-compatible from the get-go is a good habit.
I'm just speaking for myself though, so no offense to anyone who doesn't follow that. ( ->Heh, apparently better safe than sorry is deeply ingrained in my brain.^^)
theoriginalbit #20
Posted 22 April 2013 - 03:01 AM
Oh, I've updated it, but I have not saved it :P/>
So you changed it, but didn't press save… or does pastebin have some "save but don't publish" button I don't know about?

I feel you, I do the same. Better safe than sorry when it comes to requirement-checks.
One can overdo it, I suppose. But trying to make your programs backwards-compatible from the get-go is a good habit.
Yeh definitely… see if it was me making the function safe for all computers I would be doing this
Spoiler

-- the way that will make more sense reading it
local function getSafeColor(color)
  if term.isColor() then
	return color
  elseif color == colors.black then
	return color
  else
	return colors.white
  end
end

-- the compact way, i.e. the one I would actually use
local function getSafeColor(color)
  return term.isColor() and color or (color == colors.black and color or colors.white)
end

function sb(color)
  if not term.isColor then return end
  term.setBackgroundColor(getSafeColor(color))
end

function st(color)
  if not term.isColor then return end
  term.setTextColor(getSafeColor(color))
end

function cCode(h)
  return 2 ^ (tonumber(h, 16) or 0)
end
Edited on 22 April 2013 - 01:02 AM
jesusthekiller #21
Posted 22 April 2013 - 03:03 AM
Teasers for LinuxOS and Pacman:




jesusthekiller #22
Posted 22 April 2013 - 03:06 AM
So you changed it, but didn't press save… or does pastebin have some "save but don't publish" button I don't know about?

This 1st one ;)/>


I feel you, I do the same. Better safe than sorry when it comes to requirement-checks.
One can overdo it, I suppose. But trying to make your programs backwards-compatible from the get-go is a good habit.
Yeh definitely… see if it was me making the function safe for all computers I would be doing this

I'll include it today :)/>




Oops, double post
theoriginalbit #23
Posted 22 April 2013 - 03:07 AM
I'll include it today :)/>
I wasn't saying you had to… but if you do, make sure you actually pick one of the 2 identical functions in there; either long and readable, or compact.
jesusthekiller #24
Posted 22 April 2013 - 07:35 AM
cPrint update
  • Even better non-advanced computers support
SpoilerGod damn it! I can't hack into another account on my own OS :P/>

TheOddByte #25
Posted 22 April 2013 - 10:24 AM
Nice. :)/> Seems everyone is going to the 'all-in-one' posts now :)/>

here is what I said about cPrint in its thread
Spoiler
Looks very nice! I have just 2 improvements…

here is an improvement to your cCode function

function cCode(h)
  return 2 ^ tonumber(h, 16)
end

and your toCode, could become

function toCode(n)
  return string.format('%x', n)
end
Not me :P/> (Yet)
Anyway.. This seems great!
Especially cPrint and WCON. :)/>
jesusthekiller #26
Posted 22 April 2013 - 11:55 AM
Thanks! Great to get some feedback :)/>
Zudo #27
Posted 24 April 2013 - 06:35 AM
Nice!
jesusthekiller #28
Posted 05 May 2013 - 04:52 AM
Hi all, I'm back from my little holiday and I'm working on Pacman right now :)/>
theoriginalbit #29
Posted 05 May 2013 - 04:57 AM
I'm working on Pacman right now :)/>
It is such a misleading name. every time I read it I get a little excited thinking you're making Pac-Man, as in the game by Namco. Then I get disappointed when I remember its not.
jesusthekiller #30
Posted 18 May 2013 - 08:10 AM
  • Added Code Snippets section
  • Added Random String Generator
  • Added Guess the number minigame
  • Added tutorials section
  • Added "Random string generating" tutorial
jesusthekiller #31
Posted 22 May 2013 - 01:07 PM
  • Added more code snippets
  • Added Quick Installer Generator
  • Added link to my blog
micle546 #32
Posted 03 June 2013 - 10:28 AM
support for monitors in cprint?

I've hacked the code a bit to get it to do what I need it to do, but it'd be nice to have that function included
theoriginalbit #33
Posted 03 June 2013 - 11:04 AM
I've hacked the code a bit to get it to do what I need it to do, but it'd be nice to have that function included
did you do something like this…

term.redirect( peripheral.wrap('left') ) --# replace 'left' with the side the monitor is on, stuff will now print on the monitor
cprint.cprint('some string to print') --# replacing this string with your one
term.restore() --# stuff will resume printing on the terminal
jesusthekiller #34
Posted 19 June 2013 - 10:02 AM
Over 275 WCON accounts!