Skip to content

Instantly share code, notes, and snippets.

View izmajlowiczl's full-sized avatar

Łukasz Izmajłowicz izmajlowiczl

View GitHub Profile
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FFF"
android:pathData="M160,0H0v160h160V0zM128,128H32V32h96V128zM64,64h32v32h-32zM352,0v160h160V0H352zM480,128h-96V32h96V128zM416,64h32v32h-32zM192,128h32v32h-32zM256,0h64v32h-64zM256,128l32,0l0,-32l32,0l0,-32l-96,0l0,-32l-32,0l0,32l0,16l0,16l64,0z" />
<path
android:fillColor="#FFF"
// Source + Unit Tests
package pl.expensive.storage;
import java.util.ArrayList;
import java.util.List;
public class SQLiteTableBuilder {
private String table;
private List<String> commands;
struct node {
int value;
struct node *next;
};
void push_front(struct node* root, int value) {
struct node* new_root = create_node(value);
if (!new_root) ERR("Cannot allocate memory for node to add/n");
new_root->next = root;
// From Plaid app [DesignerNewsLogin.class]
private void setupAccountAutocomplete() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) ==
PackageManager.PERMISSION_GRANTED) {
permissionPrimer.setVisibility(View.GONE);
final Account[] accounts = AccountManager.get(this).getAccounts();
final Set<String> emailSet = new HashSet<>();
for (Account account : accounts) {
if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
/**
* Specifies how a [Lazy] instance synchronizes access among multiple threads.
*/
public enum class LazyThreadSafetyMode {
/**
* Locks are used to ensure that only a single thread can initialize the [Lazy] instance.
*/
SYNCHRONIZED,
fun SQLiteDatabase.doesTableExistIncludingTemps(tableName: String): Boolean {
val sql = """SELECT name
FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
WHERE type='table';"""
val c = rawQuery(sql, null)
while (c.moveToNext()) {
if (c.getString(0) == tableName) return true else continue
}
fun SQLiteDatabase.doesTableExist(tableName: String): Boolean {
val sql = "SELECT name FROM sqlite_master WHERE type='table';"
val c = rawQuery(sql, null)
while (c.moveToNext()) {
if (c.getString(0) == tableName) return true
else continue
}
return false
}
@Test fun columnsForCategoryTable() {
val columns = getTableColumns(database.readableDatabase, "tbl_category")
assertThat(columns).containsExactly("uuid", "name", "color")
}
@Test fun createDefaultCategoriesTable() {
assertThat(database.readableDatabase.doesTableExist("tbl_category")).isTrue()
}
@Test
public void storeWallets() {
Wallet wallet = Wallet.create(UUID.randomUUID(), "Test-Walet");
model.insert(wallet);
assertThat(model.list())
.containsExactly(wallet);
}
@Test
public void listWallets() {
Wallet bankWallet = Wallet.create(randomUUID(), "bank");
Wallet ccWallet = Wallet.create(randomUUID(), "credit card");
db.execSQL(storeWalletSql(bankWallet));
db.execSQL(storeWalletSql(ccWallet));
assertThat(storage.list()).containsExactly(bankWallet, ccWallet);
}