Skip to content

Instantly share code, notes, and snippets.

@southerton81
southerton81 / anonymousVsLambda.txt
Last active February 6, 2023 11:36
Kotlin: inlined anonymous vs inlined lambda
fun f1() {
// Anonymous function: this will print 1 2, return acts like a break.
listOf(1,2).forEach(fun(it: Int): Unit {
println(it)
return
})
}
import android.net.Uri
import com.commonsound.common.data.flickr.FlickrApi.Routes.FLICKR_REST_SERVICE
import com.commonsound.common.data.flickr.models.FlickrPhotoModel
import io.ktor.client.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.w3c.dom.NodeList
import java.io.BufferedInputStream
import java.io.BufferedReader
import java.net.URL
import XCTest
import CoreData
@testable import iosApp
class iosAppTests: XCTestCase {
func testCoreDataMergeConflict() {
let expectation = XCTestExpectation(description: "")
expectation.expectedFulfillmentCount = 2
import Foundation
import CoreData
final class CoreDataInventory {
static let instance = CoreDataInventory()
let persistentContainer: NSPersistentContainer
let viewContext: NSManagedObjectContext
private let backgroundContext: NSManagedObjectContext
import XCTest
import CoreData
@testable import iosApp
class iosAppTests: XCTestCase {
/*
ChartState - is a CoreData entity with two fields: chartLen and seed:
<entity name="ChartState" representedClassName="ChartState" syncable="YES" codeGenerationType="class">
use std::collections::HashMap;
fn bestSum(targetSum: i32, v: &Vec<i32>, memo: &mut HashMap<i32, Vec<i32>>) -> Vec<i32> {
if targetSum == 0 { return vec![]; }
if targetSum < 0 { return vec![-1]; }
if memo.contains_key(&targetSum) {
return memo[&targetSum].clone();
}
let mut result: Vec<i32> = Vec::new();
@southerton81
southerton81 / Retrofit2WithRxJava2TestCase.kt
Created July 2, 2020 11:20
Retrofit2WithRxJava2TestCase
package com.example.myapplication
import io.reactivex.Observable
import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Test
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
@southerton81
southerton81 / unique.js
Created March 18, 2018 20:49
Returns all possible subsets (without duplicate subsets)
let list = [];
let nums = [1,2,3];
function backtrack(nums, temparray, startindex) {
list.push(temparray.slice());
for (var i = startindex; i < nums.length; i++) {
temparray.push(nums[i]);
backtrack(nums, temparray, i + 1);
temparray.pop();
package javaapplication1;
/**
* Test java ThreadPoolExecutor can shrink to guarantee only one thread is executing at a given
* time, and then restore thread pool size.
*/
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;