Skip to content

Instantly share code, notes, and snippets.

@julioz
julioz / migration.kt
Last active June 30, 2020 16:48
Migration: copying data, rename table and relax FK constraints
database.execSQL("""
CREATE TABLE IF NOT EXISTS TrackCreator_temp (
`track_id` TEXT NOT NULL,
`user_id` TEXT NOT NULL,
PRIMARY KEY(`track_id`, `user_id`),
FOREIGN KEY(`track_id`) REFERENCES `Track`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION ,
FOREIGN KEY(`user_id`) REFERENCES `User`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
""".trimIndent())
@julioz
julioz / deletion-trigger.log
Created June 30, 2020 16:29
SQLite: INSERT OR REPLACE - Deletion trigger
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "BEGIN EXCLUSIVE;"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "INSERT OR REPLACE INTO `Users` (...) VALUES (...)"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "INSERT OR REPLACE INTO `Users` (...) VALUES (...)"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "-- TRIGGER room_table_modification_trigger_trackuser_DELETE"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "-- UPDATE room_table_modification_log SET invalidated = 1 WHERE table_id = 7 AND invalidated = 0"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "-- TRIGGER room_table_modification_trigger_trackuser_DELETE"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "-- UPDATE room_table_modification_log SET invalidated = 1 WHERE table_id = 7 AND invalidated = 0"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db: "-- TRIGGER room_table_modification_trigger_users_DELETE"
V/SQLiteStatements: /data/com.soundcloud/databases/sc.db:
@julioz
julioz / TrackDao.kt
Created June 30, 2020 16:02
OnConflictStrategy replace for SQLite resolution
@Dao
interface TrackDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(tracks: List<TrackEntity>)
}
@julioz
julioz / create_table_foreign_key_action_example.sql
Created June 30, 2020 15:49
Example of foreign key cascade action
CREATE TABLE IF NOT EXISTS TrackCreator (
`track_id` TEXT NOT NULL,
`user_id` TEXT NOT NULL,
PRIMARY KEY(`track_id`, `user_id`),
FOREIGN KEY(`track_id`) REFERENCES `Track`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ,
FOREIGN KEY(`user_id`) REFERENCES `User`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
@julioz
julioz / floorplan-integration.gradle
Created June 16, 2020 09:06
Example block for integration of FloorPlan as a Gradle Plugin
floorPlan {
schemaLocation = "schemas/"
outputLocation = "floorplan-output/"
outputFormat {
svg {
enabled = true
}
}
}
@julioz
julioz / AudioRecord definition.kt
Created October 27, 2019 11:57
Audio Capture Record definition and configuration
val config = AudioPlaybackCaptureConfiguration.Builder(mediaProjection)
.addMatchingUsage(AudioAttributes.USAGE_MEDIA)
.build()
val audioFormat = AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(8000)
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.build()
@julioz
julioz / AndroidManifest.xml
Created October 27, 2019 11:09
uses-permissions for audio capture
<manifest>
...
<uses-permission android:name="android.permission.RECORD_AUDIO />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
...
</manifest>
@julioz
julioz / AndroidManifest.xml
Created October 27, 2019 10:54
mediaProjection service declaration
<manifest ...>
...
<application >
<service
android:name=".AudioCaptureService"
android:foregroundServiceType="mediaProjection" />
...
</application>
</manifest>
@julioz
julioz / decrypt-mount-bitlocker-disk
Created April 26, 2019 16:15
Decrypt BitLocker disk on Mac OS (tested on High Sierra)
diskutil list # find the parition ID marked as Windows NTFS disk
# if ID is disk3s1, then, input disk password after running
sudo dislocker -V /dev/disk3s1 -u -- externalhdd/
# this will output partition reference
sudo hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount externalhdd/dislocker-file
# Create disk directory
sudo mkdir /Volumes/ExternalHDD
createStrippedAndDebugInfo() {
cd ${REPO_PATH} # assuming we're in your repository's directory
ANDROID_NDK=<PATH_TO_NDK>
TMP_DIR_NAME=tmp_strip_symbols
AAR=`find -name '*.aar'` # find the path to the AAR containing the binaries
mkdir -p ${TMP_DIR_NAME}
try cd ${TMP_DIR_NAME}