14 Mart 2022 Pazartesi

GPLv2 - General Public License (Genel Kamu Lisansı)

Giriş
yazılarına bakabilirsiniz

GPLv2 de eski. Eski olduğu şu sorudan anlaşılabilir
Q: Why does GPLv2 include a mailing address (51 Franklin Street) in the license notice?
A : It may help to remember that version 2 of the GNU GPL was published in June 1991. According to Wikipedia, only 11% of people in the developed world had internet access in 1997, and I can assure you that in 1991 it was very much fewer than that. Most university research users had it, though often not undergraduates; outside academia, it was really quite unusual to find access either from work or from home.
Normalde GPLv2 lisansını GPLv3 yapmak mümkün değil. Açıklaması şöyle.
Please note that GPLv2 is, by itself, not compatible with GPLv3. However, most software released under GPLv2 allows you to use the terms of later versions of the GPL as well. When this is the case, you can use the code under GPLv3 to make the desired combination.
EğerGPLv2 lisansındaki cümle şöyle ise kodu GPLv3 yaparak tekrar yayınlamak mümkün. Açıklaması şöyle.
If the GPLv2 code says "or any later version" then you may distribute your modified work entirely under the GPLv3. Otherwise, you must stick with the GPLv2.
Örneğin Linux kernel kodu bu cümleyi içermediği için GPLv3 olamıyor. Açıklaması şöyle.
Linus specified GPL2 ONLY (without the "or later" clause) for his creation - so that others who contributed to it have to use that as well - which has caused some intense discussions over the years I believe! 

11 Mart 2022 Cuma

Google Cloud - gcloud komutu

gcloud komutu
Yardım ve açıklamalar burada

auth seçeneği
gcloud auth seçeneği yazısına taşıdım

compute firewall-rules
Örnek
Açıklaması şöyle
Whenever you create a new project in Google Cloud, you get the default virtual private cloud (VPC). The virtual machines (VMs) that will host my application instances will run within that VPC.

I created a firewall rule to allow SSH, HTTP, and HTTPS traffic:

The rule will apply to all the VMs labeled geo-messenger-instance. 
Şöyle yaparız
gcloud compute --project=geo-distributed-messenger \
  firewall-rules create geo-messenger-allowed-traffic \
  --direction=INGRESS --priority=1000 --network=default \
  --action=ALLOW --rules=tcp:22,tcp:80,tcp:443 \
  --source-ranges=0.0.0.0/0 --target-tags=geo-messenger-instance
compute instances
create, delete, describe, list, start, stop seçenekleri kullanılabilir
create
Örnek
Şöyle yaparız
gcloud compute instances create test1 --zone= us-east1-c
Örnek
Elimizde start_single_app_instance.sh kodu olsun
#! /bin/bash

while getopts n:z:a:c:u:p: flag
do
    case "${flag}" in
        n) name=${OPTARG};;
        z) zone=${OPTARG};;
        a) port=${OPTARG};;
        c) url=${OPTARG};;
        u) user=${OPTARG};;
        p) pwd=${OPTARG};;
    esac
done

echo "Starting instance $name in zone $zone..."

gcloud compute instances create $name \
        --project=geo-distributed-messenger \
        --machine-type=e2-small \
        --boot-disk-type=pd-balanced --boot-disk-size=10GB \
        --network=default --zone=$zone \
        --image-family=ubuntu-1804-lts --image-project=ubuntu-os-cloud \
        --tags=geo-messenger-instance, \
        --metadata-from-file=startup-script=startup_script.sh, \
        --metadata=PORT=$port,DB_URL=$url,DB_USER=$user,DB_PWD=$pwd

if [ $? -eq 0 ]; then
    echo "Instance $name has been created!"
    echo "The will be started on port $port and connect to the database $url"
    echo "Use command below to check the progress: "
    echo "  "
    echo "  gcloud compute ssh $name --project=geo-distributed-messenger"
    echo "  sudo journalctl -u google-startup-scripts.service -f"
else
    echo FAIL
Söz dizimi şöyle
./start_single_app_instance.sh \
    -n {INSTANCE_NAME} \
    -z {CLOUD_ZONE_NAME} \
    -a {APP_HTTP_PORT_NUMBER} \
    -c "{DATABASE_CONNECTION_ENDPOINT}" \
    -u {DATABASE_USER} \
    -p {DATABASE_PWD}
west için şöyle yaparız
./start_single_app_instance.sh \
    -n messenger-us-west-instance \
    -z us-west2-a \
    -a 80 \
    -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \
    -u my-user-name \
    -p my-super-complex-password
east için şöyle yaparız
./start_single_app_instance.sh \
    -n messenger-us-east-instance \
    -z us-east4-a \
    -a 80 \
    -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \
    -u my-user-name \
    -p my-super-complex-password
central için şöyle yaparız
./start_single_app_instance.sh \
    -n messenger-us-central-instance \
    -z us-central1-a \
    -a 80 \
    -c "jdbc:postgresql://us-east1.my-instance-id.gcp.ybdb.io:5433/yugabyte?ssl=true&sslmode=require" \
    -u my-user-name \
    -p my-super-complex-password
config set
Örnek
Şöyle yaparız
gcloud config set compute/region europe-west
gcloud config set compute/zone europe-west1-c

delete
Şöyle yaparız
gcloud compute instances delete test1
describe
Şöyle yaparız
$ gcloud compute instances describe rlwy-04-kkbrp-worker-a-bs5xt --zone us-central1-a
cpuPlatform: Intel Haswell
creationTimestamp: '2022-08-24T23:20:41.092-07:00'
deletionProtection: false
disks:
- autoDelete: true
  boot: true
  deviceName: persistent-disk-0
  diskSizeGb: '300'
  guestOsFeatures:
  - type: VIRTIO_SCSI_MULTIQUEUE
  - type: UEFI_COMPATIBLE
  index: 0
  interface: SCSI
  kind: compute#attachedDisk
  licenses:
  - https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx
  mode: READ_WRITE
  source: https://www.googleapis.com/compute/v1/projects/...
  type: PERSISTENT
- autoDelete: true
  boot: false
  deviceName: persistent-disk-1
  diskSizeGb: '200'
  index: 1
  interface: SCSI
  kind: compute#attachedDisk
  mode: READ_WRITE
  source: https://www.googleapis.com/compute/v1/projects/...
  type: PERSISTENT
...
list
Şöyle yaparız
gcloud compute instances list
stop
Instance'ları durdurmak için şöyle yaparız. Proje ismi atanıyor. Daha sonra compute/zone atanıyor. İsme göre filtreleniyor ve bunlar üzerinde dolaşılarak durduruluyorlar
gcloud config set project product-oce-private && \
gcloud config set compute/zone us-central1-a && \
gcloud compute instances list --filter="name~'rlwy-04-*'" | \
grep -v NAME | \
cut -d ' ' -f1 | \ 
while read line ; do  \
  echo $line ; gcloud compute instances stop $line; \
done
Instance'ları başlatmak için şöyle yaparız
gcloud config set project product-oce-private && \
gcloud config set compute/zone us-central1-a && \
gcloud compute instances list --filter="name~'rlwy-04-*'" | \
grep -v NAME | \
cut -d ' ' -f1 | \ 
while read line ; do \
echo $line ; gcloud compute instances start $line; \
done 
Çıktısı şöyle
Updated property [core/project].
Updated property [compute/zone].
foo-04-7hdxf-master-0
Starting instance(s) foo-04-7hdxf-master-0...
..........................................................done.
Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/
zones/us-central1-a/instances/foo-04-7hdxf-master-0].
Instance internal IP is 172.18.16.173
foo-04-7hdxf-master-1
Starting instance(s) foo-04-7hdxf-master-1...
..................................done.
Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/
zones/us-central1-a/instances/foo-04-7hdxf-master-1].
Instance internal IP is 172.18.16.163
foo-04-7hdxf-master-2
Starting instance(s) foo-04-7hdxf-master-2...
...................................done.
Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/
zones/us-central1-a/instances/foo-04-7hdxf-master-2].
Instance internal IP is 172.18.16.204
foo-04-7hdxf-worker-a-277vt
Starting instance(s) foo-04-7hdxf-worker-a-277vt...
...........................................done.
Updated [https://compute.googleapis.com/compute/v1/projects/product-foo-private/
zones/us-central1-a/instances/foo-04-7hdxf-worker-a-277vt].
Instance internal IP is 172.18.16.226
foo-04-7hdxf-worker-a-2xzmg
Starting instance(s) foo-04-7hdxf-worker-a-2xzmg...
............................done.
...
app
Örnek
Şöyle yaparız
#bölge seçilir
gcloud app create

#editor açar
cloudshell workspace appengine-try-java
#editor içinde
mvn appengine:run

gcloud config set project myproject
mvn appengine:deploy
container clusters create

container fleet
container fleet yazısına taşıdım

container clusters get-credentials
Açıklaması şöyle. Böylece artık kubectl komutları ile cluster'a erişiriz
gcloud container clusters get-credentials updates a kubeconfig file with appropriate credentials and endpoint information to point kubectl at a specific cluster in Google Kubernetes Engine.
Söz dizimi şöyle. zone ismi olarak europe-west2, europe-west4 kullanılabilir
gcloud container clusters get-credentials <<your_kubernetes_cluster_name>> \
    --zone=<<your_zone_name>> \
    --project=<<your_gcp_project_id>>
Örnek
cluster'a login olmak için şöyle yaparız
gcloud auth activate-service-account --key-file=product.json

gcloud container clusters get-credentials ${CLUSTER_NAME} --zone us-central1-a 
  --project ${PROJECT_ID}
Örnek
cluster'a login olmak için şöyle yaparız
# Get the credentials
gcloud container clusters get-credentials east-cluster 
  --zone=us-east4-b
gcloud container clusters get-credentials europe-cluster 
  --zone=europe-west1-c
gcloud container clusters get-credentials asia-cluster 
  --zone=asia-south1-b
container/images
Örnek
Şöyle yaparız
gcloud container images list-tags gcr.io/PROJECT/myimage
Örnek
Belli bir tag'i aramak için şöyle yaparız
gcloud container images list-tags 
  --project product-spanner 
  --filter=tags:85.1.91-alpha16 
  --format=json gcr.io/product-spanner/oce/rlwy
Silmek için şöyle yaparız
gcloud container images delete gcr.io/product-spanner/oce/rlwy:85.1.91-alpha28
Örnek
Tüm tag'leri görmek için şöyle yaparız.
$ gcloud container images list-tags --project product-spanner gcr.io/product-spanner/oce/rlwy
DIGEST        TAGS             TIMESTAMP
f3b20a3c3cf8  85.1.91-alpha28  2022-08-12T07:55:36
aaa2ad58d288  85.1.91-alpha27  2022-07-30T15:27:52
67bb81211a3d  85.1.91-alpha26  2022-07-30T06:48:39
Şöyle yaparız.  Burada aslında image üzerinde iki tane tag var.
$ gcloud container images list-tags --project product-spanner gcr.io/product-spanner/oce/oce-rlwy-gui
DIGEST        TAGS             TIMESTAMP
11c28c119b15  9d9c3ac,v0.0.26  2022-08-17T12:33:14
9c6502979fd6                   2022-08-12T07:26:56
Json olarak görmek için şöyle yaparız
$ gcloud container images list-tags --project product-spanner --format json gcr.io/product-spanner/oce/oce-rlwy-gui | more
[
  {
    "digest": "sha256:11c28c119b159ab25a8faa4a63566f7d143e76e69b1a5218aac0a51dd8d40772",
    "tags": [
      "9d9c3ac",
      "v0.0.26"
    ],
    "timestamp": {
      "datetime": "2022-08-17 12:33:14+00:00",
      "day": 17,
      "fold": 0,
      "hour": 12,
      "microsecond": 0,
      "minute": 33,
      "month": 8,
      "second": 14,
      "year": 2022
    }
  },

config set project
Örnek
Şöyle yaparız
$ gcloud auth login
$ gcloud config set project <YOUR_GCP_PROJECT_HERE>
$ gcloud auth application-default login
Örnek
Şöyle yaparız
#Storage bucket in GCS
# Select GCP project
$  gcloud config set project [project-name]

# Create a GCS bucket
$  gsutil mb -l us-central1 -b on gs://my-vitess-operator-backup-bucket
Creating gs://my-vitess-operator-backup-bucket/...

# Create a GCP service account
$ gcloud iam service-accounts create my-backup-service-account
Created service account [my-backup-service-account].

# Grant the service account access to the bucket gsutil iam ch
$ gsutil iam ch serviceAccount:my-backup-service-account@planetscale-dev.iam.gserviceaccount.com:objectViewer,objectCreator,objectAdmin \
gs://my-vitess-operator-backup-bucket

# Create and download a key for the service account
$ gcloud iam service-accounts keys create ~/gcs_key.json --iam-account my-backup-service-account@planetscale-dev.iam.gserviceaccount.com
created key [ccd65b5a198298f9ca07ee6ab901a2492ea142c7] of type [json] as [/Users/askdba/gcs_key.json] 
for [my-backup-service-account@planetscale-dev.iam.gserviceaccount.com]

# Upload the service account key as a k8s Secret
$ kubectl create secret generic gcs-auth --from-file=gcs_key.json="$HOME/gcs_key.json"
secret/gcs-auth created

# Delete the local copy
$ rm ~/gcs_key.json
projects
gcloud projects seçeneği yazısına taşıdım

services
services yazısına taşıdım

8 Mart 2022 Salı

git clone seçeneği - Belirtilen URL'yi Getirir

Giriş
Uzak depodaki projeyi yerel depoya kopyalamak için  kullanılır. Remote Repository iki branch'ten oluşuyor olabilir. Master ve develop.

Not : svn'den gelenler için bu komut kafa karıştırıcı çünkü svn'deki checkout komutuna denk geliyor.

Örnek
Şöyle yaparız
git clone https://github/com/something
Örnek
Bulunduğumuz dizine clone yapmak istersek şöyle yaparız.
git clone git@github.com:whatever .
Belli bir dizine clone yapmak istersek şöyle yaparız.
git clone git@github.com:whatever folder-name
--depth seçeneği
Açıklaması şöyle
Bu yöntem "shallow clone" diye geçer. Git clone, tüm proje geçişimini indirir ve büyük bir projede bu işlem uzun sürer. Fakat depth parametresi ile sadece en güncel versionu indirerek süreci hızlandırabilirsiniz.
Örnek
Sadece belli bir derinlikteki dosyaları indirmek için şöyle yaparız.
git clone https://github.com/user/repository --depth 1 --branch=master ~/dir-name
--recursive seçeneği
Örnek

Şöyle yaparız.
git clone --recursive -c core.longpaths=true -j 20 https://a.b.c .

Personal Access Token
Örnek
Önce şöyle yaparız. Git bize şifre ile giriş yapamayacağımızı belirtir. Personal Access Token (PAT) kullanmak gerekir.
git config --global user.name "..."
git config --global user.email "..."

git clone https://github.com/foo.git
PAT yarattıktan sonra şöyle yaparız. Bu PAT nesnenin etkinleştirilmediği anlamına gelir. Hata mesajındaki adrese tarayıcı ile gider ve etkinleştiririz.
git clone https://github.com/foo.git
Cloning into '...'...
Username for 'https://github.com': ...
Password for 'https://...':

The `Foo' organization has enabled or enforced SAML SSO. To access
this repository, visit https://github.com/orgs/...
and try your request again.
unable to access 'https://foo.git/': The requested URL returned error: 403
Daha sonra normal git clone işleminde şifre alanına PAT gireriz. Eğer  kullanıcı ismi ve PAT'i bir daha girmek istemiyorsak şöyle yaparız
git config --global credential.helper store
Daha sonra son bir defa "git pull" yaparız. Tekrar kullanıcı ismi ve şifre istenir. Yine kullanıcı ve PAT'i gireriz ve bir daha artık sormaz

18 Şubat 2022 Cuma

Renk Uzayı - CMYK - Baskı İşlerinde Kullanılır

Giriş
CMYK renk uzayı aslında çok eskiden beri biliniyor. Açıklaması şöyle.
In 1906, the Eagle Printing Ink Company incorporated the four-colour wet process inks for the first time. These four colours were cyan, magenta, yellow, and black (also known as key), hence the name CMYK. It was discovered that these four colours can be combined to produce an almost unlimited number of richer, darker tones.
CMYK baskı işlerinde kullanılır. Günümüz teknolojisiyle bile ekranda görülen tüm renkleri baskıda görmek mümkün değildir. RGB ve CMYK arasındaki çevrimden dolayı oluşabilecek renk kayıplarından kaçınmak için CMYK ile çalışmak gerekir.

Beyaz Renk
Açıklaması şöyle. Beyaz rengi basmaya gerek yok.
Everything that is white in a CMYK image is non-printing, because white ink is not used in that printing process.
Soru şöyle. Bu soruda CMYK subtractive model, RGB ise additive model olarak anılıyor
Why is CMYK more efficient/beneficial than RGB for performing printing on paper?
Bence en anlamlı açıklama şöyle. Yani ekranda farklı renkleri elde etmek için farklı renkleri eklemek gerekiyor. Her şeyi eklersek beyaz elde ederiz. Kağıtta ise beyazdan başlıyoruz. Bir rengi elde etmek için diğer renkleri çıkarmak gerekiyor.
CMY vs. RGB is basically a question of how printing on paper works compared to how (for example) a monitor works.

Something like a monitor uses an additive model. You start with three tiny light sources next to each other, each emitting some amount of a component color. These are then basically added together to produce a result of a single apparent color.

When you're looking at something on paper, however, you start with the ambient light falling on the paper. Thanks to how our eyes adjust to ambient light, we usually see this is pretty much "white" regardless of its color1.

The ink we deposit on the paper then subtracts the colors we don't want. To see something as a particular color, we filter out the appropriate amounts to get from white to that color. To get Red, we have to filter out Green and Blue. To get Blue, we filter out Green and Red. And to get red, we have to filter out green and blue.


Git Örneklerim

Giriş
Git'i komut satırından kullanması bence oldukça zor. Bazı kullanımlarını not almak istedim
git push yazılarına bakabilirsiniz

Örnek - Push To Remote Repository
GitHub üzerinden yeni bir repository yarattım. Yeni repository'de main isimli bir branch yaratıldı.
Sonra şöyle yaptım
> git remote set-url origin https://github.com/hazelcast/hazelcast-cloud-postgre-sample
> git push origin master 
Sonra yeni repostory'de iki tane branch olduğunu fark ettim. Bunlar main ve master. Aslında ben yerel repository'imi main ismiyle gönderecektim yani şöyle yapacaktım ama dikkat etmemişim
> git push origin master:main
main branch'i sileyim dedim. Şöyle yaptım ama hata verdi
> git push origin --delete main
To https://github.com/hazelcast/hazelcast-cloud-postgre-sample
 ! [remote rejected] main (refusing to delete the current branch: refs/heads/main)
error: failed to push some refs to 'https://github.com/hazelcast/hazelcast-cloud-postgre-sample'
Çünkü main branch default branch olduğu için GitHub silmeye izin vermiyor. Önce default branch'i master yapmak gerekti. Settings sayfasından default branch'i değiştirdim. Sonra şöyle yaptım. main branch silindi
> git push origin --delete main
To https://github.com/hazelcast/hazelcast-cloud-postgre-sample
 - [deleted]         main

Örnek - Feature Brach İle Çalışma
Feature branch yarat, push'la ve feature branch'i sil
#Feature için yeni branch yarat
git checkout -b feature/rw-2028 rw_22.1 #Değişiklikleri commitle git commit -a -m "rw-2028 : ..." #Değişiklikleri pushla git push #Development branch'e geç git checkout rw_22.1 #Feature branch'i sil git branch -D feature/RLWY-2028
Örnek - Commitlenmiş Dosyayı Geri Alma
Dosyayı 2 defa commitledim ama daha push etmedim. Geri almak için şöyle yaparız
git checkout 6d4b20f81f4d17bd2a93bbcbd4eab39457e600e7 Foo.java
Örnek
Commit'lenmemiş dosya isimlerini gör
git diff --name-only
Eğer her şeyi geri sarmak istersek şöyle yaparız. Undo seçenekleri burada
git reset --hard
Örnek - Rename Remote Branch
Şöyle yaparız
git checkout railway_22.1

# change a branch name
git branch -m release/22.1.0

# delete the branch with the old name on the remote repository
git push origin --delete railway_22.1

# push the branch with the correct name
git push origin -u release/22.1.0
Örnek - tag
Yerelde tag yaratıp bir şeyi denedikten sonra silmek için şöyle yaparız
# Create new tag at local
git tag release-22.0.1
...
# Delete tag
git tag -d release-22.0.1
Örnek - tag
Yerelde tag yaratıp pushlamak için şöyle yaparız
# Delete local and push
git tag release-22.0.1
git push --tags
Örnek - yeni tag
Tag silip pushlamak için şöyle yaparız
# Delete local and push
git tag -d release-22.1.0
git push --tags
Örnek - tag move
Şöyle yaparız
# delete from remote
git push origin :refs/tags/release-22.1.0

# delete from local
git tag -d release-22.1.0

# recreate at local
git tag release-22.1.0

# push to remote
git push --tags



3 Şubat 2022 Perşembe

GraphQL Subscriptions

Giriş
Açıklaması şöyle
Subscription enables the client to fetch real-time updates from the server. You can think of subscriptions as analogous to continuous polling mechanisms. It makes it possible for the server to stream data to all the clients that are listening or 'subscribed' to it. Just like queries, subscriptions allow you to read data. Unlike queries, subscriptions maintain an active connection to your GraphQL server, most commonly via WebSocket. This enables your server to push updates to the client over time. Executing a subscription creates a persistent function on the server that maps an underlying Source Stream to a returned Response Stream. You can define available subscriptions in your GraphQL schema as fields of the Subscription type.
Örnek
Şöyle yaparız
subscription {
  newAuthor {
    name
    country
  }
}
Eğer yeni bir yazar yaratılırsa sunucu bize şunu gönderir.
{
  "newAuthor": {
    "name": "Robert Jordan",
    "country": "USA"
  }
}


10 Ocak 2022 Pazartesi

Apache Thrift - Protobuf Muadili

Giriş
Facebook tarafından yaratıldı.
Maven
Şu satırı dahil ederiz
<dependency>
  <groupId>org.apache.thrift</groupId>
  <artifactId>libthrift</artifactId>
  <version>0.15.0</version>
</dependency>

Apache Thrift ve Protocol Buffers
Designing Data Intensive Applications kitabından bazı cümleler şöyle. 
Apache Thrift and Protocol Buffers (protobuf) are binary encoding libraries that are based on the same principle. Protocol Buffers was originally developed at Google, Thrift was originally developed at Facebook, and both were made open source in 2007–08.
Both Thrift and Protocol Buffers require a schema for any data that is encoded.

Thrift and Protocol Buffers each come with a code generation tool that takes a schema definition like the ones shown here, and produces classes that implement the schema in various programming languages. Your application code can call this generated code to encode or decode records of the schema.

Tipler
Açıklaması şöyle
Base types for Thrift are :
- bool value boolean value, true or false
- byte value signed byte
- i16 value 16-bit signed integer
- i32 value 32-bit signed integer
- i64 value 64-bit signed integer
- double value 64-bit floating-point number
- string text/binary string

The other types are Structs, Containers, Exceptions, Services
thrift komutu
-r seçeneği
Örnek
Şöyle yaparız
thrift-0.15.0 -r — gen java studentservice.thrift