Showing latest added snippets.

Widget Candy. .GetShape() - Snippet icon Widget Candy. .GetShape()
  1.  
  2. Returns the shape (x,y,width and height) of the specified widget.
  3.  
  4. GetShape (widgetName)
  5.  
  6. widgetName (String) The name of a widget.
  7.  
  8. Returns: (Table) A table with the properties .x, .y, .w and .h (which is the widget's x- and y-position, its width and height).
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Widget Candy .Enable() - Snippet icon Widget Candy .Enable()
Widget Candy Library
  1.  
  2. Enables or disables a widget. A disabled widget appears grayed-out and does not respond to user interactions.
  3.  
  4.  
  5.  
  6. Show (widgetName, isEnabled)
  7.  
  8. widgetName (String) The name of a widget.
  9.  
  10. isEnabled (Boolean) Enables (true) or disables (false) the specified widget.
See the complete snippet
Language: Other
Tags: Widget Candy Library Commands
Submitted By: sierramanagement
Composer Template - Snippet icon Composer Template
Composer Template
  1. local composer = require( "composer" )
  2. local scene = composer.newScene()
  3. local w = display.contentWidth
  4. local h = display.contentHeight
  5. local centerX = display.contentCenterX
  6. local centerY = display.contentCenterY
  7.  
  8.  
  9.  
  10. --------------------------------------------------------------------------------
  11. -- All code outside of the listener functions will only be executed ONCE
  12. -- unless "composer.removeSc
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Time Difference - Snippet icon Time Difference
  1. The following code returns a table containing {year=years, month=months, day=days, hour=hours, min=minutes, sec=seconds} representing the time between two dates created by os.time - by RichardWarburton.
  2.  
  3. local timeDiff = function(t2,t1)
  4. local d1,d2,carry,diff = os.date('*t',t1),os.date('*t',t2),false,{}
  5. local colMax = {60,60,24,os.date('*t',os.time{year=d1.year,month=d1.month+1,day=0}).day,12}
  6.  
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Date Parts - Snippet icon Date Parts
  1. -- given a string date of '2006-12-31' breaks it down to integer yy, mm and dd
  2. -- Compatible with Lua 5.0 and 5.1.
  3. -- from sam_lie
  4. function get_date_parts(date_str)
  5. local iyy, imm, idd
  6.  
  7. if (date_str) then
  8. x = string.gsub(date_str, "(%d+)-(%d+)-(%d+)", function (yy,mm,dd)
  9. iyy = tonumber(yy)
  10. imm = tonumber(mm)
  11. idd = tonumber(dd)
  12. end)
  13. end
  14.  
  15. return iyy, i
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Day Of Week Interger and Name - Snippet icon Day Of Week Interger and Name
  1. -- returns the day of week integer and the name of the week
  2. -- Compatible with Lua 5.0 and 5.1.
  3. -- from sam_lie
  4. function get_day_of_week(dd, mm, yy)
  5. local days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
  6. local fullname={“Sunday”,”Monday”,”Tuesday”,”Wendsday”,
  7. “Thursday”,”Friday”,”Saturday” }
  8.  
  9. local mmx = mm
  10.  
  11. if (mm == 1) then mmx = 13; yy = yy-1 en
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Days In Month - Snippet icon Days In Month
  1. -- returns the number of days in a given month and year
  2. -- Compatible with Lua 5.0 and 5.1.
  3. -- from sam_lie
  4. function get_days_in_month(month, year)
  5. local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  6. local d = days_in_month[month]
  7.  
  8. -- check for leap year
  9. if (month == 2) then
  10. if (math.mod(year,4) == 0) then
  11. if (math.mod(year,100) == 0)then
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Time Zone - Snippet icon Time Zone
  1. NOTE: the following only computes the timezone offset for "now", which differs from os.date("%z") which can handle times in the past or future, taking daylight savings time into account. Alternatively, you can use get_timezone_anystamp(ts) below
  2.  
  3. -- Compute the difference in seconds between local time and UTC.
  4. local function get_timezone()
  5. local now = os.time()
  6. return os.difftime(now, os.time(
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
A Date Time Function - Snippet icon A Date Time Function
  1. You can use os.time() to add or substract any number of any time unit (e.g. 10000 minutes or -3 months) without converting it to seconds. What is even better, that it deals with daylight savings too.
  2.  
  3.  
  4. This feature of os.date() and os.time() is not documented on www.lua.org [1], resulting a large amount of questions on Stackoverflow[2].
  5.  
  6. -- no surprise here:
  7. os.date("%c", os.time{year = 2017, mont
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Dir Tree Iterator - Snippet icon Dir Tree Iterator
  1.  
  2. It depends on the LuaFileSystem library ("lfs") [1].
  3.  
  4. -- code by AlexanderMarinov
  5. -- Compatible with Lua 5.1 (not 5.0).
  6.  
  7. -- Code by David Kastrup
  8. require "lfs"
  9.  
  10. function dirtree(dir)
  11. assert(dir and dir ~= "", "directory parameter is missing or empty")
  12. if string.sub(dir, -1) == "/" then
  13. dir=string.sub(dir, 1, -2)
  14. end
  15.  
  16. local function yieldtree(dir)
  17. for entry in lfs.dir(dir) do
  18.  
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Format Number -- output with commas and rounded to given decimal places - Snippet icon Format Number -- output with commas and rounded to given decimal places
Example usage: amount = 1333444.1 print(format_num(amount,2)) print(format_num(amount,-2,"US$")) a
  1. -- given a numeric value formats output with comma to separate thousands
  2. -- and rounded to given decimal places
  3. --
  4. --
  5. function format_num(amount, decimal, prefix, neg_prefix)
  6. local str_amount, formatted, famount, remain
  7.  
  8. decimal = decimal or 2 -- default 2 decimal places
  9. neg_prefix = neg_prefix or "-" -- default negative sign
  10.  
  11. famount = math.abs(round(amount,decimal))
  12. famount = math.fl
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Format Number -- rounds a number to the nearest decimal places - Snippet icon Format Number -- rounds a number to the nearest decimal places
Example usage: amount = 1333444.1 print(format_num(amount,2)) print(format_num(amount,-2,"US$")) a
  1. -- rounds a number to the nearest decimal places
  2. --
  3. function round(val, decimal)
  4. if (decimal) then
  5. return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  6. else
  7. return math.floor(val+0.5)
  8. end
  9. end
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Format Number --add comma to seperate thousands - Snippet icon Format Number --add comma to seperate thousands
Example usage: amount = 1333444.1 print(format_num(amount,2)) print(format_num(amount,-2,"US$")) a
  1. -- add comma to separate thousands
  2. --
  3. function comma_value(amount)
  4. local formatted = amount
  5. while true do
  6. formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  7. if (k==0) then
  8. break
  9. end
  10. end
  11. return formatted
  12. end
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
string pad module - Snippet icon string pad module
  1. local srep = string.rep
  2.  
  3. module('pad')
  4.  
  5. -- all of these functions return their result and a boolean
  6. -- to notify the caller if the string was even changed
  7.  
  8. -- pad the left side
  9. lpad =
  10. function (s, l, c)
  11. local res = srep(c or ' ', l - #s) .. s
  12.  
  13. return res, res ~= s
  14. end
  15.  
  16. -- pad the right side
  17. rpad =
  18. function (s, l, c)
  19. local res = s .. srep(c or ' ', l - #s)
  20.  
  21. return res, res ~= s
  22. end
  23.  
  24. --
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
trim Module - Snippet icon trim Module
  1. local ssub = string.sub
  2. local sfind = string.find
  3.  
  4. module('trim')
  5.  
  6. -- Each of these functions return a 2nd value letting
  7. -- the caller know if the string was changed at all
  8.  
  9. ltrim =
  10. function (s)
  11. local res = s
  12. local tmp = sfind(res, '%S')
  13.  
  14. -- string.sub() will create a duplicate if
  15. -- called with the first and last index
  16. -- (str_sub() in lstrlib.c)
  17.  
  18. if not tmp then
  19. res = ''
  20. elsei
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
Sort By Key - Snippet icon Sort By Key
  1. -- "Sorted by key" table iterator
  2. -- Extracted from http://www.lua.org/pil/19.3.html
  3.  
  4. function pairsKeySorted(t, f)
  5. local a = {}
  6. for n in pairs(t) do
  7. table.insert(a, n)
  8. end
  9. table.sort(a, f)
  10.  
  11. local i = 0 -- iterator variable
  12. local iter = function () -- iterator function
  13. i = i + 1
  14. if a[i] == nil then
  15. return nil
  16. els
See the complete snippet
Language: Other
Tags: sort key
Submitted By: sierramanagement
for Loops - Snippet icon for Loops
For Loop
  1. --[[
  2. The numeric for loop repeats a block of code while a control variable
  3. runs through an arithmetic progression. It has the following syntax:
  4. -- e1, e2, and e3 are evaluated only once before the loop.
  5. ]]
  6.  
  7. for v = e1, e2, e3 do
  8. --[[ block ]]
  9. end
  10.  
  11. -- Equivalent to:
  12.  
  13. do
  14. local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
  15.  
  16. if not (var and limit and step) then error() end
  17.  
  18. while
  19.  
See the complete snippet
Language: Other
Tags:
Submitted By: sierramanagement
HTML 4.01 Transitional - Snippet icon HTML 4.01 Transitional
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>untitled</title>
  6. </head>
  7.  
  8. </body>
  9. </html>
See the complete snippet
Language: HTML
Tags:
Submitted By: saed
XHTML 1.0 Transitional - Snippet icon XHTML 1.0 Transitional
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>untitled</title>
  7. </head>
  8.  
  9. </body>
  10. </html>
See the complete snippet
Language: HTML
Tags:
Submitted By: saed
skEdit Header Image

Get skEdit the easy to use web/html editor

skEdit is a full featured html & web editor it is easy to use and it helps you create your next website quickly and easily.

  • PHP, SQL, Ruby, and more
  • FTP/SFTP/WebDav Support
  • Code Completion
  • Live Preview
  • Snippets & Scripts
  • Subversion integration
And many more features....

Find out more » Download skEdit 4.1.8

Web Analytics