Skip to content

Instantly share code, notes, and snippets.

BJ Peter DeLaCruz bjpeterdelacruz

Block or report user

Report or block bjpeterdelacruz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
bjpeterdelacruz /
Last active Jan 11, 2018
How to send an e-mail message with a PDF attachment and an inline image
private void send(String toAddress, String subject, String text, byte[] attachment) {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper msgHelper = new MimeMessageHelper(message, true);
bjpeterdelacruz /
Last active Jan 13, 2018
How to set font size of field using iText 5
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);
// 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++) {
bjpeterdelacruz / gist:5d7e9c9eda0f8bbaa0073dfa13536b99
Created Oct 8, 2017
Enable and disable dropdown with jQuery
View gist:5d7e9c9eda0f8bbaa0073dfa13536b99
<title>Enable and disable dropdown with jQuery</title>
<script src=""></script>
<script type="text/javascript">
function enable_dropdown() {
function disable_dropdown() {
jQuery("#items").attr('disabled', 'disabled');
bjpeterdelacruz / Archer.cs
Last active Dec 15, 2016
How to Spawn Arrows
View Archer.cs
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)
bjpeterdelacruz / GameController.cs
Last active Dec 15, 2016
How to Spawn Hazards in Unity
View GameController.cs
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour
public GameObject hazard;
public Vector3 spawnValues;
public int hazardCount;
public float spawnWait;
public float startWait;
bjpeterdelacruz / update_php5_vs_php7.php
Created Nov 23, 2016
Updating a document in a MongoDB database (PHP 5 vs. PHP 7)
View update_php5_vs_php7.php
// PHP 5
$m = new MongoClient();
$db = $m->test;
$collection = $db->todos;
array("_id" => new MongoId($id)),
array('$set' =>
array("title" => "MongoDB Tutorial")
bjpeterdelacruz / findAll_php5_vs_php7.php
Created Nov 23, 2016
Retrieving all documents from MongoDB database (PHP 5 vs. PHP 7)
View findAll_php5_vs_php7.php
// PHP 5
$m = new MongoClient();
$db = $m->test;
$collection = $db->todos;
$cursor = $collection->find();
foreach ($cursor as $document) {
echo $document["name"] . "\n";
// PHP 7
bjpeterdelacruz / insert_php5_vs_php7.php
Last active Nov 13, 2018
Inserting a document into MongoDB database (PHP 5 vs. PHP 7)
View insert_php5_vs_php7.php
// 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));
View error.txt
Unable to compile class for JSP:
An error occurred at line: [60] in the generated java file: [/var/www/tomcat/8021-kauairpt/work/Catalina/localhost/kauairpt/org/apache/jsp/]
The method getDispatcherType() is undefined for the type HttpServletRequest
You can’t perform that action at this time.