Skip to content

Instantly share code, notes, and snippets.

@ballerina-github-bot
ballerina-github-bot / xml_from_json_conversion.bal
Created September 25, 2023 06:03
examples/xml-from-json-conversion
import ballerina/io;
import ballerina/xmldata;
public function main() returns error? {
// Creates a JSON value.
json jsonValue = {"Store": {
"@id": "AST",
"name": "Anne",
"address": {
"street": "Main",
@ballerina-github-bot
ballerina-github-bot / xml_to_json_conversion.bal
Created September 25, 2023 06:03
examples/xml-to-json-conversion
import ballerina/io;
import ballerina/xmldata;
public function main() returns error? {
// Creates an XML value.
xml xmlValue = xml `<Store id="AST">
<name>Anne</name>
<address>
<street>Main</street>
<city>94</city>
@ballerina-github-bot
ballerina-github-bot / environment_variables.bal
Created September 25, 2023 06:03
examples/environment-variables
import ballerina/io;
import ballerina/os;
public function main() {
// Returns the environment variable value associated with the `HTTP_PORT`.
string port = os:getEnv("HTTP_PORT");
io:println("HTTP_PORT: ", port);
// Returns the username of the current user.
string username = os:getUsername();
@ballerina-github-bot
ballerina-github-bot / xslt_transformation.bal
Created September 25, 2023 06:03
examples/xslt-transformation
import ballerina/io;
import ballerina/xslt;
public function main() returns error? {
// Gets an `XML` value, which needs to be transformed.
xml sourceXml = getXml();
// Gets an `XSL` style sheet represented in an XML value.
xml xsl = getXsl();
// Transforms the `XML` content to another format.
// For details, see https://lib.ballerina.io/ballerina/xslt/latest#transform.
@ballerina-github-bot
ballerina-github-bot / uuid_operations.bal
Created September 25, 2023 06:03
examples/uuid-operations
import ballerina/io;
import ballerina/uuid;
public function main() returns error? {
// Tests a string to see if it is a valid UUID.
boolean valid = uuid:validate("4397465e-35f9-11eb-adc1-0242ac120002");
io:println("UUID validated: ", valid.toString());
// Detects the RFC version of a UUID.
uuid:Version v = check uuid:getVersion(
@ballerina-github-bot
ballerina-github-bot / uuid_generation.bal
Created September 25, 2023 06:03
examples/uuid-generation
import ballerina/io;
import ballerina/uuid;
public function main() returns error? {
// Generates a UUID of type 1 as a string.
string uuid1String = uuid:createType1AsString();
io:println("UUID of type 1 as a string: ", uuid1String);
// Generates a UUID of type 1 as a UUID record.
uuid:Uuid uuid1Record = check uuid:createType1AsRecord();
@ballerina-github-bot
ballerina-github-bot / manage_scheduled_jobs.bal
Created September 25, 2023 06:03
examples/manage-scheduled-jobs
import ballerina/io;
import ballerina/lang.runtime;
import ballerina/task;
import ballerina/time;
// Creates a job to be executed by the scheduler.
class Job {
*task:Job;
int i = 1;
@ballerina-github-bot
ballerina-github-bot / task_one_time_job_execution.bal
Created September 25, 2023 06:03
examples/task-one-time-job-execution
import ballerina/io;
import ballerina/lang.runtime;
import ballerina/task;
import ballerina/time;
// Creates a job to be executed by the scheduler.
class Job {
*task:Job;
int i = 1;
@ballerina-github-bot
ballerina-github-bot / task_frequency_job_execution.bal
Created September 25, 2023 06:03
examples/task-frequency-job-execution
import ballerina/io;
import ballerina/lang.runtime;
import ballerina/task;
// Creates a job to be executed by the scheduler.
class Job {
*task:Job;
int i = 1;
@ballerina-github-bot
ballerina-github-bot / random_numbers.bal
Created September 25, 2023 06:03
examples/random-numbers
import ballerina/io;
import ballerina/random;
public function main() returns error? {
// Generates a random decimal number between 0.0 and 1.0.
float randomDecimal = random:createDecimal();
io:println("Random decimal number: ", randomDecimal);
// Generates a random number between the given start(inclusive) and end(exclusive) values.
int randomInteger = check random:createIntInRange(1, 100);