Skip to content

Instantly share code, notes, and snippets.

View paulproteus's full-sized avatar

Asheesh Laroia paulproteus

View GitHub Profile
@paulproteus
paulproteus / MainActivity.kt
Created May 6, 2020 14:53
AbsoluteLayout Kotlin demo with two buttons
package org.asheesh.fourbuttonsattwohundredpixels
import android.R.attr.delay
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.widget.AbsoluteLayout
import android.widget.Button
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
@paulproteus
paulproteus / MainActivity.kt
Created May 6, 2020 15:01
RelativeLayout abused for absolute layout :)
package org.asheesh.fourbuttonsattwohundredpixels
import android.R.attr.delay
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.widget.Button
import android.widget.RelativeLayout
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
@paulproteus
paulproteus / MainActivity.kt
Created May 6, 2020 16:10
Constrain button width to a max width
package org.asheesh.fourbuttonsattwohundredpixels
import android.os.Bundle
import android.os.Handler
import android.util.DisplayMetrics
import android.view.View
import android.widget.Button
import android.widget.RelativeLayout
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
@paulproteus
paulproteus / app.py
Created May 11, 2020 02:34
HelloWorld toga/beeware app on Android
"""
My first application
"""
import toga
from toga.constants import RIGHT
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
Minor layout bug
@paulproteus
paulproteus / CustomSpinnerAdapter.kt
Created May 12, 2020 04:18
A weirdo spinner I suppose
package org.asheesh.fourbuttonsattwohundredpixels
import android.database.DataSetObserver
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.SpinnerAdapter
import android.widget.TextView
class CustomSpinnerAdapter: SpinnerAdapter {
// SNIPPET
// Create a Spinner
val spinner = Spinner(this, Spinner.MODE_DROPDOWN)
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item,
arrayOf("Option 1", "Option 2", "Option 3"))
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter
spinner.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val spinnerParams = RelativeLayout.LayoutParams(spinner.measuredWidth, spinner.measuredHeight)
dynamicLayout.addView(spinner, spinnerParams)
@paulproteus
paulproteus / log.txt
Created May 16, 2020 22:55
Logs on app startup without any infinite loop checking in NumberInput on Android
05-16 15:52:01.587 10790 10817 D stdio : Rubicon namespace package not registered!
05-16 15:52:02.994 10790 10817 D stdio : Python app launched & stored in Android Activity class
05-16 15:52:02.996 10790 10817 D stdio :
05-16 15:52:03.097 10790 10817 D stdio : Seems to have a loop for None
05-16 15:52:03.097 10790 10817 D stdio : letting it continue anyway
05-16 15:52:03.100 10790 10817 D stdio : Would have caught loop in set_value(), but continuing anyway
05-16 15:52:03.103 10790 10817 D stdio : Seems to have a loop for None
05-16 15:52:03.103 10790 10817 D stdio : letting it continue anyway
05-16 15:52:03.103 10790 10817 D stdio : Would have caught loop in set_value(), but continuing anyway
05-16 15:52:03.105 10790 10817 D stdio : Seems to have a loop for None
@paulproteus
paulproteus / Upload a 3TB block device straight to GDrive.txt
Last active May 26, 2020 01:57
Upload a 3TB block device straight to GDrive
https://github.com/labbots/google-drive-upload
+ patch out some `-f` checks to be `-e` (since `-f` is false on a block device)
+ replace `wc -c` with `blockdev --getsize64 $filename` to avoid spending 6 hours on `wc -c` before even uploading
+ `cp -a` the block device to /tmp/ with a nice filename, so google-drive-upload uses that as the GDrive filename
Wait 6 hours or so.
Then figure out the MD5 thing to validate the upload.
@paulproteus
paulproteus / Faster disk erase.txt
Last active June 5, 2020 19:52
Faster disk erase
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero | pv -pterb -s $(blockdev --getsize64 /dev/sdb) | sudo dd bs=4M of=/dev/sdb
Thanks to https://serverfault.com/questions/6440/is-there-an-alternative-to-dev-urandom/415962
Note per https://tches.iacr.org/index.php/TCHES/article/view/8392 it may not be as secure as one might dream, but I'm OK with this given my use.
This lets me write to the disk at 128MiB/s, which is better than the ~20MiB/s I was getting when doing the naive
cat /dev/urandom | pv | sudo dd of=/dev/sdb