Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
package net.coding.lucas.screenheight;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
@pablisco
pablisco / Logger.kt
Last active May 17, 2018 10:35
Fluent Logging with Kotlin
inline fun <A> A.logWith(logger: Logger, block: Logger.(A) -> Unit) : A =
this.also { logger.block(it) }
// With interface injection
interface HasLog {
val log: Logger
fun <A> A.log(block: Logger.(A) -> Unit) : A =
logWith(logger, block)
}
@sfeatherstone
sfeatherstone / ArrayCat.kt
Last active June 21, 2018 13:39
Exploring different ways to add/concatenate two arrays in Kotlin
//Copy using arraycopy
fun catTwoIntArrays1(array1 :IntArray, array2 :IntArray) : IntArray {
val newArray = IntArray(array1.size + array2.size)
System.arraycopy(array1, 0, newArray, 0 , array1.size)
System.arraycopy(array2, 0, newArray, array1.size , array2.size)
return newArray
}
//Copy using for loops
fun catTwoIntArrays2(array1 :IntArray, array2 :IntArray) : IntArray {
/**
* (C) Copyright 2018 Paulo Vitor Sato Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@unrarp
unrarp / GridLineView.java
Created November 6, 2013 14:27
Custom Android view that divides its layout into a grid by drawing equally spaced lines both horizontally and vertically
package com.rahul.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class GridLineView extends View {
@sergiocasero
sergiocasero / DaoGenerator.kt
Created April 25, 2019 09:39
DaoGenerator code template for IntelliJ/AS
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
@alphamu
alphamu / CameraMicPermissionHelper.java
Last active May 17, 2019 09:03
Gist showing use cases of headless Fragments to request Android-M runtime permissions
public class CameraMicPermissionHelper extends Fragment {
private static final int REQUEST_CAMERA_MIC_PERMISSIONS = 10;
public static final String TAG = "CamMicPerm";
private CameraMicPermissionCallback mCallback;
private static boolean sCameraMicPermissionDenied;
public static CameraMicPermissionHelper newInstance() {
return new CameraMicPermissionHelper();
}
@bitristan
bitristan / jni-build.gradle
Created March 23, 2015 15:11
use gradle to compile jni with custom Android.mk
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.your.application.id"
minSdkVersion 15
targetSdkVersion 21
@poteto
poteto / _media_queries.sass
Created October 22, 2012 13:54
Sass media queries
// Standard device screen widths
$iphone-portrait: 320px
$iphone-landscape: 480px
$ipad-portrait: 767px
$ipad-landscape: 980px
$desktop: 1224px
$desktop-large: 1824px
// General device targeting
// Use: Only use if you want the style to apply to many devices
@motorro
motorro / prepopulate-MainActivityModel.kt
Created March 12, 2020 15:40
New database instance
val db = Room
.databaseBuilder(getApplication(), CitiesDb::class.java, "cities.db")
.createFromAsset("databases/cities.db")
.fallbackToDestructiveMigration() // On version update - just copy over
.build()