Skip to content

Instantly share code, notes, and snippets.

View yusufcakal's full-sized avatar
:octocat:
Leave your code better than you found it

Yusuf Çakal yusufcakal

:octocat:
Leave your code better than you found it
View GitHub Profile
public class ComputerFactory {
public static Computer createComputer(Class aClass) throws IllegalAccessException, InstantiationException {
if (aClass.getName().equals(aClass.getName())){
return (Computer) aClass.newInstance();
}
return null;
}
}
@yusufcakal
yusufcakal / Main.java
Created October 28, 2017 23:34
Medium Post
public class Main {
public static void main(String[] args) {
try {
Asus asus = (Asus) ComputerFactory.createComputer(Asus.class);
asus.since(1234);
asus.name();
Mac mac = (Mac) ComputerFactory.createComputer(Mac.class);
public class ComputerFactory {
public static Computer createComputer(Class aClass) throws IllegalAccessException, InstantiationException {
return (Computer) aClass.newInstance();
}
}
@yusufcakal
yusufcakal / main.java
Created November 9, 2017 11:49
Selection Sort
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(8);
list.add(5);
dependencies {
compile 'com.google.firebase:firebase-messaging:11.8.0'
}
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
package yusufcakal.com.cloudmessagging;
/**
* Created by Yusuf on 19.12.2017.
*/
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {