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 static final ObjectMapper OM = new ObjectMapper(); | |
@Benchmark | |
public void jsonStringSerialization(final Blackhole blackhole) throws Exception { | |
byte[] obj = OM.writeValueAsBytes(randomString()); | |
blackhole.consume(new String(obj, 1, obj.length - 2, StandardCharsets.UTF_8)); | |
} | |
@Benchmark | |
public void jsonStringManual(final Blackhole blackhole) { |
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 static final ObjectMapper OM = new ObjectMapper(); | |
private static final String STR = "hello world - the quick brown fox jumps over " | |
+ "the lazy dog\r\n\r\nand here's " | |
+ "a random slash\\, and some \"s"; | |
@Benchmark | |
public void jsonStringSerialization(final Blackhole blackhole) throws Exception { | |
byte[] obj = OM.writeValueAsBytes(STR); | |
blackhole.consume(new String(obj, 1, obj.length - 2, StandardCharsets.UTF_8)); | |
} |
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 static final ObjectMapper OM = new ObjectMapper(); | |
public static String escapeString(Object o) { | |
if (o == null) { | |
return null; | |
} | |
try { | |
// The string is automatically quoted. Therefore, return a new string that | |
// doesn't contain those quotes (since the caller appends quotes themselves). | |
val bytes = OM.writeValueAsBytes(o.toString()); |
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 static String escapeString(Object o) { | |
if (o == null) { | |
return null; | |
} | |
String str = o.toString(); | |
if (str.contains("\\")) { | |
str = str.replace("\\", "\\\\"); | |
} | |
if (str.contains("\"")) { | |
str = str.replace("\"", "\\\""); |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.judepereira.keyremapping</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/hidutil</string> | |
<string>property</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
class State { | |
public static boolean someState; | |
} | |
class GoodTest { | |
@Test | |
public void checkState() { | |
assertFalse(State.someState); | |
} |
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
MyStubbornAPIInterface actualInstance = ... // Create it however you'd create your original instance. | |
MyStubbornAPIInterface proxiedInstance = (MyStubbornAPIInterface) Proxy.newProxyInstance(actualInstance.getClass().getClassLoader(), | |
new Class[]{MyStubbornAPIInterface.class}, (proxy, method, args) -> { | |
while (true) { | |
try { | |
return method.invoke(actualInstance, args); | |
} catch (MyThrottlingException e) { | |
try { | |
Thread.sleep(ThreadLocalRandom.current().nextInt(1, 5) * 1000L); | |
} catch (InterruptedException e) { |
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
#!/bin/bash | |
# Wrapper script for sending OTA updates to your ESP8266 running NodeMCU. | |
# See https://judepereira.com/blog/sending-ota-updates-over-wifi-to-your-esp8266/ | |
HOST=192.168.178.25 | |
PORT=8080 | |
for i in "$@"; do | |
FILE=$i |
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
-- Send OTA updates to remotely update lua scripts on your ESP8266. | |
-- | |
-- LICENCE: http://opensource.org/licenses/MIT | |
-- Created by Jude Pereira <contact@judepereira.com> | |
-- See https://judepereira.com/blog/sending-ota-updates-over-wifi-to-your-esp8266/ | |
srv = net.createServer(net.TCP) | |
current_file_name = nil |
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
http server as server | |
when server listen path: "/" as req | |
current = (redis get key: "count").result | |
if current == null | |
current = 0 | |
current = current + 1 | |
redis set key: "count" value: current | |
req write content: "This page has loaded {current} times.<br>Powered by https://gist.github.com/judepereira/c45f9080def481c0917af77c6b9e9d11" |
NewerOlder