Skip to content

Instantly share code, notes, and snippets.

View thanhxtruong's full-sized avatar

Thanh Truong thanhxtruong

View GitHub Profile
@thanhxtruong
thanhxtruong / SinglyLinkedList.py
Created March 16, 2019 11:22
Singly-linked List Python
# Node class
class Node:
def __init__(self, initial_data):
self.data = initial_data
self.next = None
# Singly-linked List class
class LinkedList:
def __init__(self):
self.head = None
@thanhxtruong
thanhxtruong / SinglyLinkedList.txt
Created March 15, 2019 18:37
Singly-linked List Pseudocode
# Append a list
ListAppend(list, newNode) {
if (list->head == null) {
list->head = newNode
list->tail = newNode
}
else {
list->tail->next = newNode
list->tail = newNode
}
@thanhxtruong
thanhxtruong / pagination.js
Created February 27, 2019 23:37
Pagination
$( document ).ready(function() {
pageSize = 1;
pagesCount = $(".content").length;
console.log(pagesCount);
var currentPage = 1;
/////////// PREPARE NAV ///////////////
var nav = '';
var totalPages = Math.ceil(pagesCount / pageSize);
@thanhxtruong
thanhxtruong / WindowsDisplayDemo.java
Created February 26, 2019 18:30
Windows Display Demo
// Use of Builder Pattern
WindowsDisplay windowDisplay = new WindowsBuilder()
.setRb(rb)
.setFXMLPath("UserLogin.fxml")
.build();
windowDisplay.displayScene();
@thanhxtruong
thanhxtruong / WindowsDisplay.java
Created February 26, 2019 18:29
Windows Display
/**
* The WindowsDisplay class is used to load FXML, set BundleResource (as needed),
* and pass an instance of mainApp and active Stage to the controller for use
* in other method calls defined in controller.
*
* Object for WindowsDisplay is instantiated using a WindowsBuilder, which is
* an instance of a builder pattern. Due to several optional parameters being
* used for constructing a WindowsDisplay, the builder design pattern was used.
*
* @param rb (optional) ResourceBundle for the language_files
@thanhxtruong
thanhxtruong / WindowsBuilder.java
Created February 26, 2019 18:29
Builder Design Pattern
/**
* This is a builder pattern for WindowsDisplay.
* The use of builder pattern makes it easier to add parameters to WindowsDisplay
* in the future to customize different types of FXML Loader.
* @author thanhtruong
*/
public class WindowsBuilder {
ResourceBundle rb;
String FXMLPath;
String title;
@thanhxtruong
thanhxtruong / FilteredAndSortedList.java
Created February 26, 2019 00:23
Filtered and Sorted List
// Set items into the TableView
customerTable.setItems(custDB.getCustomerList());
FilteredList<Customer> filteredCustomerByName = new FilteredList<>(
custDB.getCustomerList(), p -> true);
customerSearchText.textProperty().addListener((observable, oldValue, newValue) -> {
filteredCustomerByName.setPredicate(customer -> {
if((newValue.toString().isEmpty()) || (newValue.toString().equals(null))) {
return true;
@thanhxtruong
thanhxtruong / SingletonPattern.java
Created February 25, 2019 20:45
Singleton Design Pattern
public class AppointmentDB {
private static ObservableList<Appointment> apptListByCust;
private static ObservableList<Appointment> apptListByUser;
private static ObservableList<Appointment> allApptList;
private static ObservableList<Appointment> sortedList = FXCollections.observableArrayList();
private static Map<Integer, Map<Integer, ObservableList<String>>> apptMapByMonth;
private static Map<Integer, Map<Integer, ObservableList<Appointment>>> apptMapByWeek;
private static final AppointmentDB instance;
private String sqlStatement;
@thanhxtruong
thanhxtruong / concatenation.rpt
Created February 25, 2019 18:15
Crystal Report data concatenation
// Variable getter placed in the Details section of the report
// Each time a row is printed, the value is added to the variable and concatenated after filtering out duplicate values
whileprintingrecords;
stringvar Device;
if Device = "" then Device := {SPC_DEVICE.EQNO} + " " + {SPC_DEVICE_TYPE.NAME} + ", "
else if not ({SPC_DEVICE.EQNO} in Device) then Device := Device + {SPC_DEVICE.EQNO} + " " + {SPC_DEVICE_TYPE.NAME} + ", "
// Reset the variable to an emtpty String after each group is printed
// Place this variable in the Group Header section of the report to ensure the variable is reset for each group/table
whileprintingrecords;
@thanhxtruong
thanhxtruong / AppointmentByWeek.java
Created February 25, 2019 00:32
Display appointments by week
double topAnchor, botAnchor;
int rSpan;
// Calculate the number of rows to span across based on
// the number of hours for the appointment
if (endHr > startHr && endMin != 0) {
rSpan = endHr - startHr + 1;
} else if (endHr > startHr && endMin == 0) {
rSpan = endHr - startHr;
} else {
rSpan = 1;