Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
code is fun

Henrique Horbovyi henrikhorbovyi

🤖
code is fun
View GitHub Profile
@henrikhorbovyi
henrikhorbovyi / ServiceBuilder.kt
Created Jul 8, 2020
Service Builder for Retrofit
View ServiceBuilder.kt
/**
* .:.:.:. Created on 07/10/19 .:.:.:.
*/
interface ServiceBuilder {
companion object {
inline operator fun <reified S> invoke(baseUrl: String, authToken: String? = ""): S {
val httpClient = buildInterceptors(authToken)
return Retrofit.Builder()
.baseUrl(baseUrl)
View ANDROID_SETUP_LIBS.MD

ANDROID TOOLBOX

NAVIGATION

apply plugin: 'androidx.navigation.safeargs'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07"

AndroidX
implementation "androidx.navigation:navigation-fragment-ktx:2.0.0"
implementation "androidx.navigation:navigation-ui-ktx:2.0.0"

View Extensions.kt
// use >> 10.dp(context)
fun Int.dp(context: Context): Float {
return this * context.resources.displayMetrics.density
}
/* View Extensions */
// use >> bindView(R.id.example)
fun <V : View> Activity.bindView(@IdRes id: Int) = unsafeLazy { findViewById<V>(id) }
inline fun <T> unsafeLazy(noinline initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer)
View TestAdapter.kt
class TestListAdapter(private val context: Context) : RecyclerView.Adapter<TestListAdapter.ViewHolder>(){
private val data: MutableList<TestModel> = mutableListOf()
override fun getItemCount(): Int = data.count()
override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.list_Test, parent ,false)
return ViewHolder(view)
}
View TestModel.kt
data class TestModel(val id: Int = 0, val name: String? = null)
View TestActivity.kt
class TestActivity : AppCompatActivity() {
// you can use 'by lazy' in this case, and volley object will be instantiated only when needed
private val volleyRequest: RequestQueue by lazy { Volley.newRequestQueue(this) }
private val testList: MutableList<TestModel> = mutableListOf()
// you don't need to pass parameters, just need to change a bit the implementation of your Adapter class.
private val adapter: TestListAdapter = TestListAdapter(this)
// don't need to create this variable if you are not using more than 1 time
//private var layoutManager: RecyclerView.LayoutManager?=null
View multiple_file_upload.php
for($i=0; $i<count($_FILES['file']['name']); $i++) {
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
$shortname = $_FILES['file']['name'][$i];
$filename = date('YmdHis').$_FILES['file']['name'][$i];
$filePath = "./public/course_work/".$filename;
$ext = pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION);
$file = basename($shortname,".".$ext);
View AddDividerOnRecyclerViewItem.kt
recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
@henrikhorbovyi
henrikhorbovyi / Github Emojis
Created Apr 6, 2016
Gihub emojis to improve my commits. :D
View Github Emojis
http://www.emoji-cheat-sheet.com/
@henrikhorbovyi
henrikhorbovyi / mix_services.sh
Created Apr 4, 2016
A script to join in one place all services that I need in my environment.
View mix_services.sh
#!/bin/bash
service=$1
action=$2
if [ $service == 'lampp' ]
then
sudo /opt/lampp/./manager $action
else
sudo service $service $action