Skip to content

Instantly share code, notes, and snippets.

@julioz
julioz / migration.kt
Last active Jun 30, 2020
Migration: copying data, rename table and relax FK constraints
View migration.kt
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 Jun 30, 2020
SQLite: INSERT OR REPLACE - Deletion trigger
View deletion-trigger.log
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 Jun 30, 2020
OnConflictStrategy replace for SQLite resolution
View TrackDao.kt
@Dao
interface TrackDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(tracks: List<TrackEntity>)
}
@julioz
julioz / create_table_foreign_key_action_example.sql
Created Jun 30, 2020
Example of foreign key cascade action
View create_table_foreign_key_action_example.sql
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 Jun 16, 2020
Example block for integration of FloorPlan as a Gradle Plugin
View floorplan-integration.gradle
floorPlan {
schemaLocation = "schemas/"
outputLocation = "floorplan-output/"
outputFormat {
svg {
enabled = true
}
}
}
@julioz
julioz / AudioRecord definition.kt
Created Oct 27, 2019
Audio Capture Record definition and configuration
View AudioRecord definition.kt
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 Oct 27, 2019
uses-permissions for audio capture
View AndroidManifest.xml
<manifest>
...
<uses-permission android:name="android.permission.RECORD_AUDIO />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
...
</manifest>
@julioz
julioz / AndroidManifest.xml
Created Oct 27, 2019
mediaProjection service declaration
View AndroidManifest.xml
<manifest ...>
...
<application >
<service
android:name=".AudioCaptureService"
android:foregroundServiceType="mediaProjection" />
...
</application>
</manifest>
@julioz
julioz / decrypt-mount-bitlocker-disk
Created Apr 26, 2019
Decrypt BitLocker disk on Mac OS (tested on High Sierra)
View decrypt-mount-bitlocker-disk
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
View debug-symbols.sh
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}