Skip to content

Instantly share code, notes, and snippets.

View JosiasSena's full-sized avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / FixedGetCameraIds.java
Created February 12, 2020 01:07
Fixed getCameraIds()
private void getCameraIds() {
cameraManager = (CameraManager) appContext.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics;
try {
for (String cameraId : cameraManager.getCameraIdList()) {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
if (isCameraFacingBack(cameraCharacteristics) && backCameraId == null) {
backCameraId = cameraId;
} else if (isCameraFacingFront(cameraCharacteristics) && frontCameraId == null) {
frontCameraId = cameraId;
@JosiasSena
JosiasSena / BuggyGetCameraIds.java
Last active February 12, 2020 01:06
Buggy getCameraIds()
private void getCameraIds() {
cameraManager = (CameraManager) appContext.getSystemService (Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics;
try {
for (String cameraId : cameraManager.getCameraIdList()) {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
if (isCameraFacingBack(cameraCharacteristics)) {
backCameraId = cameraId;
} else if (isCameraFacingFront(cameraCharacteristics)) {
frontCameraId = cameraId;
class SomePresenterOrViewModelEtc(private val api: GraphQLApi) {
// ...
fun sunscribeToMessages() {
val messagesSubscription = OnNewMessagesReceivedSubscription.builder()
.groupUUID("uuid")
.build()
api.subscribe(messagesSubscription)
class GraphQLApi(private val sharedOkHttpClientBuilder: OkHttpClient.Builder) {
// ...
fun <D : Operation.Data, V : Operation.Variables> subscribe(subscription: Subscription<D, D, V>): Flowable<Response<D>> {
// Create our dedicated apollo client
val apolloClient = ApolloSubscriptionClientFactory(sharedOkHttpClientBuilder)
.createSubscriptionApolloClient()
class ApolloSubscriptionClientFactory {
fun createSubscriptionApolloClient(sharedOkHttpClientBuilder: OkHttpClient.Builder): ApolloClient {
val okHttpClient = sharedOkHttpClientBuilder
.pingInterval(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS)
.build()
val subscriptionTransportFactory = WebSocketSubscriptionTransport.Factory("wss://your_subscription_host/graphql", okHttpClient)
return ApolloClient.builder()
subscription onNewMessagesReceived($groupUUID: String!) {
groupChatSubscription(group: $groupUUID) {
... on Message {
uuid
}
}
}
class ApolloSubscriptionClientFactory {
fun createSubscriptionApolloClient(sharedOkHttpClientBuilder: OkHttpClient.Builder): ApolloClient {
val okHttpClient = sharedOkHttpClientBuilder
.pingInterval(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS)
.build()
val subscriptionTransportFactory = WebSocketSubscriptionTransport.Factory("wss://your_subscription_host/graphql", okHttpClient)
return ApolloClient.builder()
@JosiasSena
JosiasSena / all_to_lowercase.sh
Created March 29, 2019 14:16
Set all files in current directory to lowercase
for file in *; do mv "$file"`echo $file | tr "[:upper:]" "[:lower:]"`"; done
@JosiasSena
JosiasSena / MainActivity.kt
Created May 20, 2018 02:17
Step counter example
package com.josiassena.simplepedometer
import android.content.Context
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
@JosiasSena
JosiasSena / ResetRepository.md
Last active December 30, 2017 23:12
Reset repository. Clears all commit history.

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A