Skip to content

Instantly share code, notes, and snippets.

View hissain's full-sized avatar
:atom:

Md. Sazzad Hissain Khan hissain

:atom:
View GitHub Profile
@hissain
hissain / gist:f4cdadcb68dfd683a912c623272c3dba
Created April 1, 2020 21:52
Retrofit gradle dependencies
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
{
"user_name": "Alex",
"user_email": "alex@gmail.com",
"user_age": 32,
"user_uid": "164E92FC-D37A-4946-81CB-29DE7EE4B124"
}
{
"user_id": 1001,
"user_name": "Alex",
"user_email": "alex@gmail.com",
"user_age": 32,
"user_uid": "164E92FC-D37A-4946-81CB-29DE7EE4B124"
}
data class UserInfo (
@SerializedName("user_id") val userId: Int?,
@SerializedName("user_name") val userName: String?,
@SerializedName("user_email") val userEmail: String?,
@SerializedName("user_age") val userAge: String?,
@SerializedName("user_uid") val userUid: String?
)
@hissain
hissain / gist:7b5bbecabd6ac095a59f3660c62043a4
Last active April 1, 2020 22:28
ServiceBuilder and RestApi class
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST
interface RestApi {
@Headers("Content-Type: application/json")
@POST("users")
fun addUser(@Body userData: UserInfo): Call<UserInfo>
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
class RestApiService {
fun addUser(userData: UserInfo, onResult: (UserInfo?) -> Unit){
val retrofit = ServiceBuilder.buildService(RestApi::class.java)
retrofit.addUser(userData).enqueue(
object : Callback<UserInfo> {
@hissain
hissain / gist:35513214fa7eac6ec9ecf0808bb2573e
Last active April 1, 2020 22:47
Service Builder Class
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
object ServiceBuilder {
private val client = OkHttpClient.Builder().build()
private val retrofit = Retrofit.Builder()
.baseUrl("http://api.server.com") // change this IP for testing by your actual machine IP
.addConverterFactory(GsonConverterFactory.create())
fun addDummyUser() {
val apiService = RestApiService()
val userInfo = UserInfo( id = null,
userName = "Alex",
userEmail = "alex@gmail.com",
userAge = 32,
userUid = "164E92FC-D37A-4946-81CB-29DE7EE4B124" )
apiService.addUser(userInfo) {
if (it?.id != null) {
#!/bin/bash
echo "This is simplest bash command"
#start of the apple script code
osascript <<'END'
set theAlertText to "Swiftlint is not installed"
set theAlertMessage to "Download from https://github.com/realm/SwiftLint manually. Would you like to open link?"
display alert theAlertText message theAlertMessage as critical buttons {"Cancel", "Open link"} default button "Open link" cancel button "Cancel" giving up after 60
set the button_pressed to the button returned of the result
if the button_pressed is "Open link" then
open location "https://github.com/realm/SwiftLint/blob/master/README.md"
set listWithLinks to {"google.com", "bing.com", "yahoo.com"}
set listWithLabels to {"Google", "Bing", "Yahoo"}
set dialogTitle to "Select & Go to open link"
set buttonOK to "Go"
set buttonCancel to "Cancel"
set choosedLabels to choose from list (listWithLabels as list) with title dialogTitle OK button name buttonOK cancel button name buttonCancel with multiple selections allowed
if false is choosedLabels then return
repeat with i from 1 to number of items in choosedLabels
set choosedLabel to item i of choosedLabels
repeat with i from 1 to number of items in listWithLabels