Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
@Akifcan
Akifcan / arguments
Created April 28, 2022 19:43
arguments example
function y(z){
console.log(arguments.length)
}
var x = {
length: 5,
method: function(y){
console.log(arguments.length)
}
}
@Akifcan
Akifcan / object-flat.js
Created April 23, 2022 21:18
Object flatten Example
const cv = {
age: 20,
name: 'akif',
title: 'web developer',
contact: {
number: '0535-232-22-17'
},
address: {
home: 'bornova',
scholl: {
@Akifcan
Akifcan / docker.compose.yml
Created March 30, 2022 17:25
my docker compose example
version: '3.7'
services:
postgres:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=campusUsername
- POSTGRES_PASSWORD=campusPassword
- POSTGRES_DB=campus_db
class GraphqlResponse {
final bool success;
final data;
GraphqlResponse({required this.success, required this.data});
}
class GraphqlService {
GraphqlService._privateConstructor();
static final GraphqlService _instance = GraphqlService._privateConstructor();
static GraphqlService get instance => _instance;
Uri url = Uri.parse('http://localhost:3000/graphql');
var response = await http.post(
url,
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: jsonEncode({"query": query, "variables": variables}),
);
Map variables = {
'productId': productId,
'content': comment,
'rating': rating,
'images': images
};
String query = '''
mutation CREATE_COMMENT(\$productId: String!, \$content: String!, \$rating: Float!, \$images: [String!]!){
createComment(productId: \$productId, comment: {content: \$content , rating: \$rating, images: \$images }){
content,
rating,
userId
}
}
''';
@Akifcan
Akifcan / indexedb.js
Created July 7, 2021 18:40
create indeddb objectstore
requestfile.onupgradeneeded = function (event) {
var db = event.target.result;
var objectStore = db.createObjectStore("photos", { keyPath: "id", autoIncrement: true });
};
@Akifcan
Akifcan / indexedb.js
Created July 7, 2021 18:39
add to indexedb
document.getElementById('second').addEventListener('submit', e => {
e.preventDefault()
const fileName = document.getElementById('filename').value //text değerimizi aldık
const file = document.getElementById('file').files[0] //dosyamızı File Objemizi aldık
var request = window.indexedDB.open("file", 1); //veritabanımızı açıyoruz
request.onsuccess = function (event) {
var db = event.target.result; //veritabanımız başarılı bir şekilde açıldı
var objectStore = db.transaction('photos', 'readwrite').objectStore('photos') //Tablomuzu seçtik. Yukarıda bahsettiğim gibi transaction fonksiyonunu indexedb de sürekli kullanıyoruz. Transaction işlemini yapacağımız objectStore ve daha sonra ekleme yapacağımız objectStoreyi seçiyoruz.
objectStore.put({ fileName, file }).onsuccess = function () {
console.log('ok!');//verilerimizi kayıt ettiğimizde çalışacak fonksiyonumuz aynı şekilde onerror eventini yakalayabilirsiniz.