### Puppet Module Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/puppet/index.html This is an example of a Puppet module for installing and configuring AutoMySQLBackup. It defines parameters, validates paths, and manages files and packages. ```puppet # == Class: automysqlbackup # # Puppet module to install AutoMySQLBackup for periodic MySQL backups. # # class { # 'automysqlbackup': # backup_dir => '/mnt/backups', # } # class automysqlbackup ( $bin_dir = $automysqlbackup::params::bin_dir, $etc_dir = $automysqlbackup::params::etc_dir, $backup_dir = $automysqlbackup::params::backup_dir, $install_multicore = undef, $config = {}, $config_defaults = {}, ) inherits automysqlbackup::params { # Ensure valid paths are assigned validate_absolute_path($bin_dir) validate_absolute_path($etc_dir) validate_absolute_path($backup_dir) # Create a subdirectory in /etc for config files file { $etc_dir: ensure => directory, owner => 'root', group => 'root', mode => '0750', } # Create an example backup file, useful for reference file { "${etc_dir}/automysqlbackup.conf.example": ensure => file, owner => 'root', group => 'root', mode => '0660', source => 'puppet:///modules/automysqlbackup/automysqlbackup.conf', } # Add files from the developer file { "${etc_dir}/AMB_README": ensure => file, source => 'puppet:///modules/automysqlbackup/AMB_README', } file { "${etc_dir}/AMB_LICENSE": ensure => file, source => 'puppet:///modules/automysqlbackup/AMB_LICENSE', } # Install the actual binary file file { "${bin_dir}/automysqlbackup": ensure => file, owner => 'root', group => 'root', mode => '0755', source => 'puppet:///modules/automysqlbackup/automysqlbackup', } # Create the base backup directory file { $backup_dir: ensure => directory, owner => 'root', group => 'root', mode => '0755', } # If you'd like to keep your config in hiera and pass it to this class if !empty($config) { create_resources('automysqlbackup::backup', $config, $config_defaults) } # If using RedHat family, must have the RPMforge repo's enabled if $install_multicore { package { ['pigz', 'pbzip2']: ensure => installed } } } ``` -------------------------------- ### Asterisk Dialplan Configuration Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/asterisk/index.html This is an example of an Asterisk extensions.conf file, demonstrating various dialplan contexts, extensions, and application usages. It includes general settings, dynamic contexts, and specific examples for local calls, demo features, voicemail, and system-wide paging. ```asterisk ; extensions.conf - the Asterisk dial plan ; ; If static is set to no, or omitted, then the pbx_config will rewrite ; this file when extensions are modified. Remember that all comments ; made in the file will be lost when that happens. static=yes #include "/etc/asterisk/additional_general.conf" [iaxprovider] switch => IAX2/user:[key]@myserver/mycontext [dynamic] #exec /usr/bin/dynamic-peers.pl [trunkint] ; ; International long distance through trunk ; exten => _9011.,1,Macro(dundi-e164,${EXTEN:4}) exten => _9011.,n,Dial(${GLOBAL(TRUNK)}/${FILTER(0-9,${EXTEN:${GLOBAL(TRUNKMSD)}})}) [local] ; ; Master context for local, toll-free, and iaxtel calls only ; ignorepat => 9 include => default [demo] include => stdexten ; ; We start with what to do when a call first comes in. ; exten => s,1,Wait(1) ; Wait a second, just for fun same => n,Answer ; Answer the line same => n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds same => n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds same => n(restart),BackGround(demo-congrats) ; Play a congratulatory message same => n(instruct),BackGround(demo-instruct) ; Play some instructions same => n,WaitExten ; Wait for an extension to be dialed. exten => 2,1,BackGround(demo-moreinfo) ; Give some more information. exten => 2,n,Goto(s,instruct) exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french exten => 3,n,Goto(s,restart) ; Start with the congratulations exten => 1000,1,Goto(default,s,1) ; ; ; We also create an example user, 1234, who is on the console and has ; voicemail, etc. ; exten => 1234,1,Playback(transfer,skip) ; "Please hold while..." ; (but skip if channel is not up) exten => 1234,n,Gosub(${EXTEN},stdexten(${GLOBAL(CONSOLE)})) exten => 1234,n,Goto(default,s,1) ; exited Voicemail exten => 1235,1,Voicemail(1234,u) ; Right to voicemail exten => 1236,1,Dial(Console/dsp) ; Ring forever exten => 1236,n,Voicemail(1234,b) ; Unless busy ; ; # for when they're done with the demo ; exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo" exten => #,n,Hangup ; Hang them up. ; ; A timeout and "invalid extension rule" ; exten => t,1,Goto(#,1) ; If they take too long, give up exten => i,1,Playback(invalid) ; "That's not valid, try again" ; ; Create an extension, 500, for dialing the ; Asterisk demo. ; exten => 500,1,Playback(demo-abouttotry); Let them know what's going on exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default) ; Call the Asterisk demo exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site exten => 500,n,Goto(s,6) ; Return to the start over message. ; ; Create an extension, 600, for evaluating echo latency. ; exten => 600,1,Playback(demo-echotest) ; Let them know what's going on exten => 600,n,Echo ; Do the echo test exten => 600,n,Playback(demo-echodone) ; Let them know it's over exten => 600,n,Goto(s,6) ; Start over ; ; You can use the Macro Page to intercom a individual user nexten => 76245,1,Macro(page,SIP/Grandstream1) ; or if your peernames are the same as extensions exten => _7XXX,1,Macro(page,SIP/${EXTEN}) ; ; System Wide Page at extension 7999 ; exten => 7999,1,Set(TIMEOUT(absolute)=60) exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n) ; Give voicemail at extension 8500 ; exten => 8500,1,VoicemailMain exten => 8500,n,Goto(s,6) ``` -------------------------------- ### Kotlin HTTP Server Implementation Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/kotlin/index.html A Kotlin class demonstrating an HTTP server setup using Netty. It includes methods for starting and stopping the server. ```kotlin package org.wasabi.http import java.util.concurrent.Executors import java.net.InetSocketAddress import org.wasabi.app.AppConfiguration import io.netty.bootstrap.ServerBootstrap import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioServerSocketChannel import org.wasabi.app.AppServer public class HttpServer(private val appServer: AppServer) { val bootstrap: ServerBootstrap val primaryGroup: NioEventLoopGroup val workerGroup: NioEventLoopGroup { // Define worker groups primaryGroup = NioEventLoopGroup() workerGroup = NioEventLoopGroup() // Initialize bootstrap of server bootstrap = ServerBootstrap() bootstrap.group(primaryGroup, workerGroup) bootstrap.channel(javaClass()) bootstrap.childHandler(NettyPipelineInitializer(appServer)) } public fun start(wait: Boolean = true) { val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel() if (wait) { channel?.closeFuture()?.sync() } } public fun stop() { // Shutdown all event loops primaryGroup.shutdownGracefully() workerGroup.shutdownGracefully() // Wait till all threads are terminated primaryGroup.terminationFuture().sync() workerGroup.terminationFuture().sync() } } ``` -------------------------------- ### Dockerfile Syntax Highlighting Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/dockerfile/index.html This is a sample Dockerfile demonstrating various instructions and syntax elements. It is used for syntax highlighting by the Dockerfile mode. ```dockerfile # Install Ghost blogging platform and run development environment # # VERSION 1.0.0 FROM ubuntu:12.10 MAINTAINER Amer Grgic "amer@livebyt.es" WORKDIR /data/ghost # Install dependencies for nginx installation RUN apt-get update RUN apt-get install -y python g++ make software-properties-common --force-yes RUN add-apt-repository ppa:chris-lea/node.js RUN apt-get update # Install unzip RUN apt-get install -y unzip # Install curl RUN apt-get install -y curl # Install nodejs & npm RUN apt-get install -y rlwrap RUN apt-get install -y nodejs # Download Ghost v0.4.1 RUN curl -L https://ghost.org/zip/ghost-latest.zip -o /tmp/ghost.zip # Unzip Ghost zip to /data/ghost RUN unzip -uo /tmp/ghost.zip -d /data/ghost # Add custom config js to /data/ghost ADD ./config.example.js /data/ghost/config.js # Install Ghost with NPM RUN cd /data/ghost/ && npm install --production # Expose port 2368 EXPOSE 2368 # Run Ghost CMD ["npm","start"] ``` -------------------------------- ### Example Python Code Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/python/index.html Demonstrates a basic Python class structure with a static method and initialization. Useful for understanding class definitions and method usage. ```python import os from package import ParentClass @nonsenseDecorator def doesNothing(): pass class ExampleClass(ParentClass): @staticmethod def example(inputStr): a = list(inputStr) a.reverse() return ''.join(a) def __init__(self, mixin = 'Hello'): self.mixin = mixin ``` -------------------------------- ### Example Sieve Filter Script Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/sieve/index.html A comprehensive example demonstrating various Sieve filter rules, including rejecting large messages, handling mailing lists, filtering based on sender domain, and identifying spam. ```sieve # Example Sieve Filter # Declare any optional features or extension used by the script # require ["fileinto", "reject"]; # # Reject any large messages (note that the four leading dots get # "stuffed" to three) # if size :over 1M { reject text: Please do not send me large attachments. Put your file on a server and send me the URL. Thank you. .... Fred . stop; } # # Handle messages from known mailing lists # Move messages from IETF filter discussion list to filter folder # if header :is "Sender" "owner-ietf-mta-filters@imc.org" { fileinto "filter"; # move to "filter" folder } # # Keep all messages to or from people in my company # elsif address :domain :is ["From", "To"] "example.com" { keep; # keep in "In" folder } # # Try and catch unsolicited email. If a message is not to me, # or it contains a subject known to be spam, file it away. # elsif anyof ( not address :all :contains ["To", "Cc", "Bcc"] "me@example.com", header :matches "subject" ["*make*money*fast*", "*university*dipl*mas*"] ) { # If message header does not contain my address, # it's from a list. fileinto "spam"; # move to "spam" folder } else { # Move all other (non-company) mail to "personal" # folder. fileinto "personal"; } ``` -------------------------------- ### Lua Syntax Highlighting Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/lua/index.html Demonstrates basic Lua syntax highlighting, including comments, function definitions, variable assignments, conditional statements, and string literals. ```lua --[[ example useless code to show lua syntax highlighting this is multiline comment ]] function blahblahblah(x) local table = { "asd" = 123, "x" = 0.34, } if x ~= 3 then print( x ) elseif x == "string" my_custom_function( 0x34 ) else unknown_function( "some string" ) end --single line comment end function blablabla3() for k,v in ipairs( table ) do --abcde.. y=[[ x=[[ x is a multi line string ]] but its definition is iside a highest level string! ]=] print(" \"\" ") s = math.sin( x ) end end ``` -------------------------------- ### Cython Example Code Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/python/index.html Shows an example of Cython code for calculating pairwise distances, utilizing NumPy and C-level optimizations. This is for performance-critical numerical computations. ```cython import numpy as np cimport cython from libc.math cimport sqrt @cython.boundscheck(False) @cython.wraparound(False) def pairwise_cython(double[:, ::1] X): cdef int M = X.shape[0] cdef int N = X.shape[1] cdef double tmp, d cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64) for i in range(M): for j in range(M): d = 0.0 for k in range(N): tmp = X[i, k] - X[j, k] d += tmp * tmp D[i, j] = sqrt(d) return np.asarray(D) ``` -------------------------------- ### Basic CodeMirror Initialization Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/diff/index.html A minimal example of initializing CodeMirror from a textarea element with default settings. This is the simplest way to integrate CodeMirror into a web page. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); ``` -------------------------------- ### HTML Mixed Mode Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/htmlmixed/index.html Demonstrates a basic HTML document structure with embedded CSS and JavaScript, rendered within the HTML mixed mode. ```html Mixed HTML Example

Mixed HTML Example

``` -------------------------------- ### Initialize CodeMirror Editor Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/javascript/index.html Demonstrates how to initialize a CodeMirror editor from a textarea element with specific configurations. This example enables line numbers, bracket matching, and comment toggling. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, continueComments: "Enter", extraKeys: {"Ctrl-Q": "toggleComment"} }); ``` -------------------------------- ### LESS Syntax Examples Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/css/less.html Demonstrates various LESS syntax features including media queries, pseudo-classes, attribute selectors, vendor prefixes, and variable usage. This is useful for understanding LESS parsing capabilities. ```less @media screen and (device-aspect-ratio: 16/9) { … } ``` ```less @media screen and (device-aspect-ratio: 1280/720) { … } ``` ```less @media screen and (device-aspect-ratio: 2560/1440) { … } ``` ```less html:lang(fr-be) tr:nth-child(2n+1) /* represents every odd row of an HTML table */ img:nth-of-type(2n+1) { float: right; } ``` ```less img:nth-of-type(2n) { float: left; } ``` ```less body > h2:not(:first-of-type):not(:last-of-type) ``` ```less html|*:not(:link):not(:visited) *|*:not(:hover) ``` ```less p::first-line { text-transform: uppercase } ``` ```less @namespace foo url(http://www.example.com); ``` ```less foo|h1 { color: blue } /* first rule */ ``` ```less span[hello="Ocean"][goodbye="Land"] E[foo]{ padding:65px; } ``` ```less input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5 } ``` ```less button::-moz-focus-inner, input::-moz-focus-inner { // Inner padding and border oddities in FF3/4 padding: 0; border: 0; } ``` ```less .btn { // reset here as of 2.0.3 due to Recess property order border-color: #ccc; border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25); } ``` ```less fieldset span button, fieldset span input[type="file"] { font-size:12px; font-family:Arial, Helvetica, sans-serif; } ``` ```less .rounded-corners (@radius: 5px) { border-radius: @radius; -webkit-border-radius: @radius; -moz-border-radius: @radius; } ``` ```less @import url("something.css"); ``` ```less @light-blue: hsl(190, 50%, 65%); ``` ```less #menu { position: absolute; width: 100%; z-index: 3; clear: both; display: block; background-color: @blue; height: 42px; border-top: 2px solid lighten(@alpha-blue, 20%); border-bottom: 2px solid darken(@alpha-blue, 25%); .box-shadow(0, 1px, 8px, 0.6); -moz-box-shadow: 0 0 0 #000; // Because firefox sucks. &.docked { background-color: hsla(210, 60%, 40%, 0.4); } &:hover { background-color: @blue; } #dropdown { margin: 0 0 0 117px; padding: 0; padding-top: 5px; display: none; width: 190px; border-top: 2px solid @medium; color: @highlight; border: 2px solid darken(@medium, 25%); border-left-color: darken(@medium, 15%); border-right-color: darken(@medium, 15%); border-top-width: 0; background-color: darken(@medium, 10%); ul { padding: 0px; } li { font-size: 14px; display: block; text-align: left; padding: 0; border: 0; a { display: block; padding: 0px 15px; text-decoration: none; color: white; &:hover { background-color: darken(@medium, 15%); text-decoration: none; } } } .border-radius(5px, bottom); .box-shadow(0, 6px, 8px, 0.5); } } ``` -------------------------------- ### LESS Syntax Examples Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/css/less.html Illustrative LESS syntax, including media queries, pseudo-classes, attribute selectors, vendor prefixes, nested rules, and variable usage. ```css @media screen and (device-aspect-ratio: 16/9) { … } ``` ```css @media screen and (device-aspect-ratio: 1280/720) { … } ``` ```css @media screen and (device-aspect-ratio: 2560/1440) { … } ``` ```css html:lang(fr-be) tr:nth-child(2n+1) /* represents every odd row of an HTML table */ img:nth-of-type(2n+1) { float: right; } ``` ```css img:nth-of-type(2n) { float: left; } ``` ```css body > h2:not(:first-of-type):not(:last-of-type) ``` ```css html|*:not(:link):not(:visited) *|*:not(:hover) p::first-line { text-transform: uppercase } ``` ```css @namespace foo url(http://www.example.com); ``` ```css foo|h1 { color: blue } /* first rule */ ``` ```css span[hello="Ocean"][goodbye="Land"] E[foo]{ padding:65px; } ``` ```css input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5 } ``` ```css button::-moz-focus-inner, input::-moz-focus-inner { // Inner padding and border oddities in FF3/4 padding: 0; border: 0; } ``` ```css .btn { // reset here as of 2.0.3 due to Recess property order border-color: #ccc; border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25); } ``` ```css fieldset span button, fieldset span input[type="file"] { font-size:12px; font-family:Arial, Helvetica, sans-serif; } ``` ```css .rounded-corners (@radius: 5px) { border-radius: @radius; -webkit-border-radius: @radius; -moz-border-radius: @radius; } ``` ```css @import url("something.css"); ``` ```css @light-blue: hsl(190, 50%, 65%); ``` ```css #menu { position: absolute; width: 100%; z-index: 3; clear: both; display: block; background-color: @blue; height: 42px; border-top: 2px solid lighten(@alpha-blue, 20%); border-bottom: 2px solid darken(@alpha-blue, 25%); .box-shadow(0, 1px, 8px, 0.6); -moz-box-shadow: 0 0 0 #000; // Because firefox sucks. &.docked { background-color: hsla(210, 60%, 40%, 0.4); } &:hover { background-color: @blue; } #dropdown { margin: 0 0 0 117px; padding: 0; padding-top: 5px; display: none; width: 190px; border-top: 2px solid @medium; color: @highlight; border: 2px solid darken(@medium, 25%); border-left-color: darken(@medium, 15%); border-right-color: darken(@medium, 15%); border-top-width: 0; background-color: darken(@medium, 10%); ul { padding: 0px; } li { font-size: 14px; display: block; text-align: left; padding: 0; border: 0; a { display: block; padding: 0px 15px; text-decoration: none; color: white; &:hover { background-color: darken(@medium, 15%); text-decoration: none; } } } .border-radius(5px, bottom); .box-shadow(0, 6px, 8px, 0.5); } ``` -------------------------------- ### Example Sieve Filter Script Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/sieve/index.html This example demonstrates a Sieve filter script used for managing email. It includes directives for declaring features, rejecting large messages, and filing messages based on sender, recipient, or subject. ```sieve # # Example Sieve Filter # Declare any optional features or extension used by the script # require ["fileinto", "reject"]; # # Reject any large messages (note that the four leading dots get # "stuffed" to three) if size :over 1M { reject text: Please do not send me large attachments. Put your file on a server and send me the URL. Thank you. .... Fred . stop; } # # Handle messages from known mailing lists # Move messages from IETF filter discussion list to filter folder if header :is "Sender" "owner-ietf-mta-filters@imc.org" { fileinto "filter"; # move to "filter" folder } # # Keep all messages to or from people in my company elsif address :domain :is ["From", "To"] "example.com" { keep; # keep in "In" folder } # # Try and catch unsolicited email. If a message is not to me, # or it contains a subject known to be spam, file it away. elsif anyof (not address :all :contains ["To", "Cc", "Bcc"] "me@example.com", header :matches "subject" ["*make*money*fast*", "*university*dipl*mas*"]) { # If message header does not contain my address, # it's from a list. fileinto "spam"; # move to "spam" folder } else { # Move all other (non-company) mail to "personal" # folder. fileinto "personal"; } ``` -------------------------------- ### mIRC Initialization and Exit Handlers Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/mirc/index.html Initializes the NickNames hash table on script start, loads it from a file if available, and saves it on exit or disconnect to persist data. ```mirc On *:Start:{ if (!$hget(NickNames)) { hmake NickNames 10 } if ($isfile(NickNames.hsh)) { hload NickNames NickNames.hsh } } ``` ```mirc On *:Exit: { if ($hget(NickNames)) { hsave NickNames NickNames.hsh } } ``` ```mirc On *:Disconnect: { if ($hget(NickNames)) { hsave NickNames NickNames.hsh } } ``` ```mirc On *:Unload: { hfree NickNames } ``` -------------------------------- ### Eggdrop WHOIS Script Setup Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/tcl/index.html Configuration section for the Tcl WHOIS script. Customize command triggers, text colors, and output format. ```tcl namespace eval whois { ## change cmdchar to the trigger you want to use ## ## variable cmdchar "!" change command to the word trigger you would like to use. ## ## ## Keep in mind, This will also change the .chanset +/-command ## ## variable command "whois" change textf to the colors you want for the text. ## ## variable textf "\017\00304" change tagf to the colors you want for tags: ## ## variable tagf "\017\002" Change logo to the logo you want at the start of the line. ## ## variable logo "\017\00304\002\[\00306W\003hois\00304\]\017" Change lineout to the results you want. Valid results are channel users modes topic ## ## ## variable lineout "channel users modes topic" } ############################################################################################## ## ## End Setup. ## ## ############################################################################################## ``` -------------------------------- ### Initialize CodeMirror with Lua Mode Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/lua/index.html Initializes a CodeMirror editor instance from a textarea element, enabling bracket matching and applying the 'neat' theme. This is a common setup for using CodeMirror with specific modes. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { matchBrackets: true, theme: "neat" }); ``` -------------------------------- ### JavaScript for Test Scripting Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/index.html Shows examples of JavaScript code used for executing scripts, such as pre-test or post-test actions. It includes placeholders for refreshing data and adding new scripts. ```javascript [用例](javascript:void(0))|[账号](javascript:void(0))|[全局](javascript:void(0))[前置](javascript:void(0))|[后置](javascript:void(0))执行脚本 JavaScript [![](img/refresh.png) ](javascript:void(0))[+](javascript:void(0))[](javascript:void(0))[](javascript:void(0)) ``` -------------------------------- ### YAML Favorite Movies List Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/yaml/index.html Example of a simple YAML list structure used to define a collection of items, such as favorite movies. ```yaml --- # Favorite movies - Casablanca - North by Northwest - The Man Who Wasn't There --- ``` -------------------------------- ### CodeMirror Instance Methods Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/diff/index.html Provides a set of essential methods for interacting with a CodeMirror instance, including operations for refreshing the display, getting the input field, and managing undo history. ```javascript refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}, getInputField: function(){return input;} ``` -------------------------------- ### mIRC Script Setup and Aliases Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/mirc/index.html Configuration for mIRC nickname tracking, including display options and maximum nick storage. This section defines aliases for managing nickname data. ```mirc ;AKA Nick Tracker by Ford_Lawnmower irc.GeekShed.net #Script-Help ;*********************************************************************; **Start Setup ;Change JoinDisplay, below, for On Join AKA Display. On = 1 - Off = 0 alias -l JoinDisplay { return 1 } ;Change MaxNicks, below, to the number of nicknames you want to store for each hostmask. I wouldn't go over 400 with this ;/ alias -l MaxNicks { return 20 } ;Change AKALogo, below, To the text you want displayed before each AKA result. alias -l AKALogo { return 06 05A06K07A 06 } ;**End Setup ********************************************************************* ``` -------------------------------- ### GFM Fenced Code Block Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/gfm/index.html Demonstrates a fenced code block within GFM syntax, which allows for syntax highlighting of the enclosed code. The language specifier 'javascript' is used here. ```javascript for (var i = 0; i < items.length; i++) { console.log(items[i], i); // log them } ``` -------------------------------- ### Coin Changer Demo with Groovy Enums Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/groovy/index.html This example implements a coin changer function using Groovy's enum capabilities. It defines different coin types (US and Ozzie) and a helper function to pluralize words. ```groovy /* Coin changer demo code from http://groovy.codehaus.org */ enum UsCoin { quarter(25), dime(10), nickel(5), penny(1) UsCoin(v) { value = v } final value } enum OzzieCoin { fifty(50), twenty(20), ten(10), five(5) OzzieCoin(v) { value = v } final value } def plural(word, count) { if (count == 1) return word word[-1] == 'y' ? word[0..-2] + "ies" : word + "s" } def change(currency, amount) { currency.values().inject([]){ list, coin -> int count = amount / coin.value amount = amount % coin.value list += "$count ${plural(coin.toString(), count)}" } } ``` -------------------------------- ### APL Game of Life Example Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/apl/index.html This APL code implements Conway's game of life. It defines a creature, places it on a board, and provides a function to compute subsequent generations. The 'gen' function formats the output as a character matrix. ```apl ⍝ Conway's game of life ⍝ This example was inspired by the impressive demo at ⍝ http://www.youtube.com/watch?v=a9xAKttWgP4 ⍝ Create a matrix: ⍝ 0 1 1 ⍝ 1 1 0 ⍝ 0 1 0 creature ← (3 3 ⍴ ⍳ 9) ∈ 1 2 3 4 7 ⍝ Original creature from demo creature ← (3 3 ⍴ ⍳ 9) ∈ 1 3 6 7 8 ⍝ Glider ⍝ Place the creature on a larger board, near the centre board ← ¯1 ⊖ ¯2 ⌽ 5 7 ↑ creature ⍝ A function to move from one generation to the next life ← {∨/ 1 ⍵ ∧ 3 4 = ⊂+/ +⌿ 1 0 ¯1 ∘.⊖ 1 0 ¯1 ⌽¨ ⊂⍵} ⍝ Compute n-th generation and format it as a ⍝ character matrix gen ← {' #'\(life ⍣ ⍵) board] ⍝ Show first three generations (gen 1) (gen 2) (gen 3) ``` -------------------------------- ### Getting the Last Element Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns the last element of the collection. Throws `NoSuchElementException` if the collection is empty. This operation is order-dependent. ```scala def last: A = { var lst = head for (x <- this) lst = x lst } ``` -------------------------------- ### Getting the First Element Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns the first element of the collection. Throws `NoSuchElementException` if the collection is empty. This operation is order-dependent. ```scala def head: A = { var result: () => A = () => throw new NoSuchElementException breakable { for (x <- this) { result = () => x break } } result() } ``` -------------------------------- ### Optionally Getting the Last Element Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns the last element of the collection as an `Option[A]`. Returns `None` if the collection is empty. This operation is order-dependent. ```scala def lastOption: Option[A] = if (isEmpty) None else Some(last) ``` -------------------------------- ### YAML Shopping List Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/yaml/index.html Demonstrates a YAML list format for creating a shopping list. ```yaml --- # Shopping list [milk, pumpkin pie, eggs, juice] --- ``` -------------------------------- ### Optionally Getting the First Element Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns the first element of the collection as an `Option[A]`. Returns `None` if the collection is empty. This operation is order-dependent. ```scala def headOption: Option[A] = if (isEmpty) None else Some(head) ``` -------------------------------- ### Kotlin HTTP Server Implementation Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/kotlin/index.html A basic Kotlin HTTP server implementation using Netty. This snippet demonstrates the server bootstrap, channel configuration, and graceful shutdown procedures. ```kotlin package org.wasabi.http import java.util.concurrent.Executors import java.net.InetSocketAddress import org.wasabi.app.AppConfiguration import io.netty.bootstrap.ServerBootstrap import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioServerSocketChannel import org.wasabi.app.AppServer public class HttpServer(private val appServer: AppServer) { val bootstrap: ServerBootstrap val primaryGroup: NioEventLoopGroup val workerGroup: NioEventLoopGroup init { // Define worker groups primaryGroup = NioEventLoopGroup() workerGroup = NioEventLoopGroup() // Initialize bootstrap of server bootstrap = ServerBootstrap() bootstrap.group(primaryGroup, workerGroup) bootstrap.channel(javaClass()) bootstrap.childHandler(NettyPipelineInitializer(appServer)) } public fun start(wait: Boolean = true) { val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel() if (wait) { channel?.closeFuture()?.sync() } } public fun stop() { // Shutdown all event loops primaryGroup.shutdownGracefully() workerGroup.shutdownGracefully() // Wait till all threads are terminated primaryGroup.terminationFuture().sync() workerGroup.terminationFuture().sync() } } ``` -------------------------------- ### CodeMirror: Initialize F# editor Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/mllike/index.html Initializes a CodeMirror editor instance for F# syntax highlighting. ```javascript var fsharpEditor = CodeMirror.fromTextArea(document.getElementById('fsharpCode'), { mode: 'text/x-fsharp', lineNumbers: true, matchBrackets: true }); ``` -------------------------------- ### YAML Complex Data Structure Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/yaml/index.html Example of a more complex YAML structure including nested lists, maps, anchors, and aliases, representing a purchase invoice. ```yaml --- receipt: Oz-Ware Purchase Invoice date: 2007-08-06 customer: given: Dorothy family: Gale items: - part_no: A4786 descrip: Water Bucket (Filled) price: 1.47 quantity: 4 - part_no: E1628 descrip: High Heeled "Ruby" Slippers size: 8 price: 100.27 quantity: 1 bill-to: &id001 street: | 123 Tornado Alley Suite 16 city: East Centerville state: KS ship-to: *id001 specialDelivery: > Follow the Yellow Brick Road to the Emerald City. Pay no attention to the man behind the curtain. --- ... ``` -------------------------------- ### JSON Configuration with Comments Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/index.html Demonstrates a JSON configuration object that supports JSON5 format, including comments and type inference for method arguments. This format is useful for manual debugging and configuration. ```json { "static": true, "methodArgs": [ { "type": "long", "value": 1 }, { "type": "long", "value": 2 } ] } ``` -------------------------------- ### CodeMirror: Initialize OCaml editor Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/mllike/index.html Initializes a CodeMirror editor instance for OCaml syntax highlighting. ```javascript var ocamlEditor = CodeMirror.fromTextArea(document.getElementById('ocamlCode'), { mode: 'text/x-ocaml', lineNumbers: true, matchBrackets: true }); ``` -------------------------------- ### Markdown Headers and Paragraphs Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/markdown/index.html Demonstrates Setext and atx-style headers, blockquotes, and basic paragraphs in Markdown. Use Setext headers by underlining with '=' or '-', and atx headers with '#'. Blockquotes are indicated with '>'. ```markdown Markdown: A First Level Header =================== A Second Level Header --------------------- Now is the time for all good men to come to the aid of their country. This is just a regular paragraph. The quick brown fox jumped over the lazy dog's back. ### Header 3 > This is a blockquote. > > This is the second paragraph in the blockquote. > > ## This is an H2 in a blockquote ``` ```html

A First Level Header

A Second Level Header

Now is the time for all good men to come to the aid of their country. This is just a regular paragraph.

The quick brown fox jumped over the lazy dog's back.

Header 3

This is a blockquote.

This is the second paragraph in the blockquote.

This is an H2 in a blockquote

``` -------------------------------- ### Initialize CodeMirror with Puppet Mode Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/puppet/index.html Use this to initialize CodeMirror for editing Puppet code. Ensure the 'text/x-puppet' mode is loaded. This configuration enables bracket matching and sets the indent unit to 4 spaces. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-puppet", matchBrackets: true, indentUnit: 4 }); ``` -------------------------------- ### Getting All Elements Except the Last Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns a new collection containing all elements except the last one. Throws `UnsupportedOperationException` if the collection is empty. This operation is order-dependent. ```scala def init: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.init") var lst = head var follow = false val b = newBuilder b.sizeHint(this, -1) for (x <- this.seq) { if (follow) b += lst else follow = true lst = x } b.result } ``` -------------------------------- ### Getting All Elements Except the First Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Returns a new collection containing all elements except the first one. Throws `UnsupportedOperationException` if the collection is empty. This operation is order-dependent. ```scala override def tail: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.tail") drop(1) } ``` -------------------------------- ### Configure CodeMirror Options Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/diff/index.html This code illustrates how to set various options for a CodeMirror instance. It includes common settings like `readOnly`, `indentUnit`, and `autoMatchBrackets`, and shows how to handle option updates. ```javascript if (option == "parser") setParser(value); else if (option === "lineNumbers") setLineNumbers(value); else if (option === "gutter") setGutter(value); else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);} else options[option] = value; ``` -------------------------------- ### OCaml: List manipulation Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/mllike/index.html Demonstrates list construction and cons operations. ```ocaml let l = 1 :: 2 :: 3 :: [] [1; 2; 3] 5 :: l ``` -------------------------------- ### Initialize CodeMirror with Dockerfile Mode Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/dockerfile/index.html This JavaScript code initializes a CodeMirror editor instance for a textarea element, enabling line numbers and setting the mode to 'dockerfile' for syntax highlighting. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, mode: "dockerfile" }); ``` -------------------------------- ### CodeMirror Initialization for Python Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/python/index.html Initializes a CodeMirror editor for Python mode with specific configurations. Use this to set up a Python-aware editor instance. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: {name: "python", version: 3, singleLineStringErrors: false}, lineNumbers: true, indentUnit: 4, matchBrackets: true }); ``` -------------------------------- ### Random Data Generation for Method Arguments Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/index.html Illustrates how to specify random or ordered data generation for method arguments. This includes using ORDER_IN for sequential selection and RANDOM_IN for random selection of values, as well as RANDOM_DB for fetching data from a database. ```javascript methodArgs/0/type: ORDER_IN('int', 'long', 'double', 'int', 'Number') // 顺序取值 methodArgs/0/value: RANDOM_IN(1, 0.1, -10, 9.99, null) // 随机取值 methodArgs/1/type: ORDER_IN('int', 'long', 'double', 'int', 'Number') // 顺序取值 methodArgs/1/value: ORDER_INT(-10, 100) // 顺序整数 // 从数据库随机取值 methodArgs/1/value: RANDOM_DB(0, 1000, 'Random', 'count') ``` -------------------------------- ### Left Scan Operation Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/clike/scala.html Performs a left-to-right scan (also known as a cumulative fold) on the collection. It starts with an initial value `z` and applies the binary operation `op` cumulatively. ```scala def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(this, 1) var acc = z b += acc for (x <- this) { acc = op(acc, x) b += acc } b.result } ``` -------------------------------- ### Initialize Dylan CodeMirror Editor Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/dylan/index.html Initializes a CodeMirror editor instance for Dylan code. Sets up features like line numbers, bracket matching, and comment handling. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-dylan", lineNumbers: true, matchBrackets: true, continueComments: "Enter", extraKeys: {"Ctrl-Q": "toggleComment"}, tabMode: "indent", indentUnit: 2 }); ``` -------------------------------- ### Update Line Numbers in CodeMirror Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/diff/index.html This code snippet shows how CodeMirror updates its line number display. It accounts for a configurable `firstLineNumber` option, allowing the numbering to start from a value other than 1. ```javascript else html.push("
" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "
"); ``` -------------------------------- ### Initialize GFM Mode Editor Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Admin/md/lib/codemirror/mode/gfm/index.html Instantiate a CodeMirror editor with the 'gfm' mode enabled. This mode supports GitHub Flavored Markdown syntax. Line numbers and a theme can also be configured. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: 'gfm', lineNumbers: true, theme: "default" }); ``` -------------------------------- ### Initialize Smarty Mode in CodeMirror Source: https://github.com/tommylemon/unitauto/blob/master/UnitAuto-Java-Demo/src/main/resources/static/md/lib/codemirror/mode/smarty/index.html Basic initialization of CodeMirror with the 'smarty' mode. Use this for standard Smarty templates. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, mode: "smarty" }); ```