Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View meoyawn's full-sized avatar

Adel Nizamutdinov meoyawn

View GitHub Profile
@meoyawn
meoyawn / build.gradle
Created October 15, 2014 08:59
gradle script that sorts *@*dpi.png files into *dpi folders
final tree = fileTree("./assets").include('**/*@*dpi.png')
String normalize(String src) {
return src.replaceAll(/ /, "_")
}
tree.each { f ->
final m = f.name =~ /(.*)@(.*dpi)\.png/
final name = m[0][1]
final density = m[0][2]
@meoyawn
meoyawn / EmptyRecyclerView.java
Created November 1, 2014 11:20
RecyclerView doesn't have an emptyView support, we gotta fix that
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EmptyRecyclerView extends RecyclerView {
@Nullable View emptyView;
/*
MIT License
Copyright (c) 2015 Adel Nizamutdinov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
import android.media.MediaRecorder;
import android.support.annotation.NonNull;
import com.f2prateek.rx.android.schedulers.AndroidSchedulers;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.subscriptions.Subscriptions;
public class RxMediaRecorder {
task migrateMipmap << {
fileTree('src').include('**/res/drawable*/ic_launcher.png').each { icon ->
final p = file(icon.parent.replaceAll("drawable", "mipmap"))
p.mkdirs()
final dest = new File(p, icon.name)
icon.renameTo(dest)
}
}
#!/bin/sh
set -e
appId=$1
dst=/sdcard/container-${appId}
tar=/sdcard/container-${appId}.tar.gz
backup_file=${appId}.ab
rm -f $backup_file
@meoyawn
meoyawn / lens.kt
Last active August 29, 2015 14:27
data class Lens<S, A>(val get: (S) -> A, val set: (A, S) -> S)
fun <A, B, C> Lens<A, B>.compose(that: Lens<C, A>): Lens<C, B> =
Lens({ this.get(that.get(it)) }, { c, a -> that.set(this.set(c, that.get(a)), a) })
fun <A, B> Lens<A, B>.traverse(): Lens<List<A>, List<B>> =
Lens({ it.map { get(it) } }, { bs, aas -> bs.zip(aas).map { this.set(it.first, it.second) } })
object Play {
data class Point(val x: Double, val y: Double) {
@meoyawn
meoyawn / gc.kt
Last active November 8, 2015 20:09
play a very scary sound on each GC trigger
import rx.Observable
import rx.Subscriber
import rx.schedulers.Schedulers
import java.lang.ref.PhantomReference
import java.lang.ref.ReferenceQueue
fun gcTriggers(): Observable<Unit> =
Observable.create(triggerLoop())
.subscribeOn(Schedulers.newThread())
@meoyawn
meoyawn / Cargo.toml
Created May 26, 2016 20:52
Simple JNI with Kotlin and Rust
[package]
name = "hello"
version = "0.1.0"
authors = ["adelnizamutdinov"]
[lib]
crate-type = ["dylib"]
[dependencies]
jni-sys = "0.1.0"
@meoyawn
meoyawn / cursor.kt
Created July 21, 2016 09:33
folding cursors all day
inline fun <T> Cursor.fold(zero: T, f: (Cursor, T) -> T): T =
if (moveToFirst()) {
moveToPrevious()
var accum = zero
while (moveToNext()) {
accum = f(this, accum)
}
accum
} else zero