Skip to content

Instantly share code, notes, and snippets.

@fada21
fada21 / ImageRotator.kt
Last active March 15, 2022 07:44
Code for checking image orientation with exif, downsampling and rotating
package com.fada21.android
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import androidx.exifinterface.media.ExifInterface
import java.io.File
import java.io.FileInputStream
import java.io.IOException
package test
import io.reactivex.Observable
import io.reactivex.observers.TestObserver
import io.reactivex.rxkotlin.toObservable
import org.junit.Before
import org.junit.Test
class EndlessStreamWithListsToFilterKotlinTest {
val list1 = listOf(1, 2, 3, 4)
# gitconfig with aliases
cat > ~/.gitconfig << EOF
[alias]
list = !git config -l | grep alias | cut -c 7-
up = fetch
st = status
br = branch
brn = !git rev-parse --abbrev-ref HEAD
brd = branch -D
co = checkout
DEFAULT_API_VERSION=`cat dockerImageSha`
if [ ! -z $1 ] ; then echo "setting API_VERSION to $1"; else echo "API_VERSION not set, using default: $DEFAULT_API_VERSION"; fi
API_VERSION=${1:-$DEFAULT_API_VERSION}
export API_VERSION
echo "API_VERSION set to $API_VERSION"
@fada21
fada21 / fetchSiteCertSha256Base64
Last active November 10, 2020 01:03
Given a domain name, the code below prints out the public keys in the chain as a SHA-256 hash using base 64 encoding.
# use like ./certs.sh www.google.com
#!/bin/bash
certs=`openssl s_client -servername $1 -host $1 -port 443 -showcerts </dev/null 2>/dev/null | sed -n '/Certificate chain/,/Server certificate/p'`
rest=$certs
while [[ "$rest" =~ '-----BEGIN CERTIFICATE-----' ]]
do
cert="${rest%%-----END CERTIFICATE-----*}-----END CERTIFICATE-----"
rest=${rest#*-----END CERTIFICATE-----}
echo `echo "$cert" | grep 's:' | sed 's/.*s:\(.*\)/\1/'`
## =============================================
# peek on gms service
adb -s emulator-5554 shell dumpsys activity service GcmService --endpoints <package>
## =============================================
# MITM
MY_IP=$(ifconfig wlan0 | sed -rn 's/.*inet addr:(.+) Bcast:.*/\1/p')
mitmproxy -i $MY_IP -p 8888
# proxy enabled emulators
/home/fada21/Android/Sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5X_API_23 -http-proxy localhost:8888
@fada21
fada21 / findPrimes.scala
Created August 31, 2014 20:28
findPrimes
def findPrimes(toInt: Int): Seq[Int] = {
def eras(l: Seq[Int]): Seq[Int] = {
val size = l.size
val mlist = collection.mutable.IndexedSeq(l:_*)
def crossout(x: Int): Unit = {
def crossout(xbase: Int, x: Int):Unit = {
if (x<size) {
mlist(x) = 0
# ubuntu/mint setup tips
# SETUP ============
## =================
# http://mintguide.org/tools/317-make-a-bootable-flash-drive-from-an-iso-image-on-linux-mint.html
# df # lists mounted devices
# sudo dd if=/home/USER/linuxmint.iso of=/dev/sdb
# watch -n5 'sudo kill -USR1 $(pgrep ^dd)' # monitoring dd progress
# git ppa
sudo add-apt-repository ppa:git-core/ppa
@fada21
fada21 / scala_snippets.scala
Last active August 6, 2016 16:48
scala snippets
val line2nums = io.StdIn.readLine.split(" ").map(_.toInt)
val lines2nums = io.Source.stdin.getLines().map(_.toInt)
val streamOfInts = Stream.continually(io.StdIn.readInt())
val fib = {
def f(f0:Int, f1:Int): Stream[Int] = f0 #:: f(f1, f0 + f1)
f(0,1)
}
//fib(18)
//fib.take(19).toList
@fada21
fada21 / android_OnGlobalLayoutListener
Last active August 29, 2015 14:00
ViewTreeObserver.OnGlobalLayoutListener() handling
{
final ViewTreeObserver viewTreeObserver = someView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
viewTreeObserver.removeGlobalOnLayoutListener(this);
} else {