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
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
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
// 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
IEnumerator SpawnArrows() | |
{ | |
yield return new WaitForSeconds(startWait); | |
while (true) | |
{ | |
for (int i = 0; i < arrowCount; i++) { | |
if (!isStunned) { | |
// is archer facing right? | |
bool facingRight = ((int) _transform.rotation.eulerAngles.y) == 0; | |
// calculate origin of arrow (0.5 pixels to left or right of archer) |
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
using UnityEngine; | |
using System.Collections; | |
public class GameController : MonoBehaviour | |
{ | |
public GameObject hazard; | |
public Vector3 spawnValues; | |
public int hazardCount; | |
public float spawnWait; | |
public float startWait; |
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->update( | |
array("_id" => new MongoId($id)), | |
array('$set' => | |
array("title" => "MongoDB Tutorial") | |
) | |
); |
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 |
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)); |