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
-- Generate DROP TABLE statements for tables that begin with "ap_form_" | |
SELECT CONCAT('DROP TABLE `', TABLE_NAME, '`;') AS queries | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_NAME LIKE 'ap_form_%' | |
-- Sample output: | |
-- DROP TABLE `ap_form_10792`; | |
-- DROP TABLE `ap_form_10792_review`; | |
-- DROP TABLE `ap_form_11763`; |
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 com.bjpeter.sampleapp.utils; | |
import com.bjpeter.sampleapp.services.ServiceLoader; | |
import com.bjpeter.sampleapp.services.TextService; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mockito; | |
import org.powermock.api.mockito.PowerMockito; | |
import org.powermock.core.classloader.annotations.PrepareForTest; |
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 com.bjpeter.sampleapp.utils; | |
import java.io.UnsupportedEncodingException; | |
import java.net.URLEncoder; | |
import org.apache.commons.lang3.StringUtils; | |
public WebUtils() { | |
private WebUtils() { | |
} |
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 Person { | |
private final int age; | |
public Person(int age) { this.age = age; } | |
@Override | |
public boolean equals(Object obj) { | |
return (obj instanceof Person) && this.age == ((Person) obj).age; | |
} |
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
protected void setFirstNameField(AcroFields form) throws IOException, DocumentException { | |
// Set font size. | |
form.setFieldProperty("first_name", "textsize", 10f, null); | |
// Set font to use. | |
final BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); | |
form.setFieldProperty("first_name", "textfont", font, null); | |
// The font size must be set first before setting the value of the field. | |
form.setField("first_name", value); | |
form.setFieldProperty("first_name", "setfflags", PdfFormField.FF_READ_ONLY, null); | |
} |
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
@RequestMapping(value = "pdf", headers = { "Accept=*/*", | |
"content-type=application/json,text/plain" }, method = RequestMethod.POST, produces = "application/pdf") | |
public ResponseEntity<byte[]> getPdf(@RequestBody Object object) { | |
Form form; | |
if (object instanceof Map) { | |
form = new ObjectMapper().convertValue(object, Form.class); | |
} | |
else { | |
try { | |
form = formService.getForm(Long.parseLong(object.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
private void send(String toAddress, String subject, String text, byte[] attachment) { | |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | |
mailSender.setHost(mailHost); | |
MimeMessage message = mailSender.createMimeMessage(); | |
MimeMessageHelper msgHelper = new MimeMessageHelper(message, true); | |
msgHelper.setSubject(subject); | |
msgHelper.setFrom(fromAddress); | |
msgHelper.setTo(toAddress); |
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.format("%1$#5s", book) does not throw an exception in Java 6, | |
// but it does in Java 7, so replace this code with a call to the method below, | |
// e.g. padWithZeroes(book, 5) | |
private static String padWithZeroes(String s, int length) { | |
if (s.length() >= length) { | |
return s; | |
} | |
int numZeroes = length - s.length(); | |
StringBuffer buffer = new StringBuffer(numZeroes); | |
for (int count = 0; count < numZeroes; count++) { |
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
<html> | |
<head> | |
<title>Enable and disable dropdown with jQuery</title> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script type="text/javascript"> | |
function enable_dropdown() { | |
jQuery("#items").removeAttr('disabled'); | |
} | |
function disable_dropdown() { | |
jQuery("#items").attr('disabled', 'disabled'); |
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; | |
$cursor = $collection->find(); | |
foreach ($cursor as $document) { | |
echo $document["name"] . "\n"; | |
} | |
// PHP 7 |