Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 3aed4fc

Browse files
author
Dimitry Ivanov
committed
Added gifs
1 parent 9c5fe6f commit 3aed4fc

8 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ There are a lot of benefits for a programming language to have a [REPL](https://
88

99
Writing *whole* Java code in command line seems like an overkill. Creating a class, then main method, then call to `System.out.print()` to execute such simple as `Integer.MAX_VALUE` command seems like a long way. What's why ScriptJava is *not* completely Java REPL. For example, semicolons(`;`) are *mostly* optional. There are a lot of *build-ins* methods, that can save a coder a few keyboard strokes. So, yeah, to know the value of `Integer.MAX_VALUE` you just input `Integer.MAX_VALUE`.
1010

11-
// gif with Integer.MAX_VALUE
12-
// another gifs
11+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/1.gif)
12+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/2.gif)
13+
14+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/3.gif)
15+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/4.gif)
16+
17+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/5.gif)
18+
![](https://raw.githubusercontent.com/noties/ScriptJava/master/gif/6.gif)
1319

1420
## Build-in functions
1521
* **`bool()`** -> inspired by python's function. In short: `null`, `0`, or `""`(empty string) returns `false`. Defined in `Bool.java`

‎gif/1.gif‎

8.49 KB
Loading

‎gif/2.gif‎

20.6 KB
Loading

‎gif/3.gif‎

12.1 KB
Loading

‎gif/4.gif‎

14.8 KB
Loading

‎gif/5.gif‎

17.3 KB
Loading

‎gif/6.gif‎

18.6 KB
Loading

‎src/scriptjava/buildins/Network.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class Network {
2525
private static final String HTTP_GET = "GET";
2626
private static final String HTTP_POST = "POST";
2727

28+
private static final String USER_AGENT_KEY = "User-Agent";
29+
private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
30+
2831
public static String get(String url) {
2932
return http(url, HTTP_GET, null, null);
3033
}
@@ -53,9 +56,16 @@ private static String http(String url, String method, String body, Map<String, ?
5356
connection.setRequestMethod(method);
5457

5558
if (Bool.bool(properties)) {
59+
60+
if (!properties.containsKey(USER_AGENT_KEY)) {
61+
connection.setRequestProperty(USER_AGENT_KEY, USER_AGENT_VALUE);
62+
}
63+
5664
for (Map.Entry<String, ?> entry: properties.entrySet()) {
5765
connection.setRequestProperty(entry.getKey(), String.valueOf(entry.getValue()));
5866
}
67+
} else {
68+
connection.setRequestProperty(USER_AGENT_KEY, USER_AGENT_VALUE);
5969
}
6070

6171
if (HTTP_POST.equals(method)) {

0 commit comments

Comments
 (0)