Corona SDK Pro Tip of the Day #4
Clean code

Always write clean code, indent properly. This improves readability and makes it easier to find bugs.

ZeroBrane Studio now has an option to automatically fix indentation of your code Edit -> Source -> Correct Indentation.

Another language that I like very much Go has a special tool go fmt, it reformats entire code, making it a single standard for everybody.

When all developers use the same code style, it's much easier to read others' code.

There will be a similar feature in ZeroBrane Studio in the future.

CONTINUE READING

Corona SDK Pro Tip of the Day #1
Writing to Resource Directory

You can't write to system.ResourceDirectory on a device, but you can in the Simulator.

This is useful if for example you are making a level editor inside the game, using the Simulator you can edit and save levels inside your project directory.

UPDATE. There is one limitation, system.pathForFile('newfile.txt', system.ResourceDirectory) won't work for files that don't exist. If you need to create new files inside system.ResourceDirectory, you have to construct correct path with a file that exists for sure, such as main.lua.

Here is a small snippet that will create newfile.txt.

local path = system.pathForFile('main.lua', system.ResourceDirectory)  
-- Remove main.lua from the string
path = path:sub(0, -9)  
-- Add newfile.txt instead
path = path .. 'newfile.txt'  
-- Open new file for writing
local file = io.open(path, 'w+')  
if file then  
   file:write('File Content')
   io.close(file)
end  
CONTINUE READING

Manual post cut (preview) for Ghost

There is a website called Habrahabr, where posts have a preview version and a full version. Preview is made from the full version by cutting the text before special habracut tag <habracut />.

So I miss such feature in Ghost and decided to implement it on my own.

I use <!--preview--> to define where preview ends in my post.

When there is something more to read, three dots in the center appear.

Getting Started

Locate ghost/core/server/helpers/index.js file. Scroll down until you see coreHelpers.content function. We need an extra if statement to cover our case.

● ● ●
CONTINUE READING