瀏覽代碼

Add samples

Alex Dima 7 年之前
父節點
當前提交
6e4a60bfdd

+ 7 - 0
website/index/samples/sample.apex.txt

@@ -0,0 +1,7 @@
+/* Using a single database query, find all the leads in
+    the database that have the same email address as any
+    of the leads being inserted or updated. */
+for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) {
+    Lead newLead = leadMap.get(lead.Email);
+    newLead.Email.addError('A lead with this email address already exists.');
+}

+ 5 - 0
website/index/samples/sample.azcli.txt

@@ -0,0 +1,5 @@
+# Create a resource group.
+az group create --name myResourceGroup --location westeurope
+
+# Create a new virtual machine, this creates SSH keys if not present.
+az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys

+ 18 - 0
website/index/samples/sample.perl.txt

@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Path::Tiny;
+
+my $dir = path('foo','bar'); # foo/bar
+
+# Iterate over the content of foo/bar
+my $iter = $dir->iterator;
+while (my $file = $iter->()) {
+
+    # See if it is a directory and skip
+    next if $file->is_dir();
+
+    # Print out the file name and path
+    print "$file\n";
+}

+ 12 - 0
website/index/samples/sample.powerquery.txt

@@ -0,0 +1,12 @@
+let
+    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
+    SplitColumnDelimiter = Table.SplitColumn(Source,"Input",Splitter.SplitTextByDelimiter(","),13),
+    Unpivot = Table.Unpivot(SplitColumnDelimiter,{"Input.1", "Input.2", "Input.3", "Input.4",
+    "Input.5", "Input.6",    "Input.7", "Input.8", "Input.9", "Input.10", "Input.11", "Input.12"
+    ,  "Input.13"},"Attribute","Value"),
+    RemovedColumns = Table.RemoveColumns(Unpivot,{"Attribute"}),
+    DuplicatesRemoved = Table.Distinct(RemovedColumns),
+    GroupedRows = Table.Group(DuplicatesRemoved, {"RowID"}, {{"Count of Distinct Values"
+    , each Table.RowCount(_), type number}})
+in
+    GroupedRows

+ 105 - 0
website/index/samples/sample.scheme.txt

@@ -0,0 +1,105 @@
+;;; make-matrix creates a matrix (a vector of vectors).
+(define make-matrix
+  (lambda (rows columns)
+    (do ((m (make-vector rows))
+         (i 0 (+ i 1)))
+        ((= i rows) m)
+        (vector-set! m i (make-vector columns)))))
+
+;;; matrix? checks to see if its argument is a matrix.
+;;; It isn't foolproof, but it's generally good enough.
+(define matrix?
+  (lambda (x)
+    (and (vector? x)
+         (> (vector-length x) 0)
+         (vector? (vector-ref x 0)))))
+
+;; matrix-rows returns the number of rows in a matrix.
+(define matrix-rows
+   (lambda (x)
+      (vector-length x)))
+
+;; matrix-columns returns the number of columns in a matrix.
+(define matrix-columns
+   (lambda (x)
+      (vector-length (vector-ref x 0))))
+
+;;; matrix-ref returns the jth element of the ith row.
+(define matrix-ref
+  (lambda (m i j)
+    (vector-ref (vector-ref m i) j)))
+
+;;; matrix-set! changes the jth element of the ith row.
+(define matrix-set!
+  (lambda (m i j x)
+    (vector-set! (vector-ref m i) j x)))
+
+;;; mul is the generic matrix/scalar multiplication procedure
+(define mul
+  (lambda (x y)
+    ;; mat-sca-mul multiplies a matrix by a scalar.
+    (define mat-sca-mul
+       (lambda (m x)
+          (let* ((nr (matrix-rows m))
+                 (nc (matrix-columns m))
+                 (r  (make-matrix nr nc)))
+             (do ((i 0 (+ i 1)))
+                 ((= i nr) r)
+                 (do ((j 0 (+ j 1)))
+                     ((= j nc))
+                     (matrix-set! r i j
+                        (* x (matrix-ref m i j))))))))
+
+    ;; mat-mat-mul multiplies one matrix by another, after verifying
+    ;; that the first matrix has as many columns as the second
+    ;; matrix has rows.
+    (define mat-mat-mul
+       (lambda (m1 m2)
+          (let* ((nr1 (matrix-rows m1))
+                 (nr2 (matrix-rows m2))
+                 (nc2 (matrix-columns m2))
+                 (r   (make-matrix nr1 nc2)))
+             (if (not (= (matrix-columns m1) nr2))
+                 (match-error m1 m2))
+             (do ((i 0 (+ i 1)))
+                 ((= i nr1) r)
+                 (do ((j 0 (+ j 1)))
+                     ((= j nc2))
+                     (do ((k 0 (+ k 1))
+                          (a 0
+                             (+ a
+                                (* (matrix-ref m1 i k)
+                                   (matrix-ref m2 k j)))))
+                         ((= k nr2)
+                          (matrix-set! r i j a))))))))
+
+   ;; type-error is called to complain when mul receives an invalid
+   ;; type of argument.
+    (define type-error
+       (lambda (what)
+          (error 'mul
+             "~s is not a number or matrix"
+             what)))
+
+    ;; match-error is called to complain when mul receives a pair of
+    ;; incompatible arguments.
+    (define match-error
+       (lambda (what1 what2)
+          (error 'mul
+             "~s and ~s are incompatible operands"
+             what1
+             what2)))
+
+    ;; body of mul; dispatch based on input types
+    (cond
+      ((number? x)
+       (cond
+         ((number? y) (* x y))
+         ((matrix? y) (mat-sca-mul y x))
+         (else (type-error y))))
+      ((matrix? x)
+       (cond
+         ((number? y) (mat-sca-mul x y))
+         ((matrix? y) (mat-mat-mul x y))
+         (else (type-error y))))
+      (else (type-error x)))))

+ 42 - 0
website/index/samples/sample.shell.txt

@@ -0,0 +1,42 @@
+#!/bin/bash
+# Simple line count example, using bash
+#
+# Bash tutorial: http://linuxconfig.org/Bash_scripting_Tutorial#8-2-read-file-into-bash-array
+# My scripting link: http://www.macs.hw.ac.uk/~hwloidl/docs/index.html#scripting
+#
+# Usage: ./line_count.sh file
+# -----------------------------------------------------------------------------
+
+# Link filedescriptor 10 with stdin
+exec 10<&0
+# stdin replaced with a file supplied as a first argument
+exec < $1
+# remember the name of the input file
+in=$1
+
+# init
+file="current_line.txt"
+let count=0
+
+# this while loop iterates over all lines of the file
+while read LINE
+do
+    # increase line counter
+    ((count++))
+    # write current line to a tmp file with name $file (not needed for counting)
+    echo $LINE > $file
+    # this checks the return code of echo (not needed for writing; just for demo)
+    if [ $? -ne 0 ]
+     then echo "Error in writing to file ${file}; check its permissions!"
+    fi
+done
+
+echo "Number of lines: $count"
+echo "The last line of the file is: `cat ${file}`"
+
+# Note: You can achieve the same by just using the tool wc like this
+echo "Expected number of lines: `wc -l $in`"
+
+# restore stdin from filedescriptor 10
+# and close filedescriptor 10
+exec 0<&10 10<&-

+ 14 - 0
website/index/samples/sample.st.txt

@@ -0,0 +1,14 @@
+FUNCTION_BLOCK SubFB
+VAR_INPUT
+TimeIN : BOOL; (* Boolean input variable *)
+TimeQ : BOOL; (* Boolean input variable *)
+END_VAR
+VAR_IN_OUT
+Timer : TON; (* pointer to instance Time1 of TON – input/output variable *)
+END_VAR
+VAR_OUTPUT
+Time3 : TON; (* 3rd instance of TON *)
+END_VAR
+VAR
+Start : BOOL := TRUE; (* local Boolean variable *)
+END_VAR