This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JexlSandbox sandbox = new JexlSandbox(false); | |
sandbox.white("com.safe.Functions"); | |
JexlEngine jexl = new JexlBuilder().sandbox(sandbox).create(); | |
JexlExpression expression = jexl.createExpression(str); | |
JexlContext context = new MapContext(); | |
expression.evaluate(context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void handle(HttpRequest request) { | |
if (request.hasParameter("questionToBackend")) { | |
String expr = request.getParameter("questionToBackend")); | |
JexlEngine jexl = new JexlBuilder().create(); | |
JexlExpression expression = jexl.createExpression(expr); | |
JexlContext context = new MapContext(); | |
Object object = expression.evaluate(context); | |
handleResult(object); | |
} else { | |
callNextHandler(request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String str = "''.getClass().forName('java.lang.Runtime').getRuntime().exec('calc')"; | |
JexlEngine jexl = new JexlBuilder().create(); | |
JexlExpression expression = jexl.createExpression(str); | |
JexlContext context = new MapContext(); | |
e.evaluate(context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import ADC, Pin | |
import time | |
class LDR: | |
"""This class read a value from a light dependent resistor (LDR)""" | |
def __init__(self, pin, min_value=0, max_value=100): | |
""" | |
Initializes a new instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this class measures CO2 with MH-Z19B sensor | |
class MHZ19BSensor: | |
# initializes a new instance | |
def __init__(self, tx_pin, rx_pin, lights, co2_threshold): | |
self.uart = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=int(tx_pin), rx=int(rx_pin)) | |
self.lights = lights | |
self.co2_threshold = int(co2_threshold) | |
# measure CO2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
public B b; | |
} | |
class B { | |
public C[] array = new C[] { null }; | |
} | |
class C { | |
public String string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TranslateHttpCode { | |
public static void main(String[] args) { | |
for (String arg : args) { | |
int code = Integer.valueOf(arg); | |
System.out.printf("%d -> %s%n", code, translate(code)); | |
} | |
} | |
static String translate(int code) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tribonacci { | |
public static void main(String[] args) { | |
for (String arg : args) { | |
int n = Integer.valueOf(arg); | |
System.out.printf("Tribonacci(%d) = %d%n", n, tribonacci(n)); | |
} | |
} | |
static int tribonacci(int n) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fibonacci { | |
public static void main(String[] args) { | |
for (String arg : args) { | |
int n = Integer.valueOf(arg); | |
System.out.printf("Fibonacci(%d) = %d%n", n, fibonacci(n)); | |
} | |
} | |
static int fibonacci(int n) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StrangeYield { | |
public static void main(String[] args) { | |
go(0); | |
} | |
static void go(int n) { | |
System.out.println( | |
switch (n) { | |
case 42 -> "Fotry-two"; |