### Dockerfile Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/dockerfile/index.html A sample Dockerfile demonstrating common instructions for setting up a Ghost blogging platform environment. This includes installing dependencies, downloading Ghost, and configuring the application. ```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"] ``` -------------------------------- ### Test with OpenCms Setup Source: https://github.com/alkacon/opencms-core/blob/master/test/README-Junit-Jupiter.md Example of a test class that requires an OpenCms instance setup. Override $openCmsSetUp to configure the OpenCms environment. ```java public class TestFoo extends OpenCmsTestRunner { @Override @BeforeAll public void $openCmsSetUp(TestInfo testInfo) { setupOpenCms(testInfo, "simpletest", "/"); } @Test public void testSomething() throws Exception { CmsObject cms = getCmsObject(); assertNotNull(cms); } } ``` -------------------------------- ### Prelude Installation in LiveScript Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/livescript/index.html A meta-function to install the prelude into a target object. ```livescript # meta export installPrelude = !(target) -> unless target.prelude?isInstalled target <<< out$ # using out$ generated by livescript target <<< target.prelude.isInstalled = true export prelude = out$ ``` -------------------------------- ### Shell Script Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/shell/index.html A shell script demonstrating repository cloning, HTTPS credential generation using OpenSSL, and starting a Node.js server. This is useful for setting up development environments. ```shell #!/bin/bash # clone the repository git clone http://github.com/garden/tree # generate HTTPS credentials cd tree openssl genrsa -aes256 -out https.key 1024 openssl req -new -nodes -key https.key -out https.csr openssl x509 -req -days 365 -in https.csr -signkey https.key -out https.crt cp https.key{,.orig} openssl rsa -in https.key.orig -out https.key # start the server in HTTPS mode cd web sudo node ../server.js 443 'yes' >> ../node.log & # here is how to stop the server for pid in `ps aux | grep 'node ../server.js' | awk '{print $2}'` ; do sudo kill -9 $pid 2> /dev/null done exit 0 ``` -------------------------------- ### ProtoBuf v2 Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/protobuf/index.html An example demonstrating the syntax for Protocol Buffers version 2, including messages, fields, enums, and options. ```protobuf package addressbook; message Address { required string street = 1; required string postCode = 2; } message PhoneNumber { required string number = 1; } message Person { optional int32 id = 1; required string name = 2; required string surname = 3; optional Address address = 4; repeated PhoneNumber phoneNumbers = 5; optional uint32 age = 6; repeated uint32 favouriteNumbers = 7; optional string license = 8; enum Gender { MALE = 0; FEMALE = 1; } optional Gender gender = 9; optional fixed64 lastUpdate = 10; required bool deleted = 11 [default = false]; } ``` -------------------------------- ### Install CodeMirror via npm Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/README.md Install the CodeMirror library using npm. Ensure Node.js is installed. ```bash npm install codemirror ``` -------------------------------- ### SQL Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/sql/index.html Demonstrates various SQL syntax elements including keywords, variables, aliases, data types, and comments. This example showcases the highlighting capabilities of the SQL mode. ```sql -- SQL Mode for CodeMirror SELECT SQL_NO_CACHE DISTINCT @var1 AS `val1`, @'val2', @global.`sql_mode`, 1.1 AS `float_val`, .14 AS `another_float`, 0.09e3 AS `int_with_esp`, 0xFA5 AS `hex`, x'fa5' AS `hex2`, 0b101 AS `bin`, b'101' AS `bin2`, DATE '1994-01-01' AS `sql_date`, { T "1994-01-01" } AS `odbc_date`, 'my string', _utf8'your string', N'her string', TRUE, FALSE, UNKNOWN FROM DUAL -- space needed after '--' /* multiline comment! */ LIMIT 1 OFFSET 0; ``` -------------------------------- ### ProtoBuf v3 Syntax Example with Imports and Options Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/protobuf/index.html An example showcasing Protocol Buffers version 3 syntax, featuring imports, options, messages, fields, enums, and timestamps. ```protobuf syntax = "proto3"; package tutorial; import "google/protobuf/timestamp.proto"; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; option csharp_namespace = "Google.Protobuf.Examples.AddressBook"; message Person { string name = 1; int32 id = 2; // Unique ID number for this person. string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { string number = 1; PhoneType type = 2; } repeated PhoneNumber phones = 4; google.protobuf.Timestamp last_updated = 5; } // Our address book file is just one of these. message AddressBook { repeated Person people = 1; } service Test { rpc SayHello (HelloRequest) returns (HelloReply) {} rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} } ``` -------------------------------- ### Factor Code Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/factor/index.html A simple time server example written in the Factor programming language. It demonstrates basic Factor syntax for defining functions, using accessors, and setting up a threaded server. ```Factor ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. ! A simple time server USING: accessors calendar calendar.format io io.encodings.ascii io.servers kernel threads ; IN: time-server : handle-time-client ( -- ) now timestamp>rfc822 print ; : ( -- threaded-server ) ascii "time-server" >>name 1234 >>insecure [ handle-time-client ] >>handler ; : start-time-server ( -- ) start-server drop ; MAIN: start-time-server ``` -------------------------------- ### Turtle Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/turtle/index.html An example of RDF data written in Turtle syntax. This illustrates the structure and prefixes used in Turtle files. ```turtle @prefix foaf: . @prefix geo: . @prefix rdf: . a foaf:Person; foaf:interest ; foaf:based_near [ geo:lat "34.0736111" ; geo:lon "-118.3994444" ] ``` -------------------------------- ### Tern Server Setup and Keybindings Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/demo/tern.html Initializes the Tern server with ECMAScript definitions and configures CodeMirror keybindings for Tern features. This setup is essential for enabling code intelligence. ```javascript function getURL(url, c) { var xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.send(); xhr.onreadystatechange = function() { if (xhr.readyState != 4) return; if (xhr.status < 400) return c(null, xhr.responseText); var e = new Error(xhr.responseText || "No response"); e.status = xhr.status; c(e); }; } var server; getURL("https://unpkg.com/tern/defs/ecmascript.json", function(err, code) { if (err) throw new Error("Request for ecmascript.json: " + err); server = new CodeMirror.TernServer({ defs: [JSON.parse(code)] }); editor.setOption("extraKeys", { "Ctrl-Space": function(cm) { server.complete(cm); }, "Ctrl-I": function(cm) { server.showType(cm); }, "Ctrl-O": function(cm) { server.showDocs(cm); }, "Alt-.": function(cm) { server.jumpToDef(cm); }, "Alt-,": function(cm) { server.jumpBack(cm); }, "Ctrl-Q": function(cm) { server.rename(cm); }, "Ctrl-.": function(cm) { server.selectName(cm); } }); editor.on("cursorActivity", function(cm) { server.updateArgHints(cm); }); }); var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, mode: "javascript" }); ``` -------------------------------- ### RPM Spec File Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/rpm/index.html A complete example of an RPM spec file, demonstrating the structure and directives recognized by the RPM spec mode in CodeMirror. ```rpm-spec # # spec file for package minidlna # # Copyright (c) 2011, Sascha Peilicke # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. Name: libupnp6 Version: 1.6.13 Release: 0 Summary: Portable Universal Plug and Play (UPnP) SDK Group: System/Libraries License: BSD-3-Clause Url: http://sourceforge.net/projects/pupnp/ Source0: http://downloads.sourceforge.net/pupnp/libupnp-%{version}.tar.bz2 BuildRoot: %{\\_tmppath}/%{name}-%{version}-build %description The portable Universal Plug and Play (UPnP) SDK provides support for building UPnP-compliant control points, devices, and bridges on several operating systems. %package -n libupnp-devel Summary: Portable Universal Plug and Play (UPnP) SDK Group: Development/Libraries/C and C++ Provides: pkgconfig(libupnp) Requires: %{name} = %{version} %description -n libupnp-devel The portable Universal Plug and Play (UPnP) SDK provides support for building UPnP-compliant control points, devices, and bridges on several operating systems. %prep %setup -n libupnp-%{version} %build %configure --disable-static make %{\?_smp_mflags} %install %makeinstall find %{buildroot} -type f -name '\*.la' -exec rm -f {} \; %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files %defattr(-,root,root,-) %doc ChangeLog NEWS README TODO %{\\_libdir}/libixml.so.\* %{\\_libdir}/libthreadutil.so.\* %{\\_libdir}/libupnp.so.\* %files -n libupnp-devel %defattr(-,root,root,-) %{\\_libdir}/pkgconfig/libupnp.pc %{\\_libdir}/libixml.so %{\\_libdir}/libthreadutil.so %{\\_libdir}/libupnp.so %{\\_includedir}/upnp/ %changelog ``` -------------------------------- ### YAML Example: Shopping List Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/yaml/index.html Shows a simple YAML list format for a shopping list. ```yaml # Shopping list [milk, pumpkin pie, eggs, juice] ``` -------------------------------- ### YAML Example: Favorite Movies Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/yaml/index.html Demonstrates basic YAML list syntax for a collection of items. ```yaml --- # Favorite movies - Casablanca - North by Northwest - The Man Who Wasn't There --- ``` -------------------------------- ### Section Header Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/rst/index.html Shows how to create section headers by underlining the title with a punctuation character. ```rst ==================== This is a heading ==================== ``` -------------------------------- ### Get Current Token String Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/doc/manual.html Use `current()` to get the string content between the start of the current token and the current stream position. ```javascript stream.current() → string ``` -------------------------------- ### Publish Setup Project Source: https://github.com/alkacon/opencms-core/blob/master/test/data/scripts/script_publish.txt This script switches to the '_setupProject', unlocks it, and then publishes it, waiting for the process to complete. Ensure the project name is correctly configured. ```bash # Switch to the setup project setCurrentProject "_setupProject" # Publish the project unlockCurrentProject publishProjectAndWait ``` -------------------------------- ### Test without OpenCms Setup Source: https://github.com/alkacon/opencms-core/blob/master/test/README-Junit-Jupiter.md Example of a test class that does not require an OpenCms instance. Avoid overriding $openCmsSetUp if no OpenCms setup is needed. ```java public class TestFooUtil extends OpenCmsTestRunner { @Test public void testSomething() { assertEquals("foo", normalize(" foo ")); } } ``` -------------------------------- ### CMakeLists.txt Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/cmake/index.html A sample CMakeLists.txt file demonstrating common CMake commands and syntax. This is used to showcase the CMake mode's highlighting capabilities. ```cmake # vim: syntax=cmake if(NOT CMAKE_BUILD_TYPE) # default to Release build for GCC builds set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif() message(STATUS "cmake version ${CMAKE_VERSION}") if(POLICY CMP0025) cmake_policy(SET CMP0025 OLD) # report Apple's Clang as just Clang endif() if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH endif() project (x265) cmake_minimum_required (VERSION 2.8.8) # OBJECT libraries require 2.8.8 include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckSymbolExists) include(CheckCXXCompilerFlag) # X265_BUILD must be incremented each time the public API is changed set(X265_BUILD 48) configure_file("${PROJECT_SOURCE_DIR}/x265.def.in" "${PROJECT_BINARY_DIR}/x265.def") configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in" "${PROJECT_BINARY_DIR}/x265_config.h") SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") # System architecture detection string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC) set(X86_ALIASES x86 i386 i686 x86_64 amd64) list(FIND X86_ALIASES "${SYSPROC}" X86MATCH) if("${SYSPROC}" STREQUAL "" OR X86MATCH GREATER "-1") message(STATUS "Detected x86 target processor") set(X86 1) add_definitions(-DX265_ARCH_X86=1) if("${CMAKE_SIZEOF_VOID_P}" MATCHES 8) set(X64 1) add_definitions(-DX86_64=1) endif() elseif(${SYSPROC} STREQUAL "armv6l") message(STATUS "Detected ARM target processor") set(ARM 1) add_definitions(-DX265_ARCH_ARM=1 -DHAVE_ARMV6=1) else() message(STATUS "CMAKE_SYSTEM_PROCESSOR value \"${CMAKE_SYSTEM_PROCESSOR}\" is unknown") message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}") endif() if(UNIX) list(APPEND PLATFORM_LIBS pthread) find_library(LIBRT rt) if(LIBRT) list(APPEND PLATFORM_LIBS rt) endif() find_package(Numa) if(NUMA_FOUND) list(APPEND CMAKE_REQUIRED_LIBRARIES ${NUMA_LIBRARY}) check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2) if(NUMA_V2) add_definitions(-DHAVE_LIBNUMA) message(STATUS "libnuma found, building with support for NUMA nodes") list(APPEND PLATFORM_LIBS ${NUMA_LIBRARY}) link_directories(${NUMA_LIBRARY_DIR}) include_directories(${NUMA_INCLUDE_DIR}) endif() endif() mark_as_advanced(LIBRT NUMA_FOUND) endif(UNIX) if(X64 AND NOT WIN32) option(ENABLE_PIC "Enable Position Independent Code" ON) else() option(ENABLE_PIC "Enable Position Independent Code" OFF) endif(X64 AND NOT WIN32) # Compiler detection if(CMAKE_GENERATOR STREQUAL "Xcode") set(XCODE 1) endif() if (APPLE) add_definitions(-DMACOS) endif() ``` -------------------------------- ### Create Temporary Project Source: https://github.com/alkacon/opencms-core/blob/master/test/data/scripts/script_base.txt Creates a temporary project for setup purposes. This is a preliminary step before configuring the project. ```bash createTempfileProject ``` -------------------------------- ### Get Viewport Range Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/doc/manual.html Returns the start (inclusive) and end (exclusive) of the currently rendered portion of the document. ```javascript cm.getViewport() → {from: number, to: number} ``` -------------------------------- ### Pascal Syntax Examples Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/pascal/index.html Demonstrates basic Pascal syntax including loops, conditionals, and case statements. ```pascal (* Example Pascal code *) while a <> b do writeln('Waiting'); if a > b then writeln('Condition met') else writeln('Condition not met'); for i := 1 to 10 do writeln('Iteration: ', i:1); repeat a := a + 1 until a = 10; case i of 0: write('zero'); 1: write('one'); 2: write('two') end; ``` -------------------------------- ### Get Current Token Column Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/doc/manual.html Use `column()` to retrieve the starting column of the current token, accounting for tab characters. ```javascript stream.column() → integer ``` -------------------------------- ### Explicit Markup Block Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/rst/index.html Demonstrates the basic structure of an explicit markup block, which starts with '.. ' and is terminated by the next paragraph at the same indentation level. ```rst .. _directives: Directives ---------- A directive (:duref:`ref `) is a generic block of explicit markup. ``` -------------------------------- ### Objective-C Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/clike/index.html Shows Objective-C syntax including multi-line comments, framework imports, enums, class extensions, properties, and method implementations. Requires 'MyClass.h', 'AFramework', and 'BFrameworkModule'. ```objectivec /* This is a longer comment That spans two lines */ #import "MyClass.h" #import @import BFrameworkModule; NS_ENUM(SomeValues) { aValue = 1; }; // A Class Extension with some properties @interface MyClass () @property(atomic, readwrite, assign) NSInteger anInt; @property(nonatomic, strong, nullable) NSString *aString; @end @implementation YourAppDelegate - (instancetype)initWithString:(NSString *)aStringVar { if ((self = [super init])) { aString = aStringVar; } return self; } - (BOOL)doSomething:(float)progress { NSString *myString = @"This is a ObjC string %f "; myString = [[NSString stringWithFormat:myString, progress] stringByAppendingString:self.aString]; return myString.length > 100 ? NO : YES; } @end ``` -------------------------------- ### Stylus Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/stylus/index.html Demonstrates basic Stylus syntax including variables, nested rules, and mixins. ```stylus /* Stylus mode */ #id, .class, article font-family Arial, sans-serif #id, .class, article { font-family: Arial, sans-serif; } // Variables font-size-base = 16px line-height-base = 1.5 font-family-base = "Helvetica Neue", Helvetica, Arial, sans-serif text-color = lighten(#000, 20%) body { font: 400 16px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif; color: #333; } // Variables link-color = darken(#428bca, 6.5%) link-hover-color = darken(link-color, 15%) link-decoration = none link-hover-decoration = false // Mixin tab-focus() { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } a { color: link-color if link-decoration { text-decoration: link-decoration } &:hover, &:focus { color: link-hover-color } if link-hover-decoration { text-decoration: link-hover-decoration } &:focus { tab-focus() } } a { color: #3782c4; text-decoration: none; } a:hover, a:focus { color: #2f6ea7; } a:focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } ``` -------------------------------- ### Verify Build Configuration Source: https://github.com/alkacon/opencms-core/blob/master/GRADLE-MIGRATION.md Run the help task in a clean environment to ensure the build configures successfully after updating plugin resolution settings. ```bash ./gradlew help ``` -------------------------------- ### Oz Code Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/oz/index.html An example of Oz code demonstrating function declarations, recursion, and threading. ```oz declare fun {Ints N Max} if N == Max then nil else {Delay 1000} N|{Ints N+1 Max} end end fun {Sum S Stream} case Stream of nil then S [] H|T then S|{Sum H+S T} end end local X Y in thread X = {Ints 0 1000} end thread Y = {Sum 0 X} end {Browse Y} end ``` -------------------------------- ### C Language Example with ZMQ Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/clike/index.html Demonstrates C code using the ZeroMQ library for inter-process communication, including thread creation and message handling. Requires ZeroMQ and pthreads. ```c /* C demo code */ #include #include #include #include #include #include #include typedef struct { void* arg_socket; zmq_msg_t* arg_msg; char* arg_string; unsigned long arg_len; int arg_int, arg_command; int signal_fd; int pad; void* context; sem_t sem; } acl_zmq_context; #define p(X) (context->arg_##X) void* zmq_thread(void* context_pointer) { acl_zmq_context* context = (acl_zmq_context*)context_pointer; char ok = 'K', err = 'X'; int res; while (1) { while ((res = sem_wait(&context->sem)) == EINTR); if (res) {write(context->signal_fd, &err, 1); goto cleanup;} switch(p(command)) { case 0: goto cleanup; case 1: p(socket) = zmq_socket(context->context, p(int)); break; case 2: p(int) = zmq_close(p(socket)); break; case 3: p(int) = zmq_bind(p(socket), p(string)); break; case 4: p(int) = zmq_connect(p(socket), p(string)); break; case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break; case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break; case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break; case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break; case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break; } p(command) = errno; write(context->signal_fd, &ok, 1); } cleanup: close(context->signal_fd); free(context_pointer); return 0; } void* zmq_thread_init(void* zmq_context, int signal_fd) { acl_zmq_context* context = malloc(sizeof(acl_zmq_context)); pthread_t thread; context->context = zmq_context; context->signal_fd = signal_fd; sem_init(&context->sem, 1, 0); pthread_create(&thread, 0, &zmq_thread, context); pthread_detach(thread); return context; } ``` -------------------------------- ### XML/HTML Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/xml/index.html An example of XML/HTML content that can be edited with the CodeMirror XML mode. The indentation attempts to be intuitive. ```html HTML Example The indentation tries to be somewhat "do what I mean"... but might not match your style. ``` -------------------------------- ### Forth Insertion Sort Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/forth/index.html An example of an insertion sort algorithm implemented in Forth, demonstrating Forth syntax. ```text/x-forth : cell- 1 cells - ; : insert ( start end -- start ) dup @ >r ( r: v ) begin 2dup < while r@ over cell- @ < while cell- dup @ over cell+ ! repeat then r> swap ! ; : sort ( array len -- ) 1 ?do dup i cells + insert loop drop ; ``` -------------------------------- ### D Compile-Time String Formatting Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/d/index.html Demonstrates using the `Format` template to create strings at compile time, similar to `string.format`. This is useful for generating formatted strings without runtime overhead. ```d import std.metastrings; import std.stdio; void main() { string s = Format!("Arg %s = %s", "foo", 27); writefln(s); // "Arg foo = 27" } ``` -------------------------------- ### Twig Template Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/twig/index.html A basic example of a Twig template demonstrating inheritance, blocks, loops with conditions, and variable assignment. ```twig {% extends "layout.twig" %} {% block title %}CodeMirror: Twig mode{% endblock %} {# this is a comment #} {% block content %} {% for foo in bar if foo.baz is divisible by(3) %} Hello {{ foo.world }} {% else %} {% set msg = "Result not found" %} {% include "empty.twig" with { message: msg } %} {% endfor %} {% endblock %} ``` -------------------------------- ### N-Triples Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/ntriples/index.html Example of N-Triples syntax, including URIs, literals, and blank nodes. This format is well-supported by the N-Triples mode. ```text . "literal 1" . _:bnode3 . _:bnode4 "literal 2"@lang . _:bnode5 "literal 3"^^ . ``` -------------------------------- ### JSON-LD Example Data Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/javascript/json-ld.html An example of JSON-LD data structure, including context, name, description, image, and geographical coordinates. ```json { "@context": { "name": "http://schema.org/name", "description": "http://schema.org/description", "image": { "@id": "http://schema.org/image", "@type": "@id" }, "geo": "http://schema.org/geo", "latitude": { "@id": "http://schema.org/latitude", "@type": "xsd:float" }, "longitude": { "@id": "http://schema.org/longitude", "@type": "xsd:float" }, "xsd": "http://www.w3.org/2001/XMLSchema#" }, "name": "The Empire State Building", "description": "The Empire State Building is a 102-story landmark in New York City.", "image": "http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg", "geo": { "latitude": "40.75", "longitude": "73.98" } } ``` -------------------------------- ### Jinja2 Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/jinja2/index.html Demonstrates various Jinja2 template constructs including comments, loops, conditionals, variable access, function calls, includes, and variable assignments. ```jinja2 {# this is a comment #} {%- for item in li -%}
  • {{ item.label }}
  • {% endfor -%} {{ item.sand == true and item.keyword == false ? 1 : 0 }} {{ app.get(55, 1.2, true) }} {% if app.get('_route') == ('_home') %}home{% endif %} {% if app.session.flashbag.has('message') %} {% for message in app.session.flashbag.get('message') %} {{ message.content }} {% endfor %} {% endif %} {{ path('_home', {'section': app.request.get('section')}) }} {{ path('_home', { 'section': app.request.get('section'), 'boolean': true, 'number': 55.33 }) }} {% include ('test.incl.html.twig') %} # for item in seq:
  • {{ item }}
  • ## this comment is ignored # endfor # set text = "Multiline text" # for href, caption in [('index.html', 'Index'), ('about.html', 'About')]:
  • {{ caption }}
  • # endfor ``` -------------------------------- ### HTTP Request Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/http/index.html This snippet shows an example of an HTTP request with headers and a body, as highlighted by the CodeMirror HTTP mode. ```http POST /somewhere HTTP/1.1 Host: example.com If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT Content-Type: application/x-www-form-urlencoded; charset=utf-8 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11 This is the request body! ``` -------------------------------- ### OCaml: Triangle graphics with GLUT Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/mllike/index.html Initializes GLUT, sets up display mode, creates a window, and renders a rotating triangle. ```ocaml let () = ignore( Glut.init Sys.argv ) Glut.initDisplayMode ~double_buffer:true () ignore (Glut.createWindow ~title:"OpenGL Demo") let angle t = 10. *. t *. t let render () = GlClear.clear [ `color ] GlMat.load_identity () GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. () GlDraw.begins `triangles List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.] GlDraw.ends () Glut.swapBuffers () GlMat.mode `modelview Glut.displayFunc ~cb:render Glut.idleFunc ~cb:(Some Glut.postRedisplay) Glut.mainLoop () ``` -------------------------------- ### Get Repository and Login Session Source: https://github.com/alkacon/opencms-core/blob/master/src/org/opencms/repository/package.html Obtain a configured repository instance by name and log in to get a session for VFS operations. ```Java I_CmsRepository repository = OpenCms.getRepositoryManager().getRepository(repository_name); I_CmsRepositorySession session = repository.login(username, password); ``` -------------------------------- ### Basic R Syntax and Output Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/r/index.html Demonstrates basic R syntax for creating lists, printing objects, and accessing elements. Shows how to use sprintf for formatted output. ```r X <- list(height = 5.4, weight = 54) cat("Printing objects: "); print(X) print("Accessing individual elements:") cat(sprintf("Your height is %s and your weight is %s\n", X$height, X$weight)) ``` -------------------------------- ### Example Solr HTTP Response Source: https://github.com/alkacon/opencms-core/blob/master/src/org/opencms/search/solr/README.md An example of the XML response received when querying a Solr server directly via its HTTP interface. ```xml 0 32 *:* 2 0 ... ... ``` -------------------------------- ### Swift Protocol and Struct Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/swift/index.html Illustrates Swift protocol and struct definitions for header views and their usage. ```swift protocol HeaderViewProtocol { func setTitle(\_ string: String) } struct AnyHeaderView { let view: UIView let headerView: HeaderViewProtocol init(view: T) where T: HeaderViewProtocol { self.view = view self.headerView = view } } let header = AnyHeaderView(view: myView) header.headerView.setTitle("hi") struct HeaderView { let view: UIView let setTitle: (String) -> () } var label = UILabel() let header = HeaderView(view: label) { str in label.text = str } header.setTitle("hello") ``` -------------------------------- ### VHDL Example Code Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/vhdl/index.html A VHDL code example demonstrating entity declaration, architecture, component instantiation, and a stimulus process for testing. ```vhdl LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY tb IS END tb; ARCHITECTURE behavior OF tb IS --Inputs signal a : unsigned(2 downto 0) := (others => '0'); signal b : unsigned(2 downto 0) := (others => '0'); --Outputs signal a_eq_b : std_logic; signal a_le_b : std_logic; signal a_gt_b : std_logic; signal i,j : integer; BEGIN -- Instantiate the Unit Under Test (UUT) uut: entity work.comparator PORT MAP ( a => a, b => b, a_eq_b => a_eq_b, a_le_b => a_le_b, a_gt_b => a_gt_b ); -- Stimulus process stim_proc: process begin for i in 0 to 8 loop for j in 0 to 8 loop a <= to_unsigned(i,3); --integer to unsigned type conversion b <= to_unsigned(j,3); wait for 10 ns; end loop; end loop; end process; END; ``` -------------------------------- ### GFM Task List Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/gfm/index.html Shows how to create incomplete and completed task list items in GFM. ```gfm - [ ] Incomplete task list item - [x] **Completed** task list item ``` -------------------------------- ### Solr Query Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/solr/index.html An example of a Solr query string. This is not executable code but demonstrates the syntax the Solr mode is designed to highlight. ```solr author:Camus title:"The Rebel" and author:Camus philosophy:Existentialism -author:Kierkegaard hardToSpell:Dostoevsky~ published:[194* TO 1960] and author:(Sartre or "Simone de Beauvoir") ``` -------------------------------- ### N-Quads Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/ntriples/index.html Example of N-Quads syntax, which extends N-Triples by adding a graph identifier. The N-Triples mode also handles this format. ```text . "literal 1" . _:bnode3 . _:bnode4 "literal 2"@lang . # if a graph label _:bnode5 "literal 3"^^ . ``` -------------------------------- ### Gas Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/gas/index.html Demonstrates the syntax highlighting for Gas (GNU Assembler) including multi-line and single-line comments, directives, and labels. ```gas .syntax unified .global main /* * A * multi-line * comment. */ @ A single line comment. main: push {sp, lr} ldr r0, =message bl puts mov r0, #0 pop {sp, pc} message: .asciz "Hello world!
    " ``` -------------------------------- ### Initialize CodeMirror with Swift Mode Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/swift/index.html Demonstrates how to initialize a CodeMirror editor instance with the Swift mode enabled. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-swift" }); ``` -------------------------------- ### DTD Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/dtd/index.html An example of a Document Type Definition (DTD) used for defining XML document structures. This can be used with the DTD mode in CodeMirror. ```dtd ]> ``` -------------------------------- ### WebAssembly Syntax Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/wast/index.html Demonstrates the syntax for a WebAssembly module with exported functions for factorial and addition. This is used to showcase the WebAssembly mode in CodeMirror. ```wast /* Example WebAssembly */ (module $foo (export "fac" (func $fac)) (export "plus" (func $plus)) (func $fac (type $t0) (param $p0 i64) (result i64) (if $I0 (result i64) (i64.lt_s (local.get $p0) (i64.const 1)) (then (i64.const 1)) (else (i64.mul (local.get $p0) (call $fac (i64.sub (local.get $p0) (i64.const 1))))))) (func $plus (param $x i32) (param $y i32) (result i32) (i32.add (local.get $x) (local.get $y)))) ``` -------------------------------- ### Elm Code Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/elm/index.html A basic example of Elm code demonstrating the use of Color, Graphics, and Time modules for creating a clock visualization. ```elm import Color exposing (..) import Graphics.Collage exposing (..) import Graphics.Element exposing (..) import Time exposing (..) main = Signal.map clock (every second) clock t = collage 400 400 [ filled lightGrey (ngon 12 110), outlined (solid grey) (ngon 12 110), hand orange 100 t, hand charcoal 100 (t/60), hand charcoal 60 (t/720) ] hand clr len time = let angle = degrees (90 - 6 * inSeconds time) in segment (0,0) (fromPolar (len,angle)) |> traced (solid clr) ``` -------------------------------- ### CodeMirror Initialization for Python Mode Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/python/index.html Demonstrates how to initialize CodeMirror with the Python mode, specifying version and other configuration options. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: {name: "python", version: 3, singleLineStringErrors: false}, lineNumbers: true, indentUnit: 4, matchBrackets: true }); ``` -------------------------------- ### ECL Syntax Highlighting Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/ecl/index.html Demonstrates ECL syntax highlighting with single-line and multi-line comments, import statements, record definitions, dataset creation, and output. ```ecl /* sample useless code to demonstrate ecl syntax highlighting this is a multiline comment! */ // this is a singleline comment! import ut; r := record string22 s1 := '123'; integer4 i1 := 123; end; #option('tmp', true); d := dataset('tmp::qb', r, thor); output(d); ``` -------------------------------- ### Get Token Type at Position Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/doc/manual.html A performance-optimized method to get only the type string of the token at a given position. Returns null for unstyled tokens. ```javascript cm.getTokenTypeAt(pos) ``` -------------------------------- ### Puppet Module Example Source: https://github.com/alkacon/opencms-core/blob/master/modules/org.opencms.base/static/editors/codemirror/dist/mode/puppet/index.html This snippet demonstrates a typical Puppet module structure for managing AutoMySQLBackup. It includes class definitions, parameter validation, and resource declarations for files and directories. ```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": source => 'puppet:///modules/automysqlbackup/AMB_README', } file { "${etc_dir}/AMB_LICENSE": 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 } } } ```