Skip to content

Instantly share code, notes, and snippets.

@thomasjao
thomasjao / gist:9602291
Created March 17, 2014 16:09
HTML -- Hide partial of internal DOM object within an outer DOM object
<!-- This snippet demo how to HIDE partial of a division within some range (another division)
If replace #d2 below with images can make parts of the image shown within #s1 range.
Also some suggest to add "margin: 0 auto;" within #s1 CSS, don't know why?
-->
<!DOCTYPE html>
<head>
<style>
#s1, #s2 { width: 300x; height: 200px; }
#s1 { top: 50px; background-color: blue; overflow: hidden; } /* assume #s1 is the range */
#s2 { background-color: brown; left: 100px; position: relative; }
// SIMPLE VARIABLE ASSIGNMENT
// Using syntax: set ... to ...
set a to 1 -- set a as an integer object with value 1
set PI to 3.14159 -- set PI as a real object with value 3.14159
set b to "A string" -- set b as a text object with value "A string"
set c to {"Thomas", "Sally"} -- set c as a list object contains two items: "Thomas", "Sally"
set d to {name: "Thomas", sex: "male"} -- set d as a record object with two properties with values
// To get variable type, in AppleScript, we name variable type as "class"
class of a -- return "integer"
@thomasjao
thomasjao / stripComma
Last active August 29, 2015 13:56
strip commas off from formatted digits to real number or integer
// NOTE: ensure numString contains only validate value, e.g. only digits, comma and period allowed
function toReal( numString ) {
if ( numString.contains('.') ) { // deem as real number with period within, regardless if comma exists
return parseFloat(numString.replace(/,/g, ''));
} else {
return parseInt( numSring ); // deem as integer, without period
}
}
@thomasjao
thomasjao / gist:7853169
Created December 8, 2013 03:53
Using UI elements to access unsupported application "Dictionary"
(* Appliction "Dictionary" doesn't support AppleScript. However, we can control this application via UI elements
of System Events. Following example show how to access various parts of "Dictionary" *)
tell application "Dictionary"
activate
tell application "System Events" to tell process "Dictionary"
UI elements of window 1
(* Access Spot light, enter searching word in the spotlight *)
set value of text field 1 of group 3 of tool bar 1 of windows to "challenge"
(* Get matched words/phrases list on the side bar of "Dictionary" *)
value of text field 1 of row 2 of table 1 of scroll area 1 of splitter group 1 of window 1
-- using list in AppleScript
-- define a list
set emptyList to {}
set d to {"c", "d"}
set e to {"e", "f"}
set ne to {"a", "b", 1, 3, d, e}
-- count items in a list
count ne
--> 6