Skip to content

Instantly share code, notes, and snippets.

View bholota's full-sized avatar

Bartłomiej Hołota bholota

View GitHub Profile
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
https://mirror1.malwaredomains.com/files/justdomains
http://sysctl.org/cameleon/hosts
https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt
https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt
https://hosts-file.net/ad_servers.txt
https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/hostfile.txt
https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/easylist_host.txt
https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/easy_privacy_host.txt
https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/gambling-hosts.txt
fun jaccardSimilarity(first: Array<Int>, second: Array<Int>): Float {
val s1 = first.toSet()
val s2 = second.toSet()
return s1.intersect(s2).size / s1.union(s2).size.toFloat()
}
class Encoder {
var base = 0
fun encode(categories: Set<String>) =
val benchmarkList = List<ProducerConsumerCoroutinesOnlyBenchmark>(100) { ProducerConsumerCoroutinesOnlyBenchmark() }
launch {
val resultList = benchmarkList.map {
it.startBenchmark()
}
val resultReduced = resultList.reduce {sum, element ->
ProducerConsumerCoroutinesOnlyBenchmark.Result(sum.executionTime + element.executionTime, sum.numOfReceivedMessages + element.numOfReceivedMessages)
}
Log.d("FragmentCoroutinesDemo", "Result not reduced " + resultReduced.executionTime + "ms")
package com.techyourchance.multithreading.demonstrations.purecoroutines
import android.util.Log
import com.techyourchance.multithreading.DefaultConfiguration
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.util.concurrent.atomic.AtomicInteger
class ProducerConsumerCoroutinesOnlyBenchmark {
@bholota
bholota / QuickSort.kt
Last active September 25, 2019 19:43
fun Array<Int>.quickSort() {
quickSortImpl(this, 0, this.lastIndex)
}
fun quickSortImpl(input: Array<Int>, leftIndex: Int, rightIndex: Int) {
if (input.size <= 1) return
val pivotIndex = (leftIndex + rightIndex) / 2
val pivotValue = input[pivotIndex]
input[pivotIndex] = input[rightIndex]
var j = leftIndex
Main process (PROCESS_ONE) writes only key1 and key2
PROCESS_TWO writes only key2 and key3
2019-05-30 10:20:07.163 11464-11506/com.example.sharedprefsplease D/ProcessOneIntentService: PROCESS_ONE opens prefs
2019-05-30 10:20:09.696 11464-11506/com.example.sharedprefsplease D/ProcessOneIntentService: PROCESS_ONE writes to prefs
2019-05-30 10:20:09.704 11464-11506/com.example.sharedprefsplease D/ProcessOneIntentService: PROCESS_ONE is DONE
2019-05-30 10:20:11.174 11508-11534/com.example.sharedprefsplease:PROCESS_TWO D/ProcessTwoIntentService: PROCESS_TWO writes to prefs
2019-05-30 10:20:11.182 11508-11534/com.example.sharedprefsplease:PROCESS_TWO D/ProcessTwoIntentService: PROCESS_TWO is DONE
2019-05-30 10:20:20.702 11464-11464/com.example.sharedprefsplease D/MainActivity: key1: P1, key2: P1, key3: null}
2019-05-30 10:20:30.781 11464-11464/com.example.sharedprefsplease I/Process: Sending signal. PID: 11464 SIG: 9
class SampleService : Service() {
companion object {
private val LAUNCHER = ForegroundServiceLauncher(SampleService::class.java)
@JvmStatic
fun start(context: Context) = LAUNCHER.startService(context)
@JvmStatic
fun stop(context: Context) = LAUNCHER.stopService(context)
}
class ForegroundServiceLauncher(private val serviceClass: Class<out Service>) {
private var isStarting = false
private var shouldStop = false
@Synchronized
fun startService(context: Context, block: Intent.() -> Unit = {}) {
isStarting = true
shouldStop = false
ContextCompat.startForegroundService(context, Intent(context, serviceClass).apply { block() })
@bholota
bholota / LifecycleCoroutines.kt
Created November 29, 2018 14:39 — forked from LouisCAD/LifecycleCoroutines.kt
CoroutineScope and Job integration with Lifecycle for Android. Meant to be used for your coroutines in lifecycle aware components. Ongoing PR: https://github.com/Kotlin/kotlinx.coroutines/pull/760
import android.arch.lifecycle.GenericLifecycleObserver
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.Lifecycle.Event.ON_DESTROY
import android.arch.lifecycle.LifecycleOwner
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.android.Main
fun Lifecycle.createJob(cancelEvent: Lifecycle.Event = ON_DESTROY): Job {
@bholota
bholota / amw_search.py
Last active November 23, 2018 19:09
Quick search in AMW auction-less deals
import requests
import sys
from bs4 import BeautifulSoup
URL_AMW = "https://amw.com.pl/pl/uzbrojenie-i-sprzet-wojskowy/sprzet-wojskowy/sprzedaz-bezprzetargowa/wyniki" \
"-wyszukiwania"
params = {"search": sys.argv[1]}
response = requests.get(URL_AMW, params=params)