Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
View FixedGetCameraIds.java
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 Feb 12, 2020
Buggy getCameraIds()
View BuggyGetCameraIds.java
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;
View SomePresenterOrViewModelEtc.kt
class SomePresenterOrViewModelEtc(private val api: GraphQLApi) {
// ...
fun sunscribeToMessages() {
val messagesSubscription = OnNewMessagesReceivedSubscription.builder()
.groupUUID("uuid")
.build()
api.subscribe(messagesSubscription)
View GraphQLApi.kt
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()
View ApolloSubscriptionClientFactory.kt
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()
View subscriptions.graphql
subscription onNewMessagesReceived($groupUUID: String!) {
groupChatSubscription(group: $groupUUID) {
... on Message {
uuid
}
}
}
View ApolloSubscriptionClientFactory.kt
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 Mar 29, 2019
Set all files in current directory to lowercase
View all_to_lowercase.sh
for file in *; do mv "$file"`echo $file | tr "[:upper:]" "[:lower:]"`"; done
@JosiasSena
JosiasSena / MainActivity.kt
Created May 20, 2018
Step counter example
View MainActivity.kt
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 Dec 30, 2017
Reset repository. Clears all commit history.
View ResetRepository.md

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