Skip to content

Instantly share code, notes, and snippets.

#[derive(Serialize,Deserialize)]
struct Posts {
children: Vec<Post>
}
{
"kind": "Listing",
"data": {
"children": [....]
}
}
/**
* ArrayBinaryTree implements the BinaryTreeADT interface using an array
*
* @author Dr. Lewis
* @author Dr. Chase
* @version 1.0, 8/19/08
*/
package jss2;
import java.util.Iterator;
import jss2.exceptions.*;
@ciferkey
ciferkey / DifferentCellTypes.kt
Last active October 15, 2018 00:16
Different Cell Types Example in Kotlin
val wb = workbook {
sheet("new sheet") {
row(2) {
cell(1.1)
cell(date1)
cell(calendar1)
cell("a string")
cell(true)
cell(5) {
cellType = ERROR
@ciferkey
ciferkey / merge.kt
Last active October 14, 2018 14:29
fun Sheet.merge(firstRow: Int, lastRow: Int,firstCol: Int, lastCol: Int) {
addMergedRegion(CellRangeAddress(firstRow, lastRow, firstCol, lastCol))
}
sheet.merge(
1, //first row (0-based)
1, //last row (0-based)
1, //first column (0-based)
2 //last column (0-based)
// Notice the parameter is now of type "Workbook.() -> Unit" rather than "(Workbook) -> Unit"
fun workbook(block: Workbook.() -> Unit): Workbook {
var wb = HSSFWorkbook()
block(wb)
return wb
}
fun tryItOut() {
// Since we defined the lambda as using a Receiver Type of "Workbook.()" we can now directly call the methods without referencing the paramter
fun Sheet.row(rowNumber: Int? = null, block: Row.() -> Unit): Row {
return createRow(rowNumber ?: physicalNumberOfRows).apply(block)
}
fun Row.cell(value: Any? = null, column: Int? = null, block: Cell.() -> Unit = {}): Cell {
val cell = createCell(column ?: physicalNumberOfCells)
when (value) {
is Calendar -> cell.setCellValue(value)
is Date -> cell.setCellValue(value)
is Boolean -> cell.setCellValue(value)
fun Workbook.sheet(name: String? = null, block: Sheet.() -> Unit = {}): Sheet {
return if (name != null) {
createSheet(name)
} else {
createSheet()
}.apply(block)
}
// In Kotlin function definitions start with the keywork "fun"
// Additionally Kotlin lets you have "top level" functions that do not need to be inside a class
// "(Workbook) -> Unit" means "a function that takes a workbook and returns nothing (Unit)
fun workbook(block: (Workbook) -> Unit): Workbook {
var wb = HSSFWorkbook()
// Note that in Kotlin we can direcly call "block" rather than needing to call "accept" on it
block(wb)
return wb
}
public void createWorkbook() {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
row.createCell(0);
}