Skip to content

Instantly share code, notes, and snippets.

View artem-zinnatullin's full-sized avatar
😞

Artem Zinnatullin artem-zinnatullin

😞
View GitHub Profile
public static String getIntentExtrasAsString(Intent intent) {
if (intent == null || intent.getExtras() == null || intent.getExtras().isEmpty()) return "no extras or null intent";
StringBuilder stringBuilder = new StringBuilder();
for (String key : intent.getExtras().keySet()) {
stringBuilder.append("(" + key + ", " + intent.getExtras().get(key) + ")")
.append(", ");
}
@artem-zinnatullin
artem-zinnatullin / ShortCreateAndFillCollection
Created August 28, 2014 13:59
Short write of Collection creation and filling
Collection<String> stringsCollection = new ArrayList<String>() {
{
add("1");
add("2");
add("3");
}
};
@artem-zinnatullin
artem-zinnatullin / Dangerous.java
Created August 29, 2014 14:09
Dangerous annotation for Java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark code as dangerous
*
* @author Artem Zinnatullin [artem.zinnatullin@gmail.com]
*/
@artem-zinnatullin
artem-zinnatullin / build.gradle
Created January 27, 2015 17:01
Root build.gradle with Kotlin Gradle plugin
buildscript {
repositories {
jcenter() // or use mavenCentral() repo
}
// Please visit http://search.maven.org
// or https://bintray.com to find newest versions of dependencies
dependencies {
// Android Gradle plugin
classpath 'com.android.tools.build:gradle:1.0.1'
@artem-zinnatullin
artem-zinnatullin / HelloKotlinOnAndroid.kt
Created January 27, 2015 17:32
Hello Kotlin On Android
package nice.is.kotlin
import android.content.Context
import android.widget.Toast
class HelloKotlinOnAndroid {
public fun yo(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
}
}
@artem-zinnatullin
artem-zinnatullin / YourApp.java
Last active August 29, 2015 14:26
Fix for performance issue in RxJava 1.0.3+
// Issue: https://github.com/ReactiveX/RxJava/issues/3119
class YourApp extends Application {
static {
// I recommend you to put this code into static initialization block of Application class
// because Application class will be loaded before you will start doing some work via RxJava
// PLEASE add comment "remove fix from app class… when you'll switch to new version of RxJava"
// near to "compile 'io.reactivex:rxjava:1.0.13'" in your build.gradle
System.setProperty("rx.scheduler.jdk6.purge-force", "true");
@artem-zinnatullin
artem-zinnatullin / GCMHelper.java
Last active December 30, 2015 05:39 — forked from beshkenadze/GCMHelper.java
GCMHelper improvements
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
@artem-zinnatullin
artem-zinnatullin / App.cs
Created December 20, 2013 22:28
Changing windows phone app localization at runtime via bindings!
public class App : Application
{
// ... bla bla
// when app is launching, we should set its language to previous saved or best for user's system language or default for application
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LocalizationManager.ChangeAppLanguage(LocalizationManager.GetCurrentAppLang());
}
}

Guidelines

To keep the arguments and examples to the point there are few helpful rules:

  • No abstract examples/arguments. These cause the discussion to lose focus and make examples harder to follow. The example/argument must be traceable to a real-world problem - ___ is intended to solve real problems, not imaginary ones.
  • Examples must show the full complexity of the problem domain. Simplified examples trivialize the problems and the solutions intended to solve those simplified examples may not work for the complex problems.
  • Examples of problematic ___ code must be the “best way” of writing the code in ___ - if it can be improved then the improved version should be used instead.
  • Arguments must be straight to the point and as concise as possible.
  • Arguments should take the point of view of an average programmer - not the über-programmer who doesn’t make design mistakes.
@artem-zinnatullin
artem-zinnatullin / ValidationProcessor.java
Created September 20, 2018 18:04
Dagger1: allow @scope annotations on Dagger2 Components
/*
* Copyright (C) 2013 Google, Inc.
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*