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
// MyObject.java: https://gist.github.com/bjpeterdelacruz/b1a5b14f3d222fb30468b6edf4f3ce82 | |
import java.util.stream.IntStream; | |
public class Main { | |
public static void main(String[] args) { | |
Runnable runnableA = MyObject::doSomething; | |
Runnable runnableB = MyObject::reinitialize; | |
for (var idx = 0; idx < 1000; idx++) { | |
var threads = IntStream.range(0, 1000) |
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 final class MyObject { | |
private static int counter = 0; | |
private static Object lock = new Object(); | |
public static void doSomething() { | |
synchronized (lock) { | |
for (int i = 0; i < 100; i++) { | |
counter++; | |
} | |
} |
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
import java.math.BigDecimal; | |
import javax.servlet.http.HttpServletRequest; | |
import org.springframework.validation.Errors; | |
import org.springframework.validation.Validator; | |
public class BillValidator implements Validator { | |
private HttpServletRequest request; | |
public void setRequest(HttpServletRequest 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
public void doSomething(String recordId) { | |
log.debug("Deficiency list for recordId: {} - START", recordId); | |
Instant start = Instant.now(); | |
try { | |
// do something | |
} finally { | |
Instant end = Instant.now(); | |
Duration duration = Duration.between(start, end); | |
log.debug("Deficiency list for recordId: {} - END, millis: {}", recordId, duration.toMillis()); |
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
var input = "A%20&%20B%20Company"; | |
var output = $('<textarea/>').html(unescape(input).trim()).text(); | |
// output = "A & B Company" |
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
package gov.ehawaii.swhv.utils; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.regex.Pattern; | |
import lombok.NonNull; | |
public final class SecurityUtils { | |
private final static List<String> MALICIOUS_STRING_LIST = new ArrayList<>(); |
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
// PHP 5 | |
$m = new MongoClient(); | |
$db = $m->test; | |
$collection = $db->todos; | |
$collection->insert(array("name" => $name)); | |
// PHP 7 | |
$m = new MongoDB\Driver\Manager(); | |
$bulk = new MongoDB\Driver\BulkWrite; | |
$bulk->insert(array("name" => $name)); |
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
/* Credit: https://github.com/EpicVoyage/pobox-regex */ | |
var pos = $(this).val().search(/(?:P(?:ost(?:al)?)?[\W\s]*(?:(?:O(?:ffice)?[\W\s]*)?B(?:ox|in|\b|\d)|o(?:ffice|\b)(?:[\W\s]*\d)|code)|b(?:o*x|i*n)[\W\s\b]*\d)|(?:P+[\W\s]*O+[\W\s]*)/i); | |
if (pos >= 0) { // P.O. box address was entered, so disable Submit button and display warning message | |
$("#submit_primary").attr("disabled", true); | |
if ($("#element_2_warning").length == 0) { | |
var text = "<div class='alert alert-warning' style='font-size: 12pt' id='element_2_warning'><strong style='color: #FF0000'>"; | |
text = text + "Street Address only, no P.O. Box.</strong></div>"; | |
$(text).insertBefore($("#li_2")); | |
} |
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
var logoutUrl = "https://test-swhv.ehawaii.gov/swhv-wikiflow/logout.php"; | |
var refreshUrl = "https://test-swhv.ehawaii.gov/swhv-wikiflow/refresh.html"; | |
function displayTimeOutWarningMessage() { | |
var thirtyMinutes = 1000 * 60 * 30; | |
var fifteenMinutes = thirtyMinutes / 2; | |
var lastActivity = new Date().getTime(); | |
var checkTimeOut = function() { | |
var currentTime = new Date().getTime(); | |
if (currentTime >= lastActivity + fifteenMinutes) { |
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
-- Find data for May 8, 2018 only. | |
-- WRONG | |
SELECT * FROM inbox WHERE datetime >= date('2018-05-08') and datetime < date('2018-05-08'); | |
-- Correct | |
SELECT * FROM inbox WHERE datetime >= date('2018-05-08') and datetime < date('2018-05-08') + interval 1 day; |
NewerOlder