Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
Block or report user

Report or block Audhil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View server.py
from flask import Flask, request, jsonify
app = Flask(__name__)
# root
@app.route("/")
def index():
"""
this is a root dir of my server
:return: str
View DummyActivity.kt
class DummyActivity : AppCompatActivity() {
// it'll be passed from TestCases
private val mockUrl by lazy {
intent?.extras?.getString(ConstantsUtil.MOCK_URL, null)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dummy)
View BasicActivityTest.kt
@RunWith(AndroidJUnit4::class)
class BasicActivityTest {
private lateinit var mockServer: MockWebServer
@Rule
@JvmField
val rule = ActivityTestRule(DummyActivity::class.java, false, false)
@Before
View MockServerDispatcher.kt
class MockServerDispatcher {
// response dispatcher
class ResponseDispatcher : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
if (request.path.equals("/todos/1", true))
return MockResponse().setResponseCode(200).setBody(
"{\n" +
" \"id\" : 1,\n" +
" \"title\" : \"delectus aut autem\",\n" +
View UiRunner.kt
open class UiRunner : AndroidJUnitRunner() {
override fun onCreate(arguments: Bundle?) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
super.onCreate(arguments)
}
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
return super.newApplication(cl, UiGitHubDelegate::class.java.name, context)
}
View UiGitHubDelegate.kt
open class UiGitHubDelegate : GitHubDelegate() {
override fun getAppComponent(): GitHubAppComponent {
return DaggerGitHubAppComponent.builder()
.applicationModule(TestApplicationModule(this))
.build()
}
}
View TestApplicationModule.kt
@Module
class TestApplicationModule(application: GitHubDelegate) : ApplicationModule(application) {
@Singleton
@Provides
fun giveRetrofit(okHttpClient: OkHttpClient): Retrofit =
Retrofit.Builder()
.baseUrl("http://localhost:8080/")
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().create()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
View AppDelegate.kt
open class GitHubDelegate : Application() {
open lateinit var appDaggerComponent: GitHubAppComponent
override fun onCreate() {
super.onCreate()
appDaggerComponent = getAppComponent()
appDaggerComponent.inject(this)
}
@Audhil
Audhil / Solution.java
Last active Jun 23, 2019
Alice - Bob - Apple 🍎 - Trees - Codility
View Solution.java
import java.util.HashMap;
import java.util.Map;
public class Solution {
private static int solution(int[] A, int K, int L) {
if (K + L > A.length)
return -1;
int sum, aliceApples, bobApples, totalApples = 0;
@Audhil
Audhil / stringIs.java
Created Jun 22, 2019
String is immutable - practical check-up
View stringIs.java
String t = "foo"; // newer obj created and added string pool
System.out.println("hashCode of t: " + t.hashCode());
t = "foo"; // shares the same memory location - same hashCode()
System.out.println("hashCode of 2 t: " + t.hashCode());
t = "fuc"; // newer value added - newer obj created and added string pool - different hashCode()
System.out.println("hashCode of 3 t: " + t.hashCode());
t = new String("foo"); // shares the same memory location - same hashCode()
You can’t perform that action at this time.