Skip to content

Instantly share code, notes, and snippets.

View yankeppey's full-sized avatar

Andrei Buneyeu yankeppey

  • Freelance Android developer
  • Lisbon, Portugal
View GitHub Profile
@yankeppey
yankeppey / SharedPreferencesFlow.kt
Last active September 14, 2022 15:54
A simple Lifecycle-aware component that allows to observe SharedPreferences via Kotlin StateFlow
import android.content.SharedPreferences
import android.util.Log
import eu.buney.coroutines.ApplicationCoroutineScope
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.plus
import javax.inject.Inject
import javax.inject.Singleton
@yankeppey
yankeppey / Velocity.kt
Created August 31, 2022 10:51
Unitless Velocity (like kotlin.time.Duration)
/**
* Represents the velocity.
*
* To construct a velocity use either the extension function toVelocity, or the extension properties mph, metersPerSecond, and so on,
* avaiable on [Int], [Long], [Float] and [Double] numeric types.
*
* To get the value of this duration expressed in a particular duration units use the properties [inMetersPerSecond] and so on.
*
* @author Andrei Buneyeu
*/
@yankeppey
yankeppey / TLS12SocketFactory.java
Created June 18, 2015 08:37
TLS 1.2 on Android
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
@yankeppey
yankeppey / MainActivity.java
Created May 7, 2015 09:32
Kontakt.io beacon layout for AltBeacon library
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "RangingActivity";
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
@yankeppey
yankeppey / AppDelegate.cpp
Created March 5, 2015 12:27
Cocos2d-x 3.2. When user clicks "close" button or presses Cmd+Q, this code snippet shows a message asking user to confirm the game exit. Particular this code is used on mac desktop versions, but I guess the glfwSetWindowCloseCallback can be used on other desktop platforms too. Things can be changed on later versions of cocos2d-x.
/*
Cocos2d-x 3.2
When user clicks "close" button or presses Cmd+Q, this code snippet shows a message asking user to confirm the game exit.
Particular this code is used on mac desktop versions, but I guess the glfwSetWindowCloseCallback can be used on other desktop platforms too.
Things can be changed on later versions of cocos2d-x.
*/