Skip to content

Instantly share code, notes, and snippets.

View jordanterry's full-sized avatar

Jordan Terry jordanterry

View GitHub Profile
fun combineFlags(flagOne: Int, flagTwo: Int): Int {
return flagOne or flagTwo
}
fun checkIfServerIsUnhealthy(
errorRates: DoubleArray,
time: Int,
timeRange: Int,
minimumErrorThreshold: Double
): Boolean {
if (timeRange > errorRates.size) throw IllegalArgumentException()
var left = time - timeRange + 1
@jordanterry
jordanterry / SaveDocument.kt
Last active February 11, 2021 07:09
Abstractions
data class Document(
val data: Byte[]
}
interface ExportDocument {
fun export(document: Document)
}
class PngExportDocument : ExportDocument {
override fun export(document: Document) = TODO("Export as Png")
fun callback(data: Data) {
// Do something.
}
dataRepository.getData(::callback)
@jordanterry
jordanterry / typealias.kt
Created April 8, 2018 10:14
A use for typealiasing
import com.test.Model
typealias com.test.dtos.Model = ModelDto
@jordanterry
jordanterry / interface.kt
Created April 8, 2018 10:07
Use functions not single function interfaces.
interface DataCallback {
fun receive(data: Data)
}
val callback = object : DataCallback {
fun receive(data: Data) {
// Do something.
}
}
dataRepositroy.getData(callback)
@jordanterry
jordanterry / function.kt
Last active April 8, 2018 10:07
Use functions not single function interfaces.
val callback: (Data) -> () = { data ->
// Do something.
}
dataRepository.getData(callback)
@jordanterry
jordanterry / .gitignore
Created March 29, 2015 13:43
Example gitignore
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
@jordanterry
jordanterry / solutionPseudo
Created February 22, 2015 10:33
Pseudocode example
Sort the input array into numerical order
result = result of the last three elements in the array
if the smallest two numbers are greater than 0 and the first element is 0
altResult is result of the two smallest values and the largest value
if altResult > result
return altResult
endIf
endIf
return result
@jordanterry
jordanterry / solutionNew.java
Created February 22, 2015 10:25
This is a solution that worked.
import java.util.Arrays;
public class Solution {
public int solution(int[] A) {
Arrays.sort(A);
int l = A.length;
int result = A[l - 1] * A[l - 2] * A[l - 3];
if(A[0] * A[1] > 0 && A[0] < 0) {
int altResult = A[0] * A[1] * A[l - 1];