Skip to content

Instantly share code, notes, and snippets.

⚜️
:)

Anton Shkurenko tonyshkurenko

⚜️
:)
Block or report user

Report or block tonyshkurenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tonyshkurenko
tonyshkurenko / Dagger 2, quick start
Last active Jun 18, 2018
Everything I found about Dagger 2
View Dagger 2, quick start
Dagger step 1: Add android-apt, dagger 2, dagger2-compiler, and javax annotation to the build.gradle files.
Note that they're not all "compile" dependencies.
Step 2: Add our module. Our ApplicationModule will be able to inject the ApplicationContext to classes that need it.
Step 3: Add our Component.Dagger 2 generates code for each Component you create,
using the file name Dagger(NameOfComponent).
Example: DaggerApplicationComponent.
Components can have multiple modules, in our case we have one.
View Elegant if-else
int a = in0[i], b = in1[i];
int cmp = a < b; //if TRUE, cmp has all bits 1, if FALSE all bits 0
// & bitwise AND
// | bitwise OR
// ~ flips all bits
out[i] = (a&cmp) | (b&~cmp); //a when TRUE and b when FALSE
View Fractal tree
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class FractalTree extends JFrame {
public FractalTree() {
super("Fractal Tree");
setBounds(100, 100, 800, 600);
setResizable(false);
@tonyshkurenko
tonyshkurenko / RawStringConverter.java
Created Oct 28, 2015
Converter Factory for Retrofit 2.0
View RawStringConverter.java
public class RawStringConverter extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
//noinspection EqualsBetweenInconvertibleTypes
if (String.class.equals(type)) {
return ResponseBody::string;
}
return null;
@tonyshkurenko
tonyshkurenko / styles.xml
Created Oct 30, 2015
No ui activity theme for the AppCompat
View styles.xml
<!-- No ui for appcompat -->
<style name="NoUiAppTheme"
parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowNoDisplay">true</item>
</style>
View Two nice white colors
<color name="GhostWhite">#F8F8FF</color>
<color name="WhiteSmoke">#F5F5F5</color>
View Major-Minor-Patch-Build gradle
import java.util.regex.Pattern
task('increaseVersionCode') << {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"")
View Short bit flags description
This is an example, using a 8-bit unsigned integer to store 8 flags:
`unsigned char options;`
It is common to use larger fields, e.g. 32 bits, but I use 8 here for simplicity.
The possible options, that can be turned on or off independently are declared in an enum like this (just using some arbitrary identifiers):
```
enum Options {
OpAutoRedraw = 0x01,
View WEB_PALETTE
/**
* local max_color_component_value = 255
* local quantum = max_color_component_value / 5
* r = quantum * math.floor((r + (quantum / 2)) / quantum)
* g = quantum * math.floor((g + (quantum / 2)) / quantum)
* b = quantum * math.floor((b + (quantum / 2)) / quantum)
*
* index = (R’*36 + G’*6 + B’) / quantum
*/
View RoundedCornerLayout.java
package com.soundconcepts.mybuilder.ui.widgets;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
You can’t perform that action at this time.