Skip to content

Instantly share code, notes, and snippets.

View henriquehorbovyi's full-sized avatar
🤖

Henrique Horbovyi henriquehorbovyi

🤖
View GitHub Profile
@henriquehorbovyi
henriquehorbovyi / nodes.kt
Last active April 5, 2022 15:46
operations for ListNode like classes
data class Node<T>(var value: T, var next: Node? = null)
fun <T> buildNodeList(vararg items: T): Node<T>? {
if (items.isEmpty())
return null
val head = Node(items.first())
if (items.size == 1) return head
const val ISO6801 = "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'"
const val HUMAN_FORMAT = "dd/MM/yyyy \'at\' HH:mm"
/*
* Sample:
* "2021-10-24T14:32:12Z".formatAsDate(ISO6801, HUMAN_FORMAT)
* */
fun String.formatAsDate(patternInput: String, patternOutput: String): String {
@henriquehorbovyi
henriquehorbovyi / ServiceBuilder.kt
Created July 8, 2020 17:59
Service Builder for Retrofit
/**
* .:.:.:. 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)

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"

// 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)
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)
}
data class TestModel(val id: Int = 0, val name: String? = null)
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
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);
recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager.VERTICAL));