Skip to content

Instantly share code, notes, and snippets.

View JakeSteam's full-sized avatar
🤖

Jake Lee JakeSteam

🤖
View GitHub Profile
@JakeSteam
JakeSteam / ItemAdapter.kt
Last active April 22, 2024 09:56
Creating a grid RecyclerView with quick drag and drop item swapping, Room / LiveData support, and more!
class ItemAdapter(
private val itemClickListener: (OwnedItem) -> Unit,
private val itemSaver: (List<OwnedItem>) -> Unit
) : RecyclerView.Adapter<ItemViewHolder>() {
val items = ArrayList<OwnedItem>()
fun setItems(newItems: List<OwnedItem>) {
val result = calculateDiff(newItems)
items.clear()
@JakeSteam
JakeSteam / MyClass.kt
Last active March 23, 2024 19:24
Accessing Android app secrets from GitHub Actions using Gradle (https://blog.jakelee.co.uk/accessing-android-app-secret-from-github-actions-using-gradle/)
package uk.co.jakelee.apodwallpaper.example
import uk.co.jakelee.apodwallpaper.BuildConfig
class MyClass() {
val key = BuildConfig.APOD_API_KEY
}
@JakeSteam
JakeSteam / LevelHelper.java
Last active March 10, 2024 16:00
"Converting Levels Into XP & Vice Versa" for GameDevAlgorithms.com
public static int convertXpToLevel(int xp) {
// Level = 0.05 * sqrt(xp)
return (int) (Constants.LEVEL_MODIFIER * Math.sqrt(xp));
}
public static int convertLevelToXp(int level) {
// XP = (Level / 0.05) ^ 2
return (int) Math.pow(level / Constants.LEVEL_MODIFIER, 2);
}
@JakeSteam
JakeSteam / AndroidManifest.xml
Created April 28, 2019 21:13
"How to programmatically change your Android app icon and name" for http://blog.jakelee.co.uk/programmatically-changing-app-icon
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.jakelee.dynamiciconchanging">
<application
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
@JakeSteam
JakeSteam / AndroidManifest.xml
Last active February 23, 2023 14:42
"Generic SharedPreferences Utility Class" for blog.jakelee.co.uk
<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
@JakeSteam
JakeSteam / coins.svg
Created February 1, 2023 09:51
Cleaning up an SVG for Minima 3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JakeSteam
JakeSteam / maze.as
Created January 5, 2023 22:20
"Scary Maze Game" decompiled
package
{
import com.google.ads.instream.api.AdErrorEvent;
import com.google.ads.instream.api.AdEvent;
import com.google.ads.instream.api.AdLoadedEvent;
import com.google.ads.instream.api.AdSizeChangedEvent;
import com.google.ads.instream.api.AdsLoadedEvent;
import com.google.ads.instream.api.AdsLoader;
import com.google.ads.instream.api.AdsManager;
import com.google.ads.instream.api.AdsManagerTypes;
@JakeSteam
JakeSteam / Car.kt
Last active November 4, 2022 11:25
How to extract a Room list column into a new linked table, migrating data https://blog.jakelee.co.uk/how-to-extract-a-room-list-column-into-a-new-linked-table-migrating-data/
class Car(
@Embedded
val metadata: CarMetadata,
@Relation(
parentColumn = "id", // The name of the CarMetadata ID field
entityColumn = "carId" // The name of the Component's car ID field
)
var components: List<Component>
)
@JakeSteam
JakeSteam / settings.ini
Created March 8, 2022 23:14
IrfanView replace image with black background and filename
; UNICODE FILE - edit with care ;-)
[Batch]
AdvCrop=0
AdvCropX=0
AdvCropY=0
AdvCropW=0
AdvCropH=0
AdvCropC=0
AdvResize=0
@JakeSteam
JakeSteam / VisitorHelper.java
Created January 24, 2017 19:11
"Android: Selecting A Weighted Random Item From A List" for GameDevAlgorithms.com
private static Visitor_Type selectVisitorType() {
Visitor_Type visitor = new Visitor_Type();
List<Visitor_Type> visitorTypes = Visitor_Type.findWithQuery(Visitor_Type.class,
"SELECT * FROM VisitorType WHERE visitor_id NOT IN (SELECT type FROM Visitor)");
// Work out the total weighting.
double totalWeighting = 0.0;
for (Visitor_Type type : visitorTypes) {
totalWeighting += type.getWeighting();