Skip to content

Instantly share code, notes, and snippets.

View Bringoff's full-sized avatar

Artem Kalachian Bringoff

View GitHub Profile
@Bringoff
Bringoff / complex_modification_lang_switcher.json
Last active June 13, 2022 14:56
Karabiner language switcher (different shortcuts for different languages)
{
"title": "Language toggler",
"rules": [
{
"description": "Left_Shift+Left_Command=Ru",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "left_shift",
@Bringoff
Bringoff / main.kt
Created November 17, 2021 11:40
Circular references
fun main(args: Array<String>) {
Inner().nodes()
readLine()
System.gc()
readLine()
}
class Inner {
@Bringoff
Bringoff / main.dart
Created September 16, 2021 08:50
Can't switch on generic lists
void main() {
print(getAttribute<List<String>>(['1', '2']));
}
T getAttribute<T>(dynamic rawAttribute) {
switch (T) {
case bool:
return rawAttribute ?? false;
case String:
return rawAttribute ?? '';
void main() {
final result = SuccessFailure<int, void>.success(null);
if (result.isSuccess) { // надо будет result.isSuccess && result.success != null. Вообще весь смысл этого класса теряется
print(result.success + 5);
}
}
typedef Callback<T> = void Function(T value);
class SuccessFailure<S, F> {
@Bringoff
Bringoff / main.dart
Created March 19, 2021 20:54
Parallel streams
void main() async {
upload(1).listen((event) {});
await Future.delayed(Duration(seconds: 1));
upload(2).listen((event) {});
await Future.delayed(Duration(seconds: 1));
upload(3).listen((event) {});
await Future.delayed(Duration(seconds: 1));
upload(4).listen((event) {});
await Future.delayed(Duration(seconds: 1));
upload(5).listen((event) {});
@Bringoff
Bringoff / BillingClientWithLifecycle.java
Created June 13, 2020 13:20
Common interface for Google Play and Galaxy Store subscriptions
public interface BillingClientWithLifecycle extends LifecycleObserver {
Subject<BillingResult> getPurchases();
Subject<List<AvailableProductDetails>> getAvailablePurchasesDetails();
void updatePurchases();
void onPurchasesUpdated(int responseCode, @Nullable List<BillingClientWithLifecycle.OwnedProduct> purchases);
void launchBillingFlow(Activity activity, String productId);
@Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
...
UsageAccessHelper.ActivityData realActivity = appStatsHelper.getCurrentActivity();
realActivityName = realActivity.getActivityFullName();
checkIfPictureInPicture(realActivityName);
}
private void checkIfPictureInPicture(String activityName) {
if ("com.android.systemui/.pip.phone.PipMenuActivity".equals(activityName)) {
@Bringoff
Bringoff / DrawOverPermissionActivationListener.java
Last active February 14, 2019 09:30
Overlay drawing permission is activated on separate screen. But after activation that permission some users can't figure out how to return to the original app. Good approach is to open the app automatically after activation. The problem is we cannot listen to overlay permission changes. So here is workaround.
/**
* Looks like there is no adequate way to listen to this permission change, so do workaround here.
* Normally, we check the permission every 0.5 second. But on Oreo this won't work as Settings.canDrawOverlays still
* returns false after activation but before returning to the app (bug https://issuetracker.google.com/issues/66072795).
* Use OnOpChangedListener on Oreo.
*/
public class DrawOverPermissionActivationListener implements LifecycleObserver {
private AppCompatActivity activity;
private final OverlayManager overlayManager;
private final Class activityToBringToFrontOnDetection;
@Bringoff
Bringoff / App.java
Created July 2, 2018 07:36
Implicit broadcast dynamic registration solution for target sdk >= 26
...
private Set<ImplicitBroadcastRegistrationLifecycleObserver> getRequiredRegistrators() {
Set<ImplicitBroadcastRegistrationLifecycleObserver> registrators = new HashSet<>();
registrators.add(new AppInstallationObserver(this));
...
return registrators;
}
@Override
public void onCreate() {
@Bringoff
Bringoff / build.gradle
Created October 5, 2017 12:26
Lint gradle example config
...
apply from: 'lint-checks.gradle'
...
android {
...
lintOptions {
textReport true
abortOnError true
warningsAsErrors true