Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
coding...

Alireza A. Ahmadi alzahm

😎
coding...
View GitHub Profile
View jenkins-include-library.groovy
library identifier: 'jenkins-shared@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://github.com/MobodidTech/jenkins-shared.git',
])
View send-telegram.groovy
def sendTelegram(message) {
def encodedMessage = URLEncoder.encode(message, "UTF-8")
withCredentials([string(credentialsId: 'telegramToken', variable: 'TOKEN'),
string(credentialsId: 'telegramChatId', variable: 'CHAT_ID')]) {
response = httpRequest (consoleLogResponseBody: true,
contentType: 'APPLICATION_JSON',
httpMode: 'GET',
url: "https://api.telegram.org/bot$TOKEN/sendMessage?text=$encodedMessage&chat_id=$CHAT_ID&disable_web_page_preview=true",
View android-agent-dockerfile
FROM ubuntu:latest
# Install OS prerequisites
RUN apt-get update -qq
RUN apt-get install -y openjdk-8-jdk \
wget \
expect \
zip \
unzip
View jenkinsfile-agent.groovy
pipeline {
agent {
docker {
image 'android-agent'
}
}
}
View mvvm-send-event-with-wrapper-class.kt
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandledOrReturnNull(): T? {
return if (hasBeenHandled) {
View mvvm-send-event-with-just-live-data.kt
class MyViewModel() : ViewModel(){
val networkError = MutableLiveData<String>()
}
//inside activity
viewModel.networkError.observe(this, Observer {
showToast(it)
})
View composite-build-example.gradle
include ':app'
def progressButton = '../../Android-Lib/ProgressButton'
if (file(progressButton).exists()) {
includeBuild(progressButton) {
dependencySubstitution {
substitute module('com.alirezaahmadi:progress-button') with project(':app')
}
}
View Forwarding-Function-Parameter.kt
class LogicHandlingClass {
fun doThis(){
//does something amazing!
}
}
class UserClass {
val logicHandlingClass = LogicHandlingClass()
val myClass = MyClass(logicHandlingClass::doThis)
View Kotlin-Higher-Order-Functions-As-Interface.kt
class MyClass(val doThis: () -> Unit, val doThat: (number: Int) -> Unit = {}) {
fun someFunction(){
doThis()
doThat(12)
}
}
class UserClass {
val myClass = MyClass(::doThis, ::doThat)
View Kotlin-Interfaces.kt
class MyClass(val listener: Listener) {
interface Listener {
fun doThis()
fun doThat(number: Int)
}
fun someFunction(){
listener.doThis()
listener.doThat(12)