pygments.rb 0.3.7 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lexers +0 -0
- data/lib/pygments/version.rb +1 -1
- data/test/test_pygments.rb +0 -1
- data/vendor/pygments-main/AUTHORS +14 -1
- data/vendor/pygments-main/CHANGES +56 -6
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/Makefile +1 -1
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/docs/generate.py +1 -1
- data/vendor/pygments-main/docs/src/api.txt +1 -1
- data/vendor/pygments-main/docs/src/index.txt +1 -1
- data/vendor/pygments-main/docs/src/integrate.txt +5 -0
- data/vendor/pygments-main/docs/src/java.txt +70 -0
- data/vendor/pygments-main/external/autopygmentize +64 -0
- data/vendor/pygments-main/external/markdown-processor.py +2 -2
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive-old.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +1 -1
- data/vendor/pygments-main/pygments/__init__.py +2 -2
- data/vendor/pygments-main/pygments/cmdline.py +14 -6
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatter.py +1 -1
- data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -1
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +73 -2
- data/vendor/pygments-main/pygments/formatters/img.py +1 -1
- data/vendor/pygments-main/pygments/formatters/latex.py +1 -1
- data/vendor/pygments-main/pygments/formatters/other.py +1 -1
- data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
- data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal256.py +1 -1
- data/vendor/pygments-main/pygments/lexer.py +76 -12
- data/vendor/pygments-main/pygments/lexers/__init__.py +2 -2
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +4 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_mapping.py +26 -10
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +11 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +2 -2
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +4 -2
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +14 -3
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +11 -0
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +2 -2
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +6 -6
- data/vendor/pygments-main/pygments/lexers/agile.py +6 -4
- data/vendor/pygments-main/pygments/lexers/asm.py +40 -2
- data/vendor/pygments-main/pygments/lexers/compiled.py +751 -438
- data/vendor/pygments-main/pygments/lexers/dalvik.py +2 -2
- data/vendor/pygments-main/pygments/lexers/dotnet.py +1 -1
- data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +6 -5
- data/vendor/pygments-main/pygments/lexers/hdl.py +3 -3
- data/vendor/pygments-main/pygments/lexers/jvm.py +130 -16
- data/vendor/pygments-main/pygments/lexers/math.py +250 -9
- data/vendor/pygments-main/pygments/lexers/other.py +518 -13
- data/vendor/pygments-main/pygments/lexers/parsers.py +3 -2
- data/vendor/pygments-main/pygments/lexers/shell.py +48 -2
- data/vendor/pygments-main/pygments/lexers/special.py +1 -1
- data/vendor/pygments-main/pygments/lexers/sql.py +1 -1
- data/vendor/pygments-main/pygments/lexers/templates.py +7 -6
- data/vendor/pygments-main/pygments/lexers/text.py +9 -9
- data/vendor/pygments-main/pygments/lexers/web.py +264 -51
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/style.py +1 -1
- data/vendor/pygments-main/pygments/styles/__init__.py +1 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/token.py +1 -1
- data/vendor/pygments-main/pygments/unistring.py +1 -1
- data/vendor/pygments-main/pygments/util.py +1 -1
- data/vendor/pygments-main/scripts/check_sources.py +2 -2
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +2 -0
- data/vendor/pygments-main/scripts/find_codetags.py +1 -1
- data/vendor/pygments-main/scripts/find_error.py +5 -6
- data/vendor/pygments-main/setup.cfg +1 -0
- data/vendor/pygments-main/setup.py +6 -4
- data/vendor/pygments-main/tests/examplefiles/BOM.js +1 -0
- data/vendor/pygments-main/tests/examplefiles/autoit_submit.au3 +25 -0
- data/vendor/pygments-main/tests/examplefiles/bigtest.nsi +308 -0
- data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
- data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +89 -4
- data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -0
- data/vendor/pygments-main/tests/examplefiles/example.prg +161 -0
- data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -0
- data/vendor/pygments-main/tests/examplefiles/example.ts +28 -0
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +2 -2
- data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -0
- data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
- data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -0
- data/vendor/pygments-main/tests/examplefiles/nanomsg.intr +95 -0
- data/vendor/pygments-main/tests/examplefiles/phpMyAdmin.spec +163 -0
- data/vendor/pygments-main/tests/examplefiles/rust_example.rs +191 -701
- data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -0
- data/vendor/pygments-main/tests/examplefiles/test.opa +10 -0
- data/vendor/pygments-main/tests/examplefiles/test2.pypylog +120 -0
- data/vendor/pygments-main/tests/examplefiles/unix-io.lid +37 -0
- data/vendor/pygments-main/tests/old_run.py +1 -1
- data/vendor/pygments-main/tests/run.py +3 -2
- data/vendor/pygments-main/tests/support/tags +36 -0
- data/vendor/pygments-main/tests/test_basic_api.py +3 -2
- data/vendor/pygments-main/tests/test_clexer.py +1 -1
- data/vendor/pygments-main/tests/test_cmdline.py +1 -1
- data/vendor/pygments-main/tests/test_examplefiles.py +1 -1
- data/vendor/pygments-main/tests/test_html_formatter.py +17 -1
- data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
- data/vendor/pygments-main/tests/test_perllexer.py +1 -1
- data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
- data/vendor/pygments-main/tests/test_token.py +1 -1
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +5 -4
- metadata +26 -2
@@ -0,0 +1,161 @@
|
|
1
|
+
&& This is a concatenation of all VFP examples on Wikipedia.
|
2
|
+
&& Copyright 2013 Wikimedia, under the GFDL.
|
3
|
+
|
4
|
+
FOR i = 1 to 10
|
5
|
+
x = x + 6.5
|
6
|
+
ENDFOR
|
7
|
+
|
8
|
+
IF i = 25
|
9
|
+
i = i + 1
|
10
|
+
ELSE
|
11
|
+
i = i + 3
|
12
|
+
ENDIF
|
13
|
+
|
14
|
+
x = 1
|
15
|
+
DO WHILE x < 50
|
16
|
+
x = x + 1
|
17
|
+
ENDDO
|
18
|
+
|
19
|
+
x = 1
|
20
|
+
DO WHILE .T.
|
21
|
+
x = x + 1
|
22
|
+
IF x < 50
|
23
|
+
LOOP
|
24
|
+
ELSE
|
25
|
+
EXIT
|
26
|
+
ENDIF
|
27
|
+
ENDDO
|
28
|
+
|
29
|
+
nMonth = MONTH(DATE())
|
30
|
+
DO CASE
|
31
|
+
CASE nMonth <= 3
|
32
|
+
MESSAGEBOX("Q1")
|
33
|
+
|
34
|
+
CASE nMonth <= 6
|
35
|
+
MESSAGEBOX("Q2")
|
36
|
+
|
37
|
+
CASE nMonth <= 9
|
38
|
+
MESSAGEBOX("Q3")
|
39
|
+
|
40
|
+
OTHERWISE
|
41
|
+
MESSAGEBOX("Q4")
|
42
|
+
ENDCASE
|
43
|
+
|
44
|
+
FOR EACH oControl IN THISFORM.Controls
|
45
|
+
MESSAGEBOX(oControl.Name)
|
46
|
+
ENDFOR
|
47
|
+
|
48
|
+
f = Factorial(10)
|
49
|
+
|
50
|
+
FUNCTION Factorial(n)
|
51
|
+
LOCAL i,r
|
52
|
+
r = 1
|
53
|
+
FOR i = n TO 1 STEP -1
|
54
|
+
r = r * n
|
55
|
+
ENDFOR
|
56
|
+
RETURN r
|
57
|
+
ENDFUNC
|
58
|
+
|
59
|
+
loForm = CREATEOBJECT("HiForm")
|
60
|
+
loForm.Show(1)
|
61
|
+
|
62
|
+
DEFINE CLASS HiForm AS Form
|
63
|
+
AutoCenter = .T.
|
64
|
+
Caption = "Hello, World"
|
65
|
+
|
66
|
+
ADD OBJECT lblHi as Label WITH ;
|
67
|
+
Caption = "Hello, World!"
|
68
|
+
ENDDEFINE
|
69
|
+
|
70
|
+
loMine = CREATEOBJECT("MyClass")
|
71
|
+
? loMine.cProp1 && This will work. (Double-ampersand marks an end-of-line comment)
|
72
|
+
? loMine.cProp2 && Program Error: Property CPROP2 is not found.
|
73
|
+
|
74
|
+
? loMine.MyMethod1() && This will work.
|
75
|
+
? loMine.MyMethod2() && Program Error: Property MYMETHOD2 is not found.
|
76
|
+
|
77
|
+
DEFINE CLASS MyClass AS Custom
|
78
|
+
cProp1 = "My Property" && This is a public property
|
79
|
+
HIDDEN cProp2 && This is a private (hidden) property
|
80
|
+
dProp3 = {} && Another public property
|
81
|
+
|
82
|
+
PROCEDURE Init() && Class constructor
|
83
|
+
This.cProp2 = "This is a hidden property."
|
84
|
+
ENDPROC
|
85
|
+
|
86
|
+
PROCEDURE dProp3_Access && Property Getter
|
87
|
+
RETURN DATE()
|
88
|
+
ENDPROC
|
89
|
+
PROCEDURE dProp3_Assign(vNewVal) && Property Setter
|
90
|
+
IF VARTYPE(vNewVal) = "D"
|
91
|
+
THIS.dProp3 = vNewVal
|
92
|
+
ENDIF
|
93
|
+
ENDPROC
|
94
|
+
|
95
|
+
PROCEDURE MyMethod1()
|
96
|
+
* This is a public method, calling a hidden method that returns
|
97
|
+
* the value of a hidden property.
|
98
|
+
RETURN This.MyMethod2()
|
99
|
+
ENDPROC
|
100
|
+
|
101
|
+
HIDDEN PROCEDURE MyMethod2() && This is a private (hidden) method
|
102
|
+
RETURN This.cProp2
|
103
|
+
ENDPROC
|
104
|
+
ENDDEFINE
|
105
|
+
|
106
|
+
&& Create a table
|
107
|
+
CREATE TABLE randData (iData I)
|
108
|
+
|
109
|
+
&& Populate with random data using xBase and SQL DML commands
|
110
|
+
FOR i = 1 TO 50
|
111
|
+
APPEND BLANK
|
112
|
+
REPLACE iData WITH (RAND() * 100)
|
113
|
+
|
114
|
+
INSERT INTO randData (iData) VALUES (RAND() * 100)
|
115
|
+
ENDFOR
|
116
|
+
|
117
|
+
&& Place a structural index on the data
|
118
|
+
INDEX ON iData TAG iData
|
119
|
+
CLOSE ALL
|
120
|
+
|
121
|
+
&& Display ordered data using xBase-style commands
|
122
|
+
USE randData
|
123
|
+
SET ORDER TO iData
|
124
|
+
GO TOP
|
125
|
+
LIST NEXT 10 && First 10
|
126
|
+
GO BOTTOM
|
127
|
+
SKIP -10
|
128
|
+
LIST REST && Last 10
|
129
|
+
CLOSE ALL
|
130
|
+
|
131
|
+
&& Browse ordered data using SQL DML commands
|
132
|
+
SELECT * ;
|
133
|
+
FROM randData ;
|
134
|
+
ORDER BY iData DESCENDING
|
135
|
+
|
136
|
+
|
137
|
+
&& Connect to an ODBC data source
|
138
|
+
LOCAL nHnd
|
139
|
+
nHnd = SQLCONNECT ("ODBCDSN", "user", "pwd")
|
140
|
+
|
141
|
+
&& Execute a SQL command
|
142
|
+
LOCAL nResult
|
143
|
+
nResult = SQLEXEC (nHnd, "USE master")
|
144
|
+
IF nResult < 0
|
145
|
+
MESSAGEBOX ("MASTER database does not exist!")
|
146
|
+
RETURN
|
147
|
+
ENDIF
|
148
|
+
|
149
|
+
&& Retrieve data from the remote server and stores it in
|
150
|
+
&& a local data cursor
|
151
|
+
nResult = SQLEXEC (nHnd, "SELECT * FROM authors", "QAUTHORS")
|
152
|
+
|
153
|
+
&& Update a record in a remote table using parameters
|
154
|
+
PRIVATE cAuthorID, cAuthorName
|
155
|
+
cAuthorID = "1001"
|
156
|
+
cAuthorName = "New name"
|
157
|
+
nResult = SQLEXEC (nHnd, "UPDATE authors SET auth_name = ?cAuthorName WHERE auth_id = ?cAuthorID")
|
158
|
+
|
159
|
+
&& Close the connection
|
160
|
+
SQLDISCONNECT(nHnd)
|
161
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi- clean
|
2
|
+
rm -rf *.sb
|
3
|
+
rm -f sd_mmc_bootstream.raw
|
4
|
+
rm -f linux_prep/board/*.o
|
5
|
+
...
|
6
|
+
Files:
|
7
|
+
rm -f power_prep.o eabi.o
|
8
|
+
Build output:
|
9
|
+
make[1]: Leaving directory `/home/...'
|
10
|
+
[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi-
|
11
|
+
make[1]: Entering directory `/home/...'
|
12
|
+
...
|
13
|
+
#@echo "generating U-Boot boot stream image"
|
14
|
+
#elftosb2 -z -c ./uboot_prebuilt.db -o imx23_uboot.sb
|
15
|
+
echo "generating kernel bootstream file sd_mmc_bootstream.raw"
|
16
|
+
generating kernel bootstream file sd_mmc_bootstream.raw
|
17
|
+
#Please use cfimager to burn xxx_linux.sb. The below way will no
|
18
|
+
#work at imx28 platform.
|
19
|
+
> test
|
20
|
+
$ test
|
21
|
+
rm -f sd_mmc_bootstream.raw
|
22
|
+
[user@linuxbox imx-bootlets-src-10.05.02]$
|
23
|
+
pi@raspberrypi ~ $ sudo sh -c "echo 17 > /sys/class/gpio/export"
|
24
|
+
pi@raspberrypi ~ $ sudo sh -c "echo out > /sys/class/gpio/gpio17/direction"
|
25
|
+
pi@raspberrypi ~ $ sudo sh -c "echo 1 > /sys/class/gpio/gpio17/value"
|
26
|
+
pi@raspberrypi ~ $ sudo sh -c "echo 0 > /sys/class/gpio/gpio17/value"
|
27
|
+
pi@raspberrypi ~ $
|
28
|
+
[user@linuxbox ~]$ # copy other stuff to the SD card
|
29
|
+
root@imx233-olinuxino-micro:~# lsmod
|
30
|
+
Not tainted
|
31
|
+
[user@linuxbox ~]$ tail -n 2 /mnt/rpi/etc/inittab
|
32
|
+
#Spawn a getty on Raspberry Pi serial line
|
33
|
+
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
|
34
|
+
pi@raspberrypi:~/Adafruit-WebIDE$ mkdir tmp
|
35
|
+
pi@raspberrypi:~/Adafruit-WebIDE$ npm config set tmp tmp
|
36
|
+
pi@raspberrypi:~/Adafruit-WebIDE$ npm install
|
37
|
+
pi@raspberrypi ~/Adafruit-WebIDE $ ifconfig eth0
|
38
|
+
eth0 Link encap:Ethernet HWaddr b5:33:ff:33:ee:aq
|
39
|
+
inet addr:10.42.0.60 Bcast:10.42.0.255 Mask:255.255.255.0
|
40
|
+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
41
|
+
RX packets:21867 errors:0 dropped:0 overruns:0 frame:0
|
42
|
+
TX packets:8684 errors:0 dropped:0 overruns:0 carrier:0
|
43
|
+
collisions:0 txqueuelen:1000
|
44
|
+
RX bytes:27338495 (26.0 MiB) TX bytes:1268356 (1.2 MiB)
|
45
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Animal {
|
2
|
+
constructor(public name) { }
|
3
|
+
move(meters) {
|
4
|
+
alert(this.name + " moved " + meters + "m.");
|
5
|
+
}
|
6
|
+
}
|
7
|
+
|
8
|
+
class Snake extends Animal {
|
9
|
+
constructor(name) { super(name); }
|
10
|
+
move() {
|
11
|
+
alert("Slithering...");
|
12
|
+
super.move(5);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
class Horse extends Animal {
|
17
|
+
constructor(name) { super(name); }
|
18
|
+
move() {
|
19
|
+
alert("Galloping...");
|
20
|
+
super.move(45);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
var sam = new Snake("Sammy the Python")
|
25
|
+
var tom: Animal = new Horse("Tommy the Palomino")
|
26
|
+
|
27
|
+
sam.move()
|
28
|
+
tom.move(34)
|
@@ -39,7 +39,7 @@ unhex = q -> q and map p -> (int p 16) (q.split ':')
|
|
39
39
|
# :return: an integer which, written in binary form, points to the same node.
|
40
40
|
#
|
41
41
|
inet_pton6 = address ->
|
42
|
-
raise $ ValueError 'not a valid IPv6 address'
|
42
|
+
raise $ ValueError 'not a valid IPv6 address' if not (match = addrv6.match address)
|
43
43
|
start, end, *ipv4 = match.groups!
|
44
44
|
|
45
45
|
is_ipv4 = not $ None in ipv4
|
@@ -47,7 +47,7 @@ inet_pton6 = address ->
|
|
47
47
|
|
48
48
|
raise $ ValueError 'not a valid IPv6 address' if (end is None and shift) or shift < 0
|
49
49
|
hexaddr = (base_n 0x10000 (unhex start) << shift) + base_n 0x10000 (unhex $ end or '')
|
50
|
-
|
50
|
+
(hexaddr << 32) + base_n 0x100 (map int ipv4) if is_ipv4 else hexaddr
|
51
51
|
|
52
52
|
|
53
53
|
inet6_type = q -> switch
|
@@ -0,0 +1,28 @@
|
|
1
|
+
%hook ABC
|
2
|
+
- (id)a:(B)b {
|
3
|
+
%log;
|
4
|
+
return %orig(nil);
|
5
|
+
}
|
6
|
+
%end
|
7
|
+
|
8
|
+
%subclass DEF: NSObject
|
9
|
+
- (id)init {
|
10
|
+
[%c(RuntimeAccessibleClass) alloc];
|
11
|
+
return nil;
|
12
|
+
}
|
13
|
+
%end
|
14
|
+
|
15
|
+
%group OptionalHooks
|
16
|
+
%hook ABC
|
17
|
+
- (void)release {
|
18
|
+
[self retain];
|
19
|
+
%orig;
|
20
|
+
}
|
21
|
+
%end
|
22
|
+
%end
|
23
|
+
|
24
|
+
%ctor {
|
25
|
+
%init;
|
26
|
+
if(OptionalCondition)
|
27
|
+
%init(OptionalHooks);
|
28
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
; docformat = 'rst'
|
2
|
+
|
3
|
+
; Example IDL (Interactive Data Language) source code.
|
4
|
+
|
5
|
+
;+
|
6
|
+
; Get `nIndices` random indices for an array of size `nValues` (without
|
7
|
+
; repeating an index).
|
8
|
+
;
|
9
|
+
; :Examples:
|
10
|
+
; Try::
|
11
|
+
;
|
12
|
+
; IDL> r = randomu(seed, 10)
|
13
|
+
; IDL> print, r, format='(4F)'
|
14
|
+
; 0.6297589 0.7815896 0.2508559 0.7546844
|
15
|
+
; 0.1353382 0.1245834 0.8733745 0.0753110
|
16
|
+
; 0.8054136 0.9513228
|
17
|
+
; IDL> ind = mg_sample(10, 3, seed=seed)
|
18
|
+
; IDL> print, ind
|
19
|
+
; 2 4 7
|
20
|
+
; IDL> print, r[ind]
|
21
|
+
; 0.250856 0.135338 0.0753110
|
22
|
+
;
|
23
|
+
; :Returns:
|
24
|
+
; lonarr(`nIndices`)
|
25
|
+
;
|
26
|
+
; :Params:
|
27
|
+
; nValues : in, required, type=long
|
28
|
+
; size of array to choose indices from
|
29
|
+
; nIndices : in, required, type=long
|
30
|
+
; number of indices needed
|
31
|
+
;
|
32
|
+
; :Keywords:
|
33
|
+
; seed : in, out, optional, type=integer or lonarr(36)
|
34
|
+
; seed to use for random number generation, leave undefined to use a
|
35
|
+
; seed generated from the system clock; new seed will be output
|
36
|
+
;-
|
37
|
+
function mg_sample, nValues, nIndices, seed=seed
|
38
|
+
compile_opt strictarr
|
39
|
+
|
40
|
+
; get random nIndices by finding the indices of the smallest nIndices in a
|
41
|
+
; array of random values
|
42
|
+
values = randomu(seed, nValues)
|
43
|
+
|
44
|
+
; our random values are uniformly distributed, so ideally the nIndices
|
45
|
+
; smallest values are in the first bin of the below histogram
|
46
|
+
nBins = nValues / nIndices
|
47
|
+
h = histogram(values, nbins=nBins, reverse_indices=ri)
|
48
|
+
|
49
|
+
; the candidates for being in the first nIndices will live in bins 0..bin
|
50
|
+
nCandidates = 0L
|
51
|
+
for bin = 0L, nBins - 1L do begin
|
52
|
+
nCandidates += h[bin]
|
53
|
+
if (nCandidates ge nIndices) then break
|
54
|
+
endfor
|
55
|
+
|
56
|
+
; get the candidates and sort them
|
57
|
+
candidates = ri[ri[0] : ri[bin + 1L] - 1L]
|
58
|
+
sortedCandidates = sort(values[candidates])
|
59
|
+
|
60
|
+
; return the first nIndices of them
|
61
|
+
return, (candidates[sortedCandidates])[0:nIndices-1L]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
; main-level example program
|
66
|
+
|
67
|
+
r = randomu(seed, 10)
|
68
|
+
print, r
|
69
|
+
ind = mg_sample(10, 3, seed=seed)
|
70
|
+
print, ind
|
71
|
+
print, r[ind]
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/****************************************************************************
|
2
|
+
**
|
3
|
+
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
** All rights reserved.
|
5
|
+
** Contact: Nokia Corporation (qt-info@nokia.com)
|
6
|
+
**
|
7
|
+
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
8
|
+
**
|
9
|
+
** $QT_BEGIN_LICENSE:LGPL$
|
10
|
+
** GNU Lesser General Public License Usage
|
11
|
+
** This file may be used under the terms of the GNU Lesser General Public
|
12
|
+
** License version 2.1 as published by the Free Software Foundation and
|
13
|
+
** appearing in the file LICENSE.LGPL included in the packaging of this
|
14
|
+
** file. Please review the following information to ensure the GNU Lesser
|
15
|
+
** General Public License version 2.1 requirements will be met:
|
16
|
+
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
17
|
+
**
|
18
|
+
** In addition, as a special exception, Nokia gives you certain additional
|
19
|
+
** rights. These rights are described in the Nokia Qt LGPL Exception
|
20
|
+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
21
|
+
**
|
22
|
+
** GNU General Public License Usage
|
23
|
+
** Alternatively, this file may be used under the terms of the GNU General
|
24
|
+
** Public License version 3.0 as published by the Free Software Foundation
|
25
|
+
** and appearing in the file LICENSE.GPL included in the packaging of this
|
26
|
+
** file. Please review the following information to ensure the GNU General
|
27
|
+
** Public License version 3.0 requirements will be met:
|
28
|
+
** http://www.gnu.org/copyleft/gpl.html.
|
29
|
+
**
|
30
|
+
** Other Usage
|
31
|
+
** Alternatively, this file may be used in accordance with the terms and
|
32
|
+
** conditions contained in a signed written agreement between you and Nokia.
|
33
|
+
**
|
34
|
+
**
|
35
|
+
**
|
36
|
+
**
|
37
|
+
**
|
38
|
+
** $QT_END_LICENSE$
|
39
|
+
**
|
40
|
+
****************************************************************************/
|
41
|
+
|
42
|
+
import QtQuick 1.0
|
43
|
+
import "MinehuntCore" 1.0
|
44
|
+
|
45
|
+
Item {
|
46
|
+
id: field
|
47
|
+
property int clickx: 0
|
48
|
+
property int clicky: 0
|
49
|
+
|
50
|
+
width: 450; height: 450
|
51
|
+
|
52
|
+
Image { source: "MinehuntCore/pics/background.png"; anchors.fill: parent; fillMode: Image.Tile }
|
53
|
+
|
54
|
+
Grid {
|
55
|
+
anchors.horizontalCenter: parent.horizontalCenter
|
56
|
+
columns: 9; spacing: 1
|
57
|
+
|
58
|
+
Repeater {
|
59
|
+
id: repeater
|
60
|
+
model: tiles
|
61
|
+
delegate: Tile {}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
Row {
|
66
|
+
id: gamedata
|
67
|
+
x: 20; spacing: 20
|
68
|
+
anchors.bottom: field.bottom; anchors.bottomMargin: 15
|
69
|
+
|
70
|
+
Image {
|
71
|
+
source: "MinehuntCore/pics/quit.png"
|
72
|
+
scale: quitMouse.pressed ? 0.8 : 1.0
|
73
|
+
smooth: quitMouse.pressed
|
74
|
+
y: 10
|
75
|
+
MouseArea {
|
76
|
+
id: quitMouse
|
77
|
+
anchors.fill: parent
|
78
|
+
anchors.margins: -20
|
79
|
+
onClicked: Qt.quit()
|
80
|
+
}
|
81
|
+
}
|
82
|
+
Column {
|
83
|
+
spacing: 2
|
84
|
+
Image { source: "MinehuntCore/pics/bomb-color.png" }
|
85
|
+
Text { anchors.horizontalCenter: parent.horizontalCenter; color: "white"; text: numMines }
|
86
|
+
}
|
87
|
+
|
88
|
+
Column {
|
89
|
+
spacing: 2
|
90
|
+
Image { source: "MinehuntCore/pics/flag-color.png" }
|
91
|
+
Text { anchors.horizontalCenter: parent.horizontalCenter; color: "white"; text: numFlags }
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
Image {
|
96
|
+
anchors.bottom: field.bottom; anchors.bottomMargin: 15
|
97
|
+
anchors.right: field.right; anchors.rightMargin: 20
|
98
|
+
source: isPlaying ? 'MinehuntCore/pics/face-smile.png' :
|
99
|
+
hasWon ? 'MinehuntCore/pics/face-smile-big.png': 'MinehuntCore/pics/face-sad.png'
|
100
|
+
|
101
|
+
MouseArea { anchors.fill: parent; onPressed: reset() }
|
102
|
+
}
|
103
|
+
Text {
|
104
|
+
anchors.centerIn: parent; width: parent.width - 20
|
105
|
+
horizontalAlignment: Text.AlignHCenter
|
106
|
+
wrapMode: Text.WordWrap
|
107
|
+
text: "Minehunt demo has to be compiled to run.\n\nPlease see README."
|
108
|
+
color: "white"; font.bold: true; font.pixelSize: 14
|
109
|
+
visible: tiles == undefined
|
110
|
+
}
|
111
|
+
|
112
|
+
}
|