Skip to content

Instantly share code, notes, and snippets.

@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
## =============================================
# 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 / 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/'`
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"
# 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
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)
@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