Skip to content

Instantly share code, notes, and snippets.

View shalperin's full-sized avatar

Shimi Halperin shalperin

View GitHub Profile
let a = 0.1 + 0.2
let b = 0.3
a == b // false. WTF?
@shalperin
shalperin / CameraManager.cs
Created July 17, 2022 09:16
Deal with extraneous cameras generated by Sketchup Scenes for an XR Rig.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Camera[] allCameras = FindObjectsOfType<Camera>();
@shalperin
shalperin / DatabaseModule.kt
Created June 5, 2022 13:13
A Hilt module providing a Room database using a RoomDatabase.Callback
@InstallIn(SingletonComponent::class)
@Module
object DatabaseModule {
@Singleton
@Provides
fun provideTeaDao(database: AppDatabase):TeaDao = database.teaDao()
@Provides
@Singleton
fun provideDatabase(
@shalperin
shalperin / ViewPager.kt
Created June 1, 2022 20:19
Reddit code review request
enum class PAGE_TYPES {color, manufacturer}
const val noFilter = "no filter"
class ViewPagerAdapter(private val context: Context?, private val viewModel: SharedViewModel): RecyclerView.Adapter<ViewPagerAdapter.VPAViewHolder>() {
private val data = HashMap<String, List<String>>()
class VPAViewHolder(view: View?): RecyclerView.ViewHolder(view!!) {
val radioGroup:RadioGroup = view!!.findViewById<RadioGroup>(R.id.options)
val title: TextView = view!!.findViewById<TextView>(R.id.title)
}
sealed class ViewState() {
class State1() : ViewState()
class State2(): ViewState()
class State3(): ViewState()
class State4(): ViewState()
class State5(): ViewState()
}
class DayView : ImageView {
private fun show() {
when(viewState) {
is ViewState.Skipped -> {
setImageResource(notMetVector)
}
is ViewState.Met -> {
setImageResource(metVector)
}
is ViewState.MetToday -> {
sealed class ViewState() {
class Skipped() : ViewState()
class Met(): ViewState()
class MetToday(): ViewState()
class DidntMeetYetToday(): ViewState()
class Future(): ViewState()
}
CoroutineScope(Dispatchers.Main).launch {
val html :String= flickrApi.fetchContents()
binding.myTextView.text = html
}
CoroutineScope(Dispatchers.Main).launch{
var html:String? = null
withContext(Dispatchers.IO){
html= flickrApi.fetchContents()
}
binding.myTextView.text = html
}
interface FlickrApi {
@GET("/")
suspend fun fetchContents(): String
}