-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_highlight.Rmd
153 lines (121 loc) · 3.04 KB
/
code_highlight.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
title: "Code Hightlight"
author: "etibhar"
date: "4 October 2016"
output:
html_document:
highlight: pygments
---
```{r,echo=FALSE}
library(rmarkdown)
```
## Bash
```{r, engine='bash'}
#!/bin/bash
# bash trap command
trap bashtrap INT
# bash clear screen command
clear;
# bash trap function is executed when CTRL-C is pressed:
# bash prints message => Executing bash trap subrutine !
bashtrap()
{
echo "CTRL+C Detected !...executing bash trap !"
}
# for loop from 1/10 to 10/10
for a in `seq 1 10`; do
echo "$a/10 to Exit."
#sleep 1;
done
echo "Exit Bash Trap Example!!!"
```
## Basic
```{r, engine='basic', eval=F}
Declare Sub PrintArray()
Dim Numbers(1 To 10) As Integer
Dim Shared OtherNumbers(1 To 10) As Integer
Dim a As Integer
Numbers(1) = 1
Numbers(2) = 2
OtherNumbers(1) = 3
OtherNumbers(2) = 4
PrintArray ()
For a = 1 To 10
Print Numbers(a)
Next a
Sub PrintArray ()
Dim a As Integer
For a = 1 To 10
Print otherNumbers(a)
Next a
End Sub
```
## C
```{r, engine='c'}
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
```
## Java
```{r, engine='java', eval=F}
/*
Even Odd Number Example
This Java Even Odd Number Example shows how to check if the given
number is even or odd.
*/
public class FindEvenOrOddNumber {
public static void main(String[] args) {
//create an array of 10 numbers
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};
for(int i=0; i < numbers.length; i++){
/*
* use modulus operator to check if the number is even or odd.
* If we divide any number by 2 and reminder is 0 then the number is
* even, otherwise it is odd.
*/
if(numbers[i]%2 == 0)
System.out.println(numbers[i] + " is even number.");
else
System.out.println(numbers[i] + " is odd number.");
}
}
}
```
## Perl
```{r, engine='perl'}
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::Read;
my $workbook = ReadData ("test.xls");
print $workbook->[1]{A3} . "\n";
```
## Python
```{r, engine='python'}
import re
for test_string in ['555-1212', 'ILL-EGAL']:
if re.match(r'^\d{3}-\d{4}$', test_string):
print test_string, 'is a valid US local phone number'
else:
print test_string, 'rejected'
```