Login
...or Sign up
Home
Search
Search Code Snippets
Search People
Search
Code Snippets
People
7 Code Snippets found matching macro
on ParseUnixTime ts,toffset ts = integer(ts+toffset) -- get days and time days = ts / 86400 second = ts mod 86400 if (second < 0) then second = second + 86400 days = days - 1 end if -- time hour = second / 3600 second = second mod 3600 minute = second / 60 second = second mod 60 -- weekday wkday = (4 + days) mod 7 if (wkday < 0) then wkday = wkday + 7 -- year ryear = 1970 repeat while days < 0 or days > DaysInYear(ryear) -- guess year gyear = ryear + (days / 365) if (days mod 365) < 0 then gyear = gyear - 1 -- adjust daydiff = ((gyear - ryear) * 365) + LeapsThruEndOf(gyear - 1) - LeapsThruEndOf(ryear - 1) days = days - daydiff ryear = gyear end repeat -- day and month yearday = days + 1 if DaysInYear(ryear) = 365 then monthDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365] else monthDays = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366] end if i = 12 repeat while days < monthDays[i] i = i - 1 end repeat days = days - monthDays[i] rmonth = i rday = days + 1 return [#year:ryear, #month:rmonth, #day:rday, #weekday:wkday, #yearday:yearday, #hour:hour, #minute:minute, #second:second] end ParseUnixTime on LeapsThruEndOf pyear return integer(pyear / 4) - integer(pyear / 100) + integer(pyear / 400) end LeapsThruEndOf on DaysInYear pyear if ((pyear mod 4 = 0) and (pyear mod 100 <> 0)) or (pyear mod 400 = 0) then return 366 else return 365 end if end DaysInYear
Decode Unix Timestamp
Uploaded on
6/21/2007 4:13:14 AM
Programming Language:
Lingo
By:
Zydeco
See more code snippets of
Zydeco
director
lingo
macromedia
POSIX time
time_t
unix time
unix timestamp
on ToUnixTime pyear,pmonth,pday,phour,pmin,psec,toffset monthDays = MonthDaysInYear(pyear) ts = ((pyear - 1970) * 31536000) -- year seconds ts = ts + ((LeapsThruEndOf(pyear-1) - 478)* 86400) -- leap year extra days ts = ts + (monthDays[pmonth] * 86400) -- month seconds ts = ts + (pday * 86400) -- day seconds ts = ts + (phour * 3600) + (pmin * 60) + psec - toffset return ts end ToUnixTime on DaysInYear pyear if ((pyear mod 4 = 0) and (pyear mod 100 <> 0)) or (pyear mod 400 = 0) then return 366 else return 365 end if end DaysInYear on LeapsThruEndOf pyear return integer(pyear / 4) - integer(pyear / 100) + integer(pyear / 400) end LeapsThruEndOf on MonthDaysInYear pyear if DaysInYear(pyear) = 365 then return [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365] else return [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366] end if end MonthDaysInYear
Encode Unix Timestamp
Uploaded on
1/20/2008 6:39:44 AM
Programming Language:
Lingo
By:
Zydeco
See more code snippets of
Zydeco
director
lingo
macromedia
POSIX time
time_t
unix time
unix timestamp
-- JSON Toolkit -- version 1.0, February 26th 2009 -- Requires Director 11 for proper unicode support -- -- Copyright (C) 2009 Dyne Labs -- Based on JSON Dictionary 1.6, Copyright (C) 2007 Charcoal Design -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- 3. This notice may not be removed or altered from any source distribution. property json, jlist property _CR, _LF, _FF, _BS property _errorPos, _errorStr property _pos, _line, _lineStart property _indentStr, _keyValueSeparator, _keysAsSymbols, _endOfLine -- decodeJSON(): Parses a JSON string -- str: JSON string -- keysAsSymbols: (boolean) return property list keys as symbols instead of strings, defaults to TRUE -- recover: (boolean) return something even if there is a parsing error, defaults to FALSE -- returns a property list containing the parsed JSON, or VOID if an error occurred and the parser was not in recovery mode on decodeJSON str, keysAsSymbols, recover if voidP(keysAsSymbols) then keysAsSymbols = TRUE if voidP(recover) then recover = FALSE parser = new(script "JSON", str, keysAsSymbols) return parser.parse(recover) end -- encodeJSON(): Serializes an objecct into JSON -- obj: object to serialize, should be a property list -- * property list keys can be strings or symbols, both work -- pretty: output type -- * FALSE for compact -- * TRUE to indent with four spaces, and put each item on a line -- * any string to use it for indenting, and put each item on a line -- returns serialized string, or VOID if an error occurred on encodeJSON obj, pretty if voidP(pretty) then pretty = TRUE if integerP(pretty) and pretty = TRUE then pretty = " " if ilk(obj) <> #propList then return VOID parser = new(script "JSON", obj, pretty) parser.serializeObject(obj, 0) return parser[#json] end on HexToNum hex num = 0 repeat with i=1 to hex.length num = (num * 16) + offset(hex.char[i], "0123456789ABCDEF") - 1 end repeat return num end on new me, obj, arg _CR = NumToChar(13) _LF = NumToChar(10) _FF = NumToChar(12) _BS = NumToChar(8) _pos = 1 _line = 1 _lineStart = 1 if stringP(obj) then -- parser json = obj jlist = VOID _errorPos = VOID _keysAsSymbols = arg else -- serializer json = EMPTY jlist = obj if stringP(arg) then _indentStr = arg _endOfLine = _LF _keyValueSeparator = ": " else _indentStr = VOID _endOfLine = EMPTY _keyValueSeparator = ":" end if end if return me end on serializeObject me, obj, indent case ilk(obj) of #propList: me.serializePropertyList(obj, indent) #list: me.serializeList(obj, indent) #rect: me.serializeList(obj, indent) #point: me.serializeList(obj, indent) #symbol: put string(obj) after json #integer: put string(obj) after json #float: put string(obj) after json #string: me.serializeString(obj) #void: put "null" after json end case end on serializeString me, input output = EMPTY repeat with i=1 to the length of input c = char i of input case c of "\": put "\\" after output "/": put "\/" after output quote: put "\" & quote after output _BS: put "\b" after output _FF: put "\f" after output _LF: put "\n" after output _CR: put "\r" after output TAB: put "\t" after output otherwise: put c after output end case end repeat put quote & output & quote after json end on serializePropertyList me, obj, indent put "{" & _endOfLine after json -- elements repeat with i=1 to obj.count me.indent(indent+1) p = obj.getPropAt(i) if symbolP(p) then p = string(p) me.serializeString(p) put _keyValueSeparator after json me.serializeObject(obj[p], indent+1) if (i <> obj.count) then put "," after json put _endOfLine after json end repeat me.indent(indent) put "}" after json end on serializeList me, obj, indent put "[" & _endOfLine after json -- elements repeat with i=1 to obj.count me.indent(indent+1) me.serializeObject(obj[i], indent+1) if (i <> obj.count) then put "," after json put _endOfLine after json end repeat me.indent(indent) put "]" after json end on indent me, times if voidP(_indentStr) then return repeat with i=1 to times put _indentStr after json end repeat end on parse me, recover if voidP(recover) then recover = FALSE _pos = 1 me.skipWhiteSpace() obj = me.parseObject() if voidP(_errorPos) then return obj if recover then return obj return VOID end on skipWhiteSpace me repeat while true case json.char[_pos] of _CR: _line = _line + 1 _lineStart = _pos+1 _LF: if (json.char[_pos-1] <> _CR) then _line = _line + 1 _lineStart = _pos+1 SPACE: TAB: otherwise: exit repeat end case _pos = _pos + 1 end repeat end on parseObject me obj = [:] if json.char[_pos] <> "{" then return me.parseError(_pos, "expected {") _pos = _pos + 1 -- check for empty object me.skipWhiteSpace() if json.char[_pos] = "}" then _pos = _pos + 1 return obj end if repeat while true -- key me.skipWhiteSpace() key = me.parseString() if voidP(key) then return VOID -- separator me.skipWhiteSpace() if json.char[_pos] <> ":" then return me.parseError(_pos, "expected :") _pos = _pos + 1 -- value me.skipWhiteSpace() value = me.parseValue() if _keysAsSymbols then key = symbol(key) obj[key] = value -- more values, or end me.skipWhiteSpace() _pos = _pos + 1 case json.char[_pos-1] of ",": next repeat "}": return obj otherwise: return me.parseError(_pos-1, "expected , or }") end case end repeat end on parseValue me _pos = _pos + 4 case json.char[_pos-4.._pos-1] of "null": return #null "true": return #true "fals": if json.char[_pos] = "e" then _pos = _pos + 1 return #false end if _pos = _pos - 5 otherwise: _pos = _pos - 4 end case case json.char[_pos] of "-","0","1","2","3","4","5","6","7","8","9": return me.parseNumber() quote: return me.parseString() "{": return me.parseObject() "[": return me.parseArray() "": return me.parseError(_pos, "end of input") otherwise: return me.parseError(_pos, "expected value") end case end on parseError me,where,str _errorPos = [_line, where - _lineStart] _errorStr = str put "JSON parser error at" && _line & ":" & where - _lineStart && ":" && str return VOID end on parseString me str = EMPTY if json.char[_pos] <> quote then return me.parseError(_pos, "expected quote") _pos = _pos + 1 repeat while true c = json.char[_pos] _pos = _pos + 1 case c of quote: -- end of string return str EMPTY: -- end of input me.parseError(_pos-1, "end of input") return str "\": -- escape _CR: _line = _line + 1 _lineStart = _pos put c after str next repeat _LF: if (json.char[_pos-2] <> _CR) then _line = _line + 1 _lineStart = _pos put c after str next repeat otherwise: -- character put c after str next repeat end case -- escape c = json.char[_pos] _pos = _pos + 1 case c of quote, "/", "\": put c after str "b": put _BS after str "f": put _FF after str "n": put _LF after str "r": put _CR after str "t": put TAB after str "u": ucv = json.char[_pos.._pos+3] if ucv.length <> 4 then return me.parseError(_pos, "invalid unicode value") put NumToChar(HexToNum(ucv)) after str _pos = _pos + 4 otherwise: return me.parseError(_pos, "invalid escape sequence" && c) end case end repeat end on parseArray me arr = [] if json.char[_pos] <> "[" then return me.parseError(_pos, "expected [") _pos = _pos + 1 -- empty array? me.skipWhiteSpace() if json.char[_pos] = "]" then _pos = _pos + 1 return arr end if repeat while true me.skipWhiteSpace() arr.add(me.parseValue()) me.skipWhiteSpace() _pos = _pos + 1 case json.char[_pos-1] of ",": next repeat "]": return arr EMPTY: return me.parseError(_pos-1, "end of input") otherwise: return me.parseError(_pos-1, "expected ; or ]") end case end repeat end on parseNumber me integerPart = EMPTY decimalPart = EMPTY exponentPart = EMPTY exponentDecimalPart = EMPTY if json.char[_pos] = "-" then _pos = _pos + 1 integerPart = "-" end if -- integer part if json.char[_pos] = "0" then integerPart = "0" c = json.char[_pos+1] _pos = _pos + 2 else repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after integerPart ".", "e": exit repeat otherwise: _pos = _pos - 1 return integer(integerPart) end case end repeat end if if c = "." then -- decimal part decimalPart = "." repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after decimalPart "e": exit repeat otherwise: _pos = _pos - 1 return float(integerPart & decimalPart) end case end repeat end if if decimalPart = "." then return me.parseError(_pos, "invalid decimal part") if c = "e" then -- exponent part exponentPart = "e" c = json.char[_pos] if c = "+" or c = "-" then _pos = _pos + 1 put c after exponentPart end if repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after exponentPart otherwise: _pos = _pos - 1 if exponentPart = "e" then return me.parseError(_pos, "invalid exponent part") return float(integerPart & decimalPart & exponentPart) end case end repeat end if return 0 end
JSON Toolkit (Lingo)
Uploaded on
2/26/2009 10:48:44 AM
Programming Language:
Lingo
By:
Zydeco
See more code snippets of
Zydeco
adobe
director
json
lingo
macromedia
-- JSON Toolkit -- version 1.0, February 26th 2009 -- Requires Director 11 for proper unicode support -- -- Copyright (C) 2009 Dyne Labs -- Based on JSON Dictionary 1.6, Copyright (C) 2007 Charcoal Design -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- 3. This notice may not be removed or altered from any source distribution. property json, jlist property _CR, _LF, _FF, _BS property _errorPos, _errorStr property _pos, _line, _lineStart property _indentStr, _keyValueSeparator, _keysAsSymbols, _endOfLine -- decodeJSON(): Parses a JSON string -- str: JSON string -- keysAsSymbols: (boolean) return property list keys as symbols instead of strings, defaults to TRUE -- recover: (boolean) return something even if there is a parsing error, defaults to FALSE -- returns a property list containing the parsed JSON, or VOID if an error occurred and the parser was not in recovery mode on decodeJSON str, keysAsSymbols, recover if voidP(keysAsSymbols) then keysAsSymbols = TRUE if voidP(recover) then recover = FALSE parser = new(script "JSON", str, keysAsSymbols) return parser.parse(recover) end -- encodeJSON(): Serializes an objecct into JSON -- obj: object to serialize, should be a property list -- * property list keys can be strings or symbols, both work -- pretty: output type -- * FALSE for compact -- * TRUE to indent with four spaces, and put each item on a line -- * any string to use it for indenting, and put each item on a line -- returns serialized string, or VOID if an error occurred on encodeJSON obj, pretty if voidP(pretty) then pretty = TRUE if integerP(pretty) and pretty = TRUE then pretty = " " if ilk(obj) <> #propList then return VOID parser = new(script "JSON", obj, pretty) parser.serializeObject(obj, 0) return parser[#json] end on HexToNum hex num = 0 repeat with i=1 to hex.length num = (num * 16) + offset(hex.char[i], "0123456789ABCDEF") - 1 end repeat return num end on new me, obj, arg _CR = NumToChar(13) _LF = NumToChar(10) _FF = NumToChar(12) _BS = NumToChar(8) _pos = 1 _line = 1 _lineStart = 1 if stringP(obj) then -- parser json = obj jlist = VOID _errorPos = VOID _keysAsSymbols = arg else -- serializer json = EMPTY jlist = obj if stringP(arg) then _indentStr = arg _endOfLine = _LF _keyValueSeparator = ": " else _indentStr = VOID _endOfLine = EMPTY _keyValueSeparator = ":" end if end if return me end on serializeObject me, obj, indent case ilk(obj) of #propList: me.serializePropertyList(obj, indent) #list: me.serializeList(obj, indent) #rect: me.serializeList(obj, indent) #point: me.serializeList(obj, indent) #symbol: put string(obj) after json #integer: put string(obj) after json #float: put string(obj) after json #string: me.serializeString(obj) #void: put "null" after json end case end on serializeString me, input output = EMPTY repeat with i=1 to the length of input c = char i of input case c of "\": put "\\" after output "/": put "\/" after output quote: put "\" & quote after output _BS: put "\b" after output _FF: put "\f" after output _LF: put "\n" after output _CR: put "\r" after output TAB: put "\t" after output otherwise: put c after output end case end repeat put quote & output & quote after json end on serializePropertyList me, obj, indent put "{" & _endOfLine after json -- elements repeat with i=1 to obj.count me.indent(indent+1) p = obj.getPropAt(i) if symbolP(p) then p = string(p) me.serializeString(p) put _keyValueSeparator after json me.serializeObject(obj[p], indent+1) if (i <> obj.count) then put "," after json put _endOfLine after json end repeat me.indent(indent) put "}" after json end on serializeList me, obj, indent put "[" & _endOfLine after json -- elements repeat with i=1 to obj.count me.indent(indent+1) me.serializeObject(obj[i], indent+1) if (i <> obj.count) then put "," after json put _endOfLine after json end repeat me.indent(indent) put "]" after json end on indent me, times if voidP(_indentStr) then return repeat with i=1 to times put _indentStr after json end repeat end on parse me, recover if voidP(recover) then recover = FALSE _pos = 1 me.skipWhiteSpace() obj = me.parseObject() if voidP(_errorPos) then return obj if recover then return obj return VOID end on skipWhiteSpace me repeat while true case json.char[_pos] of _CR: _line = _line + 1 _lineStart = _pos+1 _LF: if (json.char[_pos-1] <> _CR) then _line = _line + 1 _lineStart = _pos+1 SPACE: TAB: otherwise: exit repeat end case _pos = _pos + 1 end repeat end on parseObject me obj = [:] if json.char[_pos] <> "{" then return me.parseError(_pos, "expected {") _pos = _pos + 1 -- check for empty object me.skipWhiteSpace() if json.char[_pos] = "}" then _pos = _pos + 1 return obj end if repeat while true -- key me.skipWhiteSpace() key = me.parseString() if voidP(key) then return VOID -- separator me.skipWhiteSpace() if json.char[_pos] <> ":" then return me.parseError(_pos, "expected :") _pos = _pos + 1 -- value me.skipWhiteSpace() value = me.parseValue() if _keysAsSymbols then key = symbol(key) obj[key] = value -- more values, or end me.skipWhiteSpace() _pos = _pos + 1 case json.char[_pos-1] of ",": next repeat "}": return obj otherwise: return me.parseError(_pos-1, "expected , or }") end case end repeat end on parseValue me _pos = _pos + 4 case json.char[_pos-4.._pos-1] of "null": return #null "true": return #true "fals": if json.char[_pos] = "e" then _pos = _pos + 1 return #false end if _pos = _pos - 5 otherwise: _pos = _pos - 4 end case case json.char[_pos] of "-","0","1","2","3","4","5","6","7","8","9": return me.parseNumber() quote: return me.parseString() "{": return me.parseObject() "[": return me.parseArray() "": return me.parseError(_pos, "end of input") otherwise: return me.parseError(_pos, "expected value") end case end on parseError me,where,str _errorPos = [_line, where - _lineStart] _errorStr = str put "JSON parser error at" && _line & ":" & where - _lineStart && ":" && str return VOID end on parseString me str = EMPTY if json.char[_pos] <> quote then return me.parseError(_pos, "expected quote") _pos = _pos + 1 repeat while true c = json.char[_pos] _pos = _pos + 1 case c of quote: -- end of string return str EMPTY: -- end of input me.parseError(_pos-1, "end of input") return str "\": -- escape _CR: _line = _line + 1 _lineStart = _pos put c after str next repeat _LF: if (json.char[_pos-2] <> _CR) then _line = _line + 1 _lineStart = _pos put c after str next repeat otherwise: -- character put c after str next repeat end case -- escape c = json.char[_pos] _pos = _pos + 1 case c of quote, "/", "\": put c after str "b": put _BS after str "f": put _FF after str "n": put _LF after str "r": put _CR after str "t": put TAB after str "u": ucv = json.char[_pos.._pos+3] if ucv.length <> 4 then return me.parseError(_pos, "invalid unicode value") put NumToChar(HexToNum(ucv)) after str _pos = _pos + 4 otherwise: return me.parseError(_pos, "invalid escape sequence" && c) end case end repeat end on parseArray me arr = [] if json.char[_pos] <> "[" then return me.parseError(_pos, "expected [") _pos = _pos + 1 -- empty array? me.skipWhiteSpace() if json.char[_pos] = "]" then _pos = _pos + 1 return arr end if repeat while true me.skipWhiteSpace() arr.add(me.parseValue()) me.skipWhiteSpace() _pos = _pos + 1 case json.char[_pos-1] of ",": next repeat "]": return arr EMPTY: return me.parseError(_pos-1, "end of input") otherwise: return me.parseError(_pos-1, "expected ; or ]") end case end repeat end on parseNumber me integerPart = EMPTY decimalPart = EMPTY exponentPart = EMPTY exponentDecimalPart = EMPTY if json.char[_pos] = "-" then _pos = _pos + 1 integerPart = "-" end if -- integer part if json.char[_pos] = "0" then integerPart = "0" c = json.char[_pos+1] _pos = _pos + 2 else repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after integerPart ".", "e": exit repeat otherwise: _pos = _pos - 1 return integer(integerPart) end case end repeat end if if c = "." then -- decimal part decimalPart = "." repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after decimalPart "e": exit repeat otherwise: _pos = _pos - 1 return float(integerPart & decimalPart) end case end repeat end if if decimalPart = "." then return me.parseError(_pos, "invalid decimal part") if c = "e" then -- exponent part exponentPart = "e" c = json.char[_pos] if c = "+" or c = "-" then _pos = _pos + 1 put c after exponentPart end if repeat while true c = json.char[_pos] _pos = _pos + 1 case c of "0","1","2","3","4","5","6","7","8","9": put c after exponentPart otherwise: _pos = _pos - 1 if exponentPart = "e" then return me.parseError(_pos, "invalid exponent part") return float(integerPart & decimalPart & exponentPart) end case end repeat end if return 0 end
JSON Toolkit (Lingo)
Uploaded on
2/26/2009 10:48:59 AM
Programming Language:
Lingo
By:
Zydeco
See more code snippets of
Zydeco
adobe
director
json
lingo
macromedia
Sub Macro1() ' Copia el contenido de la celda (1,1) es decir la A1 de todas las hojas en una misma fila (A1, A2, A3..) de la última hoja (o la hoja actual en la que estemos), generando así un listado de valores Dim Numerohojas As Integer For i = 1 To Workbooks.Application.Sheets.Count - 1 Workbooks.Application.Sheets(Workbooks.Application.Sheets.Count).Cells(i, 1).Value = Workbooks.Application.Sheets(i).Cells(1, 1) Next i End Sub
Agrupar celdas de diferentes hojas en una única hoja de excel (I)
Uploaded on
2/12/2010 3:43:53 AM
Programming Language:
Macro de excel: visualbasic
By:
rubensi
See more code snippets of
rubensi
excel
macro
1
2
Help
Help by email
What is Naslu?
|
About Naslu
|
Contact
|
Terms of Use
|
Downloads
|
Webprogramacion.com
|
Blog
|
Top
Links
Select language:
Español
|
English
© 2009 naslu.com