Skip to content

Instantly share code, notes, and snippets.

View yunusemredilber's full-sized avatar
:shipit:
Hanging out at localhost

Yunus Emre Dilber yunusemredilber

:shipit:
Hanging out at localhost
View GitHub Profile
@yunusemredilber
yunusemredilber / react_spring_example.jsx
Created December 19, 2020 15:44
React spring animation example
import { render } from 'react-dom'
import React, { useState } from 'react'
import { useSprings, animated } from 'react-spring'
const items = ['hey', 'yooo']
function ReactSpringExample() {
const [pos, setPos] = useState(0)
const springs = useSprings(items.length, items.map((item, i) => ({
opacity: pos === i ? 1 : 0,
@yunusemredilber
yunusemredilber / ActivityLifecycleListener.java
Created October 5, 2020 14:45
ActivityLifecycleListener
import android.app.Activity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import java.lang.ref.WeakReference;
import java.util.function.Consumer;
public class ActivityLifecycleListener implements LifecycleObserver {
@yunusemredilber
yunusemredilber / rails_polymorphic_association_query.md
Created September 14, 2020 12:33
Rails Polymorphic Association Query

Rails Polymorphic Association Query

Example use case:

class User < ApplicationRecord
  belongs_to :authable, polymorphic: true, optional: true
end
 
class Google < ApplicationRecord
@yunusemredilber
yunusemredilber / MultipleTurbolinksViewActivity.java
Last active July 13, 2020 12:07
Multiple turbolinks view with bottom navigation bar [Android]
/*
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha08'
*/
public class MultipleTurbolinksViewActivity extends BaseActivity {
private ActivityMultipleTurbolinksViewBinding binding;
private String[] paths = new String[]{"/", "/profile"};
@yunusemredilber
yunusemredilber / loading_animation.cr
Created May 24, 2020 20:57
Crystal termial/cli loading animation
require "colorize"
arr_loading = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
i = 0
loop do
print "#{arr_loading[i % arr_loading.size]}\r".colorize(:light_magenta)
i += 1
sleep(0.1)
end
@yunusemredilber
yunusemredilber / local_to_android.md
Last active May 20, 2020 07:53
Connecting to a local rails project from android

Connecting to a local rails project from android

Find your public ip

ifconfig |grep inet

or

@yunusemredilber
yunusemredilber / AndroidManifest.xml
Last active May 20, 2020 07:24
Android Firebase Cloud Messaging Skeleton
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.example">
<!-- ... -->
<application
<!-- ... --> >
<!-- ... -->
@yunusemredilber
yunusemredilber / text_horizontal_scrollable.xml
Created May 12, 2020 12:53
Android horizontal scrollable text
<androidx.appcompat.widget.AppCompatEditText
android:background="@null"
android:inputType="none"
android:textIsSelectable="false"
android:cursorVisible="false"
android:focusable="false"
android:layout_width="200dp"
app:layout_constrainedWidth="true"
android:scrollHorizontally="true"
android:singleLine="true"
@yunusemredilber
yunusemredilber / RxBus.java
Created May 7, 2020 13:29
Asynchronous and event-based data passing in Android with RxJava
public final class RxBus {
// String can be replaced with any kind of Object.
private static final BehaviorSubject<String> behaviorSubject
= BehaviorSubject.create();
public static Disposable subscribe(@NonNull Consumer<String> action) {
return behaviorSubject.subscribe(action);
}
public static void publish(@NonNull String value) {
@yunusemredilber
yunusemredilber / QrActivity.java
Created April 21, 2020 11:43
Android QR Reading
public class QrActivity extends AppCompatActivity implements QRCodeReaderView.OnQRCodeReadListener {
private QRCodeReaderView qrCodeReaderView;
private static final int MY_CAMERA_REQUEST_CODE = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qr);
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {