Skip to content

Instantly share code, notes, and snippets.

@jabubuck
jabubuck / ExampleUnitTest
Created February 25, 2019 00:36
Self reference for writing unitt tests with mockito
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import org.junit.Test
class Tests {
@Test
fun testname_callsfunctionname() {
//Instantiate Presenter
val presenter = MyPresenter()
@jabubuck
jabubuck / snippet.java
Created February 25, 2019 00:25
Useful android java snippets
//JSON Load from file to object
public JSONObject loadJSONFromAsset() {
String json = null;
try {
//Points towards top level assets folder
InputStream is = getApplicationContext().getAssets().open("filename.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
@jabubuck
jabubuck / snippet.kt
Created February 25, 2019 00:23
Useful Kotlin snippets
//JSON Load from file to object
private fun loadJSONFromAsset(): JSONObject? {
var json: JSONObject?
try {
val inputStream = applicationContext.assets.open("currencies.json")
val inputString = inputStream.bufferedReader().use{it.readText()}
json = JSONObject(inputString)
} catch (ex: IOException) {
ex.printStackTrace()
return null
@jabubuck
jabubuck / app.js
Created June 28, 2013 22:15
Small snippet that will rotate through a selection of colors. For titanium iOS and Android
var win = Ti.UI.createWindow({
fullscreen: true,
backgroundColor: 'blue',
});
setInterval(function(){
var backColor = win.backgroundColor;
if(backColor == 'blue'){
win.animate({backgroundColor: 'purple', duration: 1500});
win.backgroundColor = 'purple';
@jabubuck
jabubuck / scrollDownView.js
Created May 10, 2013 18:44
Small sample that demonstrates a drag down view, for Titanium, works with iOS and Android.
var screenHeight = Ti.Platform.displayCaps.platformHeight;
var screenWidth = Ti.Platform.displayCaps.platformWidth;
var win = Ti.UI.createWindow({
fullscreen: true,
height: screenHeight,
width: screenWidth,
backgroundColor: 'white'
});
@jabubuck
jabubuck / customPicker.js
Created May 3, 2013 17:50
Sample project that creates a customizable picker from scrollable views, functionality needs tweaking slightly. Titanium Project, works for iOS.
//"THE BEER-WARE LICENSE": As long as you retain this notice you can do whatever you want with this stuff.
//If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Jamie Buckley
var screenWidth = Ti.Platform.displayCaps.platformWidth;
var screenHeight = Ti.Platform.displayCaps.platformHeight;
var win = Ti.UI.createWindow({
fullscreen: true,
width: screenWidth,
height: screenHeight,
@jabubuck
jabubuck / spriteSheetAnimator.js
Created April 26, 2013 17:52
Sample project that animates single row sprite sheets(I will later add support for multiple rows/animations for single sprites) This is for Titanium iOS and Android
//"THE BEER-WARE LICENSE": As long as you retain this notice you can do whatever you want with this stuff.
//If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Jamie Buckley
var win = Ti.UI.createWindow({
backgroundColor: 'black',
fullscreen: true,
width: Ti.Platform.displayCaps.platformWidth,
height: Ti.Platform.displayCaps.platformHeight
});
@jabubuck
jabubuck / slotMachine.js
Created April 19, 2013 17:11
Titanium code sample that uses pickers to randomly select 3 values and display them side by side. iOS only(for now). You can do whatever you like with this code.
var win1 = Titanium.UI.createWindow({
backgroundColor:'black',
layout: 'vertical',
fullscreen: true,
width: Ti.Platform.displayCaps.platformWidth,
height: Ti.Platform.displayCaps.platformHeight
});
//Create window that will contain the picker
var pickerView = Ti.UI.createView({
@jabubuck
jabubuck / SliderPageScrollSample.js
Last active December 15, 2015 20:49
Small sample that demonstrates page scrolling controlled by a slider that snaps to values along the length. For Titanium works on Android and iOS. You can do whatever you want with this code.
var win = Ti.UI.createWindow({
fullscreen: true,
backgroundColor: 'gray',
layout: 'vertical'
});
//This function is used to create our pages
function newPage(pageColor, leftPos){
v = Ti.UI.createView({backgroundColor: pageColor, left: leftPos, height: Ti.Platform.displayCaps.platformHeight * 0.9, width: Ti.Platform.displayCaps.platformWidth});
return v;