Skip to content

Instantly share code, notes, and snippets.

View ernestkamara's full-sized avatar

Saidu Ernest Kamara ernestkamara

View GitHub Profile
@ernestkamara
ernestkamara / AdbCommands
Created June 26, 2018 08:42 — forked from Pulimet/AdbCommands
Adb useful commands list
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
== Shell
@ernestkamara
ernestkamara / Salone Hackathon 2019 Entry Questions Solutions
Last active March 9, 2021 17:11
Solution to Salone Hackathon 2019 Entry Questions
###1. FIND THE LONGEST WORD
["hello", "world", "hi", "bye"]
###Solution:
Given that there is only one longest word in the Array or the first longest word is a valid
```kotlin
fun findLongestWord(words: List<String>): String {
var longestWord = ""
words.onEach { word -> if(word.length > longestWord.length) longestWord = word }
return longestWord
@ernestkamara
ernestkamara / onboarding_motion_layout.xml
Last active January 3, 2020 12:39
MotionLayout for the Onboarding Screen
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motionLayout"
app:layoutDescription="@xml/onboarding_scene"
android:background="@color/onboarding_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ernestkamara
ernestkamara / OnboardingBubbleItem.kt
Last active January 6, 2020 13:00
Onboarding Bubble Item
class OnboardingBubbleItem
@kotlin.jvm.JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
init { initView(attrs) }
private fun initView(attrs: AttributeSet?) {
View.inflate(context, R.layout.layout_bubble_item, this)
val ta = context.obtainStyledAttributes(attrs, R.styleable.OnboardingBubbleItem)
@ernestkamara
ernestkamara / onboarding_scene.xml
Created January 3, 2020 12:23
The Onboarding Scene
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetStart="@id/firstTransition"
app:constraintSetEnd="@id/secondTransition"
app:duration="500">
</Transition>
@ernestkamara
ernestkamara / OnboardingFragment.kt
Last active January 4, 2020 14:41
The Onboarding Fragment
class OnboardingFragment : DialogFragment() {
private val indicators = mutableListOf<View>()
private var currentPosition = 0
private fun attachNextButtonListener() {
next.setOnClickListener {
when (currentPosition) {
0 -> next.navigate(R.id.firstTransition, R.id.secondTransition)
1 -> next.navigate(R.id.secondTransition, R.id.thirdTransition)
else -> dismiss()
@ernestkamara
ernestkamara / index.js
Last active March 10, 2020 22:57
Cloud Functions Demo
// functions/index.js
const admin = require('firebase-admin');
const functions = require('firebase-functions');
// path to a service account key JSON file
const serviceAccount = require("./account_key.json");
// Lightweight JavaScript date library for parsing, validating,
// manipulating, and formatting dates.
const moment = require('moment');
// Serpwow module
const SerpWow = require('google-search-results-serpwow');
@ernestkamara
ernestkamara / index.js
Last active March 23, 2020 10:19
Cloud Functions Demo Dependencies
// functions/index.js
const admin = require('firebase-admin');
const functions = require('firebase-functions');
// Path to a service account key JSON file
const serviceAccount = require("./account_key.json");
// Lightweight JavaScript date library for parsing, validating,
// manipulating, and formatting dates.
const moment = require('moment');
// Serpwow module
const SerpWow = require('google-search-results-serpwow');
@ernestkamara
ernestkamara / setup.js
Last active March 23, 2020 10:34
Cloud Functions Demo
// Create the serpwow object, passing in our API key
const serpwow = new SerpWow(API_KEY);
// Initialize the default app
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://APP_ID.firebaseio.com"
});
// Minimum time period(i.e. 'from') search parameter
@ernestkamara
ernestkamara / scheduled_function.js
Created March 10, 2020 22:56
Cloud Functions Demo
// The function scheduled to run every 12 hours
exports.scheduledFunction = functions.pubsub.schedule('every 12 hours').onRun(async (context) => {
// retrieve the search results as JSON
await serpwow.json(params)
.then(result => {
// Articles Firestore CollectionReference
const articlesRef = admin.firestore().collection('articles');
// Save search results to Firestore
const articles = result["news_results"]