Skip to content

Instantly share code, notes, and snippets.

View Nilzor's full-sized avatar

Frode Nilsen Nilzor

  • Forse.no
  • Oslo, Norway
View GitHub Profile
@Nilzor
Nilzor / multiple_null_checks.kt
Created March 18, 2020 21:41
Kotlin shorthands
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 / ScalingImageView.java
Last active May 17, 2018 11:22
An ImageView with modified onMeasure which scales bounding box even if ImageView has layout width/height match_parent / fill_parent
package nilzor.public.views;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
public class ScalingImageView extends ImageView {
private boolean mAdjustViewBounds;
@Nilzor
Nilzor / keybase.md
Created September 19, 2017 08:56
Keybase proof

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 September 9, 2017 14:03
Xamarin HttpClient 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 / chocoProgramListToXml.ps1
Last active September 6, 2017 17:13
A script that converts list of programs output by "choco list" to an XML file parsable by choco installer. Run with 'choco list -lo | chocoProgramListToXml.ps1"
$xml = "<?xml version=`"1.0`" encoding=`"utf-8`"?>`n"
$xml += "<packages>`n"
foreach ($program in $input) {
$name, $version, $shouldBeEmpty = $program.Split(" ")
if (!$shouldBeEmpty) {
$xml += (" <package id=`"{0}`" version=`"{1}`"/>`n" -f $name,$version)
}
}
$xml += "</packages>`n"
echo $xml
@Nilzor
Nilzor / bash.rc
Last active August 11, 2017 06:20
bash.rc for Android screenshot and recording
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 / statehelper.cs
Created November 15, 2012 13:04
StateHelper
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Messaging;
using GTWin8.Messages;
using GTWin8.Ui;
using Windows.UI.Xaml;
@Nilzor
Nilzor / DictionaryExtensions.cs
Created February 11, 2013 09:32
DictionaryExtensions - safer and simpler get avoiding exceptions. See http://www.nilzorblog.com/2013/01/improving-generic-c-dictionary-with.html
public static class DictionaryExtensions
{
/// <summary>
/// Returns a default value of type U if the key does not exist in the dictionary
/// </summary>
/// <param name="dic">The dictionary to search</param>
/// <param name="key">Key to search for</param>
/// <param name="onMissing">Optional default value of type U. If not specified, the C# default value will be returned.</param>
public static U GetOrDefault<T, U>(this Dictionary<T, U> dic, T key, U onMissing = default(U))
{
@Nilzor
Nilzor / LangUtils.java
Created March 30, 2015 09:29
Java langUtils. Some HashMap and reflection stuff
public class LangUtils {
public static <K,V> ArrayList<V> getOrCreateArrayList(HashMap<K, ArrayList<V>> hashMap, K key) {
ArrayList<V> list = hashMap.get(key);
if (list == null) {
list = new ArrayList<V>();
hashMap.put(key, list);
}
return list;
}
@Nilzor
Nilzor / php-intellij-xdebug-linux.md
Created October 19, 2016 18:59
PHP debugging intellij linux apache2
  • 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