Skip to content

Instantly share code, notes, and snippets.

View dron247's full-sized avatar

dron247 dron247

View GitHub Profile
@dron247
dron247 / SessionExpiredInterceptor.java
Created January 23, 2017 04:28
Okhttp 401 interceptor, handles session expired error
package com.company.product.net.interceptor;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
* Connect this interceptor to okhttp3 line to intercept all 401 answers from service and get callback
// multicallback example
namespace com.example {
class Runner {
var devices = new List<Item>();
void foo(){
devices.Add(new Item());
devices.Add(new Item(Handler));
}
@dron247
dron247 / NoInflateAdapterExample.java
Created March 21, 2017 05:00
Example implementation of an recycler adapter without xml markup used. No inflate - no problemo
// this is an internal class in example activity
// check file name and access modifiers before use
static class ExampleAdapter extends RecyclerView.Adapter<ExampleAdapter.ViewHolder> {
List<TodoListItem> items;
ClickListener clickListener;
Resources resources;
int DP16;
ExampleAdapter(Context context, List<TodoListItem> items) {
public static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null)
{
var filePath = assembly.Location;
const int c_PeHeaderOffset = 60;
const int c_LinkerTimestampOffset = 8;
var buffer = new byte[2048];
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
stream.Read(buffer, 0, 2048);
@dron247
dron247 / TestListAdapter.kt
Created March 24, 2017 15:29
Example imutable RecyclreView adapter made on Kotlin. Item click listener passed as parameter.
package com.dementiev.realtest
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.util.TypedValue
import android.view.animation.AnimationUtils
import android.widget.LinearLayout
@dron247
dron247 / ViewHelper.java
Created March 26, 2017 08:37
View expand/collapse helper
package com.dgse.grukoza_body_composition_tracker.helpers;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* Created by Андрей on 26.09.2014.
*/
@dron247
dron247 / omnisharp.json
Created March 29, 2017 05:07
Slightly better settings for C# formatter in VS Code.
{
"FormattingOptions": {
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInAccessors": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
@dron247
dron247 / ListTextBreaker.java
Created April 5, 2017 03:59
This code for ViewHolder helps you to shorten your text lines which do not fit into your list item. Smooth scroll as a result.
int maxWidth = viewHolder.viewGroup.getWidth();
TextPaint textPaint = viewHolder.titleView.getPaint();
String title = cursor.getString(ArticlesQuery.TITLE);
int chars = textPaint.breakText(title, true, maxWidth, null);
if (chars < title.length()) {
title = title.substring(0, chars);
}
viewHolder.titleView.setText(title);
@dron247
dron247 / LocalizedText.cs
Created April 5, 2017 07:23
Unity localization example
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Text))]
public class LocalizedText : MonoBehaviour {
// Use this for initialization
void Awake() {
var stringId = gameObject.name;
var language = Application.systemLanguage;