Skip to content

Instantly share code, notes, and snippets.

View xrubioj's full-sized avatar

Xavier Rubio Jansana xrubioj

View GitHub Profile
@tomaszpolanski
tomaszpolanski / Comparison.txt
Last active October 25, 2022 21:29
Kotlin Standard comparison
╔══════════╦═════════════════╦═══════════════╦═══════════════╗
║ Function ║ Receiver (this) ║ Argument (it) ║ Result ║
╠══════════╬═════════════════╬═══════════════╬═══════════════╣
║ let ║ this@MyClass ║ String("...") ║ Int(42) ║
║ run ║ String("...") ║ N\A ║ Int(42) ║
║ run* ║ this@MyClass ║ N\A ║ Int(42) ║
║ with* ║ String("...") ║ N\A ║ Int(42) ║
║ apply ║ String("...") ║ N\A ║ String("...") ║
║ also ║ this@MyClass ║ String("...") ║ String("...") ║
╚══════════╩═════════════════╩═══════════════╩═══════════════╝
@dedeexe
dedeexe / URLRequest+curlCommand.swift
Last active April 17, 2020 13:08
Convert URL Request to curl command
extension URLRequest {
public func curl(pretty:Bool = false) -> String {
var data : String = ""
let complement = pretty ? "\\\n" : ""
let method = "-X \(self.httpMethod ?? "GET") \(complement)"
let url = "\"" + self.url?.absoluteString ?? "" + "\""
var header = ""
@josh-burton
josh-burton / androidmanifest.xml
Created May 3, 2017 02:07
Prevent TouchWiz from surrounding your app icon in a frame
<!-- Prevents TouchWiz from surrounding your app icon in a frame -->
<!-- Add to your manifest inside the application tag -->
<meta-data
android:name="com.samsung.android.icon_container.has_icon_container"
android:value="true"/>
@nickbutcher
nickbutcher / timestamp.sh
Created April 3, 2017 11:31
A script for setting creation and modification dates on all files within a folder. Specify the first date in the script then all files are stamped in alphabetical order, increasing by 1s.
USAGE="Set the desired date/time in the script and then call: timestamp /path/to/folder"
DATE="022109002017" # month day hour min year
if (( $# != 1 )); then
echo "Illegal parameters"
echo $USAGE
exit 2
fi
if [ ! -d $1 ]; then
@algal
algal / ScaleAspectFitImageView.swift
Last active September 24, 2023 10:19
UIImageView subclass that works with Auto Layout to express its desired aspect ratio
import UIKit
// known-good: Xcode 8.2.1
/**
UIImageView subclass which works with Auto Layout to try
to maintain the same aspect ratio as the image it displays.
This is unlike the usual behavior of UIImageView, where the
@markus2610
markus2610 / RealmTypeAdapter.kt
Last active March 21, 2017 10:51
Kotlin Realm Primitive Arrays Workaround for Moshi
package de.wdv.apps.yoursingapore.core.moshi
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import de.wdv.apps.yoursingapore.core.realm.RealmIntArray
import de.wdv.apps.yoursingapore.core.realm.RealmLongArray
import de.wdv.apps.yoursingapore.core.realm.RealmStringArray
import java.lang.reflect.Type
@DarrenAtherton49
DarrenAtherton49 / GetPosts.kt
Last active July 21, 2017 15:43
Parameterised reactive use cases in Kotlin
class GetPosts @Inject constructor(
uiExecutor: UiExecutor,
@Named("ioExecutor") backgroundExecutor: BackgroundExecutor,
private val redditRepository: RedditRepository
) : ReactiveUseCase<List<RedditLink>>(uiExecutor, backgroundExecutor) {
fun execute(onNext: (List<RedditLink>) -> Unit,
onError: (Throwable) -> Unit,
onCompleted: () -> Unit) {
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.view.View;
@android10
android10 / AndroidApplication.java
Created July 20, 2016 09:56
Android: how to know if your app is completely hidden
public class AndroidApplication extends MultiDexApplication {
public static final String TAG = AndroidApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
registerComponentCallbacks(new ComponentCallback());
}
private class ComponentCallback implements ComponentCallbacks2 {
@kabadisha
kabadisha / dedup-imovie-library
Last active November 7, 2017 06:46 — forked from bhollis/dedup-imovie-library
When you import movies into iMovie 10 libraries, the file is always copied, wasting space and hindering editability. This script replaces the copy with a hardlink, reclaiming disk space.
#!/usr/bin/env ruby
# Usage: dedup-imovie-library LIBRARY ORIGINALS
#
# Goes through an iMovie 10 library and replaces all the "Original Media" with
# symlinks to the actual original media, in order to conserve disk space. Note
# that because they're symlinks, if the path to the originals changes (e.g. you
# rename the external drive they are on) then the links will be broken.
#
# This assumes you've already imported the files into iMovie and waited for them