Skip to content

Instantly share code, notes, and snippets.

Avatar

Frode Nilsen Nilzor

View GitHub Profile
@Nilzor
Nilzor / ContentTypeInterceptor.kt
Last active Jun 19, 2020
An OkHttp interceptor allowing you to override Content-Type for POST, PUT and PATCH requests
View ContentTypeInterceptor.kt
/**
* Overrides the HTTP Header Content-Type for POST, PATCH and PUT calls to the given [contentType]
*/
class ContentTypeInterceptor(private val contentType: String) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val chainBuilder = request.newBuilder()
request.body()?.let {
val newBody = ForwardingRequestbody(it, contentType)
when (request.method()) {
@Nilzor
Nilzor / ToothpickTest.kt
Created Jun 3, 2020
Toothpick overriding and stuff
View ToothpickTest.kt
package no.ruter.sales.utils
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsInstanceOf
import org.junit.Test
import toothpick.Scope
import toothpick.Toothpick
import toothpick.config.Module
import toothpick.ktp.binding.bind
import toothpick.ktp.binding.module
@Nilzor
Nilzor / databinderror.txt
Last active May 17, 2020
Databind error
View databinderror.txt
import com.myapp.shared.databinding.FragmentSaleProductBindingImpl;
^
symbol: class FragmentSaleProductBindingImpl
^
warning Binding adapter AK(android.widget.ImageView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBindingAdapter.Companion#setIdleCardImage with com.myapp.shared.bindingadapters.ValidatorBindingAdapter#setIdleCardImage
warning Binding adapter AK(android.widget.ImageView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBindingAdapter.Companion#setIdleCardImage with com.myapp.shared.bindingadapters.ValidatorBindingAdapter#setIdleCardImage
warning Binding adapter AK(android.widget.TextView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBin
@Nilzor
Nilzor / BuyTicketButton.kt
Created Apr 23, 2020
DAtabinding to custom prop
View BuyTicketButton.kt
class BuyTicketButton(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : this(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs)
init {
val view = LayoutInflater.from(context)!!.inflate(R.layout.button_ticket, this, true)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.BuyTicketButton)
val imageSrc = attributes.getResourceId(R.styleable.BuyTicketButton_imageSrc, 0)
View multiple_null_checks.kt
fun <R, A, B> withNoNulls(p1: A?, p2: B?, function: (p1: A, p2: B) -> R): R? = p1?.let { p2?.let { function.invoke(p1, p2) } }
fun <R, A, B, C> withNoNulls(p1: A?, p2: B?, p3: C?, function: (p1: A, p2: B, p3: C) -> R): R? = p1?.let { p2?.let { p3?.let { function.invoke(p1, p2, p3) } } }
@Nilzor
Nilzor / keybase.md
Created Sep 19, 2017
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am nilzor on github.
  • I am frodenilsen (https://keybase.io/frodenilsen) on keybase.
  • I have a public key ASAl5OwmAffcKHYFXAub-yC-Z2TP1v9XlbbFy70Qtt55eAo

To claim this, I am signing this object:

@Nilzor
Nilzor / debug.log
Created Sep 9, 2017
Xamarin HttpClient log
View debug.log
Android application is debugging.
Loaded assembly: /storage/emulated/0/Android/data/xam_android_news.xam_android_news/files/.__override__/xam-android-news.dll
Loaded assembly: /storage/emulated/0/Android/data/xam_android_news.xam_android_news/files/.__override__/RestSharp.dll [External]
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: Java.Interop.dll [External]
Loaded assembly: System.Runtime.dll [External]
Loaded assembly: System.Collections.Concurrent.dll [External]
09-09 13:59:37.789 I/art ( 3889): Not late-enabling -Xcheck:jni (already on)
09-09 13:59:37.789 W/art ( 3889): Unexpected CPU variant for X86 using defaults: x86
09-09 13:59:37.828 W/monodroid( 3889): Creating public update directory: `/data/user/0/xam_android_news.xam_android_news/files/.__override__`
@Nilzor
Nilzor / bash.rc
Last active Aug 11, 2017
bash.rc for Android screenshot and recording
View bash.rc
And-Screenshot() {
# Todo: Add demo mode: https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/docs/demo_mode.md
if [ "$1" = "" ] ; then echo "Specify output file name"
else
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
PCT=$2
if [ "$PCT" = "" ]; then PCT=33%; fi
convert screen.png -resize $PCT $1
@Nilzor
Nilzor / php-intellij-xdebug-linux.md
Created Oct 19, 2016
PHP debugging intellij linux apache2
View php-intellij-xdebug-linux.md
  • sudo apt-get install php5-xdebug
  • "PHP Web Application" run configuration backed by a "PHP Server" with XDebug set up. Run in debug mode.
  • This at the end of /etc/php5/apache2/php.in
[xdebug]
zend_extension="/usr/lib/php5/20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
@Nilzor
Nilzor / fail.sh
Last active Aug 22, 2016
AppNexus Curl scripts
View fail.sh
curl -I 'http://ams1-ib.adnxs.com/click?yhyNPW26GkDKHI09bboaQAAAAOBRuBNAyhyNPW26GkDKHI09bboaQMsSLcutjYE0CBHfEVlphz_VV7VXAAAAAOSzYgDgDAAA4AwAAAIAAAACeQQDBR8OAAAAAABVU0QATk9LAEAB-gBhdQAAAAABAQQAAQAAAKoAqyBnfwAAAAA./cnd=%210QjpZQiioNAGEILykRgYhb44IAQoioTQugw./bn=63379/referrer=http%3A%2F%2Fwww.vg.no%2Fsport%2Fol-2016%2Fslik-var-ol-natten-hekke-isabelle-lei-trusespoersmaal%2Fa%2F23768893%2F/clickenc=https://track.adform.net/C/?bn=13442192;adfibeg=0;cdata=BrHTQUfSbdPfs5ZCfJ32id3uF0FxvvzX9DxWEU-biQUlI0uGMmq9cwXtoBuHWFajy0ZLabVcrmPXHUiMkqf858rncRr8QBzgw3iI60gHGBc1;;CREFURL=http%3a%2f%2fwww.vg.no%2fsport%2fol-2016%2fslik-var-ol-natten-hekke-isabelle-lei-trusespoersmaal%2fa%2f23768893%2f;C=1' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,applicatio
You can’t perform that action at this time.