Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Tuğrul Bayrak tgrlbyrk

🎯
Focusing
View GitHub Profile
@tgrlbyrk
tgrlbyrk / Person.java
Created Jul 6, 2019
class with builder pattern
View Person.java
public class Person {
private String name, surname, address;
public Person(Builder builder) {
this.name = builder.name;
this.surname = builder.surname;
this.address = builder.address;
}
@tgrlbyrk
tgrlbyrk / Person.java
Created Jul 6, 2019
class without builder pattern
View Person.java
public class Person {
private String name, surname, address;
public Person(String name, String surname, String address) {
this.name = name;
this.surname = surname;
this.address = address;
}
// Getter & setter metodları
View binary_search.java
class BinarySearch {
int binarySearch(int arr[], int x) {
int l = 0, r = arr.length - 1;
while (l <= r) {
int m = l + (r - l) / 2;
//x değeri ortanca değer mi kontrol et
if (arr[m] == x)
return m;
View linear_search.java
class LinearSearch {
public static int search(int arr[], int x) {
int n = arr.length;
for(int i = 0; i < n; i++) {
if(arr[i] == x)
return i;
}
return -1;
}
View singletonPattern.java
public class SingleObject {
//SingleObject sınıfından bir nesne oluştur
private static SingleObject instance = new SingleObject();
/*constructorın access modifierını private olarak tanımlayalım ki bu sınıftan nesne oluşturulamasın*/
private SingleObject(){}
//Oluşturduğumuz nesneye erişim için getter
public static SingleObject getInstance(){
View prototypePattern.java
import java.util.Hashtable;
public abstract class Shape implements Cloneable {
private String id;
protected String type;
abstract void draw();
public String getType(){
return type;
View checkauth.js
const jwt = require('jsonwebtoken');
module.exports = (req, res, next) => {
try {
/*JWT is send with request header!
Format of it: Authorization : Bearer <token>
*/
const token = req.headers.authorization.split(" ")[1];
const decodedToken = jwt.verify(token, 'secret_key');
req.userData = decodedToken;
@tgrlbyrk
tgrlbyrk / auth.js
Created Apr 17, 2019
express login auth jwt
View auth.js
login(req, res) {
if (!req.body.memail || !req.body.mpassword) {
return res.status(404).send({
message: 'Email and password can not be empty!',
});
} else {
const email = req.body.memail;
const password = crypto.createHash('md5').update(req.body.mpassword).digest("hex");
const potentialUser = {
where: {
@tgrlbyrk
tgrlbyrk / App.java
Last active Sep 23, 2018
Hibernate #2 - Medium (Saving object to DB example)
View App.java
package com.hibernateyazilari.hibernate_2;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.internal.SessionFactoryServiceRegistryBuilderImpl;
public class App {
public static void main( String[] args ) {
SessionFactory factory = new Configuration()
View Student.java
package com.hibernateyazilari.hibernate_2;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "Students")
public class Student {