Skip to content

Instantly share code, notes, and snippets.

@ankushg
ankushg / JsMapLikeObject.kt
Created January 19, 2022 22:08
Convert kotlin.collections.Map to something that can work with Typescript
import Partial
import Record
import set
import toPartial
typealias JsMapLikeObject<K, V> = Partial<Record<K, V>>
inline operator fun <K : Any, V : Any> JsMapLikeObject<K, V>.get(key: K): V? =
asDynamic()[key] as? V
/**
* Implementation of [SSLSocketFactory] that adds [TlsVersion.TLS_1_2] as an enabled protocol for every [SSLSocket]
* created by [delegate].
*
* [See this discussion for more details.](https://github.com/square/okhttp/issues/2372#issuecomment-244807676)
*
* @see SSLSocket
* @see SSLSocketFactory
*/
class Tls12SocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() {
@ankushg
ankushg / BaseRobolectricUnitTest.kt
Created April 6, 2018 23:26
ShadowResourcesCompat
import com.ankushg.example.BuildConfig
import com.ankushg.example.shadows.ShadowResourcesCompat
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows
import org.robolectric.annotation.Config

Keybase proof

I hereby claim:

  • I am ankushg on github.
  • I am ankushg (https://keybase.io/ankushg) on keybase.
  • I have a public key whose fingerprint is 8D1C 337B 650E 1842 6493 6F40 04B6 1D77 12C8 1B37

To claim this, I am signing this object:

@ankushg
ankushg / mount_fade_out.user.js
Last active February 7, 2016 17:30 — forked from TApicella/mount_fade_out.user.js
Mount fade out for Habitica (formerly HabitRPG)
// ==UserScript==
// Sources: http://stackoverflow.com/questions/2246901/how-can-i-use-jquery-in-greasemonkey-scripts-in-google-chrome
// @name Mount Fader
// @namespace habiticaMountFader
// @include https://habitica.com/*
// @author Tom Apicella (jquery by Erik Vergobbi Vold & Tyler G. Hicks-Wright)
// @description This userscript fades out your mount when you mouse over your hero
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
@ankushg
ankushg / ArrayExtensions.swift
Created June 12, 2014 23:12
removeObject extension for Array in Swift
import Foundation
extension Array {
func indexOfObject(object : AnyObject) -> NSInteger {
return (self as NSArray).indexOfObject(object)
}
mutating func removeObject(object : AnyObject) {
for var index = self.indexOfObject(object); index != NSNotFound; index = self.indexOfObject(object) {
self.removeAtIndex(index)
@ankushg
ankushg / CalendarActivity.java
Last active January 4, 2016 14:09
TimesSquare for Android: A standalone Android widget for picking a single date from a calendar view.
protected void onCreate (Bundle savedInstanceState){
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime())
.withSelectedDate(today);
}
@ankushg
ankushg / layout.xml
Last active August 22, 2021 18:30
HoloGraphLibrary PieGraph Example
<com.echo.holographlibrary.PieGraph
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/graph"/>