Skip to content

Instantly share code, notes, and snippets.

View Lerg's full-sized avatar

Sergey Lerg Lerg

View GitHub Profile
@Lerg
Lerg / app.lua
Last active August 29, 2015 13:56
local _M = {}
_M.deviceID = system.getInfo('deviceID')
if system.getInfo('environment') ~= 'simulator' then
io.output():setvbuf('no')
else
_M.isSimulator = true
end
local platform = system.getInfo('platformName')
#!/bin/bash
rm _*.png
s=${1:-32}
ss=$((s+2))
for f in $(find . -name "*@2x.png" -maxdepth 1); do
echo "Paddding $f..."
wo=`convert $f -ping -format "%w" info:`
h=`convert $f -ping -format "%h" info:`
w=$((wo + (wo / s)*2))
convert $f \
@Lerg
Lerg / config.lua
Last active August 29, 2015 13:57
Hex LED config.lua
local h, w = display.pixelWidth, display.pixelHeight
if (w == 1024 and h == 768) or (w == 960 and h == 640) or (w == 1136 and h == 640) or (w == 2048 and h == 1536) or (w == 1280 and h == 720) or (w == 480 and h == 320) then
while w > 700 do
w = w * 0.5
h = h * 0.5
end
w, h = h, w
else
w = 320 -- w = 300 -- for kindle fire and nexus 7 like tablets (1024x600)
h = 480
@Lerg
Lerg / enterFrameManager.lua
Last active August 29, 2015 13:58
Enter Frame functions manager with tags
local _M = {}
function _M.nextFrame(f)
timer.performWithDelay(1, f)
end
function _M.enterFrame()
for i = 1, #_M.enterFrameFunctions do
_M.enterFrameFunctions[i][1]()
end
end
@Lerg
Lerg / downsize.sh
Created June 2, 2014 19:50
Automatically downsizes your @4x and @2x images in the current directory
#!/bin/sh
ext=$1
for f in $(find . -name "*@4x.$ext"); do
echo "Converting $f..."
convert "$f" -resize '50%' -unsharp 1x4 "$(dirname $f)/$(basename -s "@4x.$ext" $f)@2x.$ext"
done
for f in $(find . -name "*@2x.$ext"); do
echo "Converting $f..."
convert "$f" -resize '50%' -unsharp 1x4 "$(dirname $f)/$(basename -s "@2x.$ext" $f).$ext"
done
--[[
A simple sample game for Corona SDK.
http://coronalabs.com
Made by @SergeyLerg.
Licence: MIT.
]]
-- Don't show pesky status bar.
display.setStatusBar(display.HiddenStatusBar)
@Lerg
Lerg / index-content.js
Last active September 3, 2021 08:18
Manual preview cut for {{content}} helper in Ghost platform
// ### Content Helper
//
// *Usage example:*
// `{{content}}`
// `{{content words="20"}}`
// `{{content characters="256"}}`
// `{{content preview="true"}}`
//
// Turns content html into a safestring so that the user doesn't have to
// escape it or tell handlebars to leave it alone with a triple-brace.
@Lerg
Lerg / utils.lua
Last active August 23, 2022 20:09
local mRandom = math.random
local tInsert = table.insert
local app = require('lib.app')
-------------------------------------------
-- Shuffle a table
-------------------------------------------
table.shuffle = function (t)
local n = #t
while n > 2 do
-- n is now the last pertinent index
@Lerg
Lerg / main.lua
Last active November 6, 2022 21:04
Take screenshots in simulator with S key
if app.isSimulator then
Runtime:addEventListener('key', function (event)
if event.keyName == 's' and event.phase == 'down' then
local scene = storyboard.getScene(storyboard.getCurrentSceneName())
if scene and scene.view then
display.save(scene.view, display.pixelWidth .. 'x' .. display.pixelHeight .. '_' .. math.floor(system.getTimer()) .. '.png')
return true
end
end
end)
@Lerg
Lerg / n28s.lua
Last active December 2, 2022 16:43
Script wrapper for Defold
local hashed = require('libs.hashed')
local _M = {}
local scripts = {}
-- NoMoreGlobalFunctionsInScripts
function _M.new()
local script = {