3 Kasım 2017 Cuma

ng is not recognized as an internal or external command

angular-cli is older version, for new version first
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli

to install new version
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest

17 Ekim 2017 Salı

Git basic command.

add files to stage

git add -A stages all;

git add . stages new and modified, without deleted;

git add -u stages modified and deleted, without new.

 

git commit code

git commit -m "message"

git push code

git push

git push master

git push origin dev:master

git swicth branch

git checkout dev

git get last changed from any branch

git pull

 

16 Ekim 2017 Pazartesi

Mongo DB run as window services

mongod --dbpath "C:\MongoDB\data" --logpath "C:\MongoDB\log\mongolog.txt" --install--serviceName "MongoDB"

27 Eylül 2017 Çarşamba

Web Api ActionFilterAttribute

public class Auth : ActionFilterAttribute
{
public string token { get; set; }
public override void OnActionExecuting(HttpActionContext actionContext)
{
base.OnActionExecuting(actionContext);

var id = actionContext.ActionArguments["token"] as string;
if (id != "1")
{
actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
}

}
}




[Auth]
public IEnumerable<string> Get(string token)
{
return new string[] { "value1", "value2" };
}

16 Ağustos 2017 Çarşamba

ORACLE LISTAGG

USERS TABLE















IDNAME
1BURAK
2ARIF

 

 

DEPARMENTS TABLE























IDDEPARMENT_NAMERF_
USER_ID
1DELIVERY1
2FINANCE2
3IT1

 

SELECT
U.NAME,
LISTAGG (D.DEPARMENT_NAME,',') WITHIN GROUP (ORDER BY U.NAME) AS DEPARTMENTS
FROM
USERS U
INNER JOIN DEPARMENTS D ON U.ID = D.RF_USER_ID group by u.name

 

 

RESULT TABLE















NAMEDEPARTMENTS
BURAKDELIVERY,IT
ARIFFINANCE

13 Ağustos 2017 Pazar

how to use array in oracle

if you wanna its not null array you must be write "not null"


DECLARE
TYPE myArrayType IS TABLE OF VARCHAR(50) NOT NULL INDEX BY BINARY_INTEGER;


v_array myArrayType;


BEGIN
v_array(0):='OLGUN';


v_array(1):='ARİF';


v_array(2):='BURAK';


FOR I IN 0 .. 2 LOOP
dbms_output.put_line(v_array(i));
END LOOP;
END;

express static in node js

in app.js

app.use(express.static('public'));

app.use (express.static('src/views'));

  • /

  • app.js

  • public

    • css

      • bootsrap.min.css

      • styles.css



    • js

      • style.js





  • src

    • views

      • index.html





global temp table in oracle

CREATE GLOBAL TEMPORARY TABLE globaltemp_1
(
NAME VARCHAR2(50)
)
ON COMMIT PRESERVE ROWS; -- session

CREATE GLOBAL TEMPORARY TABLE globaltemp_2
(
NAME VARCHAR2(50)
)
ON COMMIT DELETE ROWS; -- commit,truncate,alter,drop

BEGIN
INSERT INTO USERS VALUES(2,'BURAK');
INSERT INTO globaltemp_1 VALUES ('A');
INSERT INTO globaltemp_2 VALUES ('A');
END;

check constraint in oracle

ALTER TABLE USERS ADD
CONSTRAINT USERS_C01
CHECK (NAME IN('BURAK'))
ENABLE
VALIDATE;

Using a Deferred Constraint in Oracle

ALTER TABLE DEPARMENTS
ADD CONSTRAINT fk1
FOREIGN KEY (RF_USER_ID)
REFERENCES USERS (ID) DEFERRABLE;


set constraint FK1 deferred;

update users
set ID = 5
where ID = 2;

update deparments
set RF_USER_ID = 5
where ID = 1;

commit;

OR

 

SET CONSTRAINT FK1 IMMEDIATE;

linq practies one

var value = "2:00,2:00";
var x = value.Split(',').Select(t => "0:" + t).Select(t=> TimeSpan.Parse(t)).Select(t=>t.TotalSeconds).Sum();
Console.WriteLine(TimeSpan.FromSeconds(x));
Console.ReadLine();

 

result : 00:04:00

12 Ağustos 2017 Cumartesi

Entitiy Framework Where If Extension Method.

public static class Extension
{
public static IQueryable<TSource> WhereIf<TSource>(this IQueryable<TSource> source, bool condition, Expression<Func<TSource, bool>> predicate)
{
return condition ? source.Where(predicate) : source;
}
}

var query = db.USERS.WhereIf(txtName.Text.IsNotNull(), x => x.Name==txtName.Text).WhereIf(txtSurName.Text.IsNotNull(), x => x.SurName==txtSurName.Text);

 

 

How to connect oracle 12 c with entitiy framework v.5.0 - visual studio 2017

1) install oracle 12 c 12.1.0.2.0(http://www.oracle.com/technetwork/database/enterprise edition/downloads/database12c-win64-download-2297732.html)

2) if you have dr0ulib.sql.sbs error when install oracle 12 c

  •  Abort the current installer

  • Open the winx64_12c_database_2of2 directory and navigate to ..\winx64_12c_database_2of2\database\stage\Components directory copy all the files

  • Paste all files to the following location..\winx64_12c_database_1of2\database\stage\Components


 

  • Now run the setup.exe “Run as administrator” and follow the instructions to complete the installation without error.


3) install ( 64-bit ODAC 12c Release 1 (12.1.0.1.0) for Windows x64) http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html - VS 2017

http://www.oracle.com/technetwork/topics/dotnet/downloads/odacmsidownload-2745497.html - VS2015

4)Open visual studio

5)İnstall Entitiy Framework 5.0 on nuget

6)Project Right Click > Add > New Item > Data > ADO.NET Enitity Data Model>  > EF Desiger From database > New Connection > You must fill the area (Username,Password) you check connect as sysdba role and then select the connection type (im using ez connect ) database host name 127.0.0.1, port number 1521 , database service name orcl  (you have to grant sysdba database user GRANT SYSDBA to BURAK;)

7) if you have error 'Unable to find the requested .Net Framework Data Provider. It may not be installed'

8) İnstall Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntitiyFramework on nuget.

 

 

no privileges on tablespace 'USERS' ORA-06512

GRANT UNLIMITED TABLESPACE TO BURAK;

how to create new user / schema oracle 12 c

ALTER SESSION SET "_ORACLE_SCRIPT"=TRUE;
CREATE USER BURAK
IDENTIFIED BY "1";
GRANT SYSDBA to BURAK;

14 Temmuz 2017 Cuma

How to execute sh script from a desktop shortcut?


  1. /usr/share/applications/ depending upon your system) if you want the launcher shortcut to be available to all users.
    sudo -i gedit /usr/share/applications/name.desktop


  2. Paste below text
    [Desktop Entry]
    Type=Application
    Terminal=true
    Name=unmount-mount
    Icon=/path/to/icon/icon.svg
    Exec=/path/to/file/mount-unmount.sh

    edit Icon= and Exec= and Name=

    Also Terminal=True/false determines whether the terminal opens a window and displays output or runs in the background

  3. put this in unity panel by dragging it from files manager


logic is very simple that unity panel allows *.desktop files as launcher though I haven't tried it because I use Natty.

20 Mayıs 2017 Cumartesi

how to get data in iframe on cross domain

SEND.HTML

<html>
<head>

window.onload = function () {
var btn = document.getElementById('send').addEventListener("click", function () {
top.postMessage('hello', '*');
});
}

</head>
<body>
<button id="send">GÖNDER</button>
</body>
</html>

RECEIVER.HTML
<html>
<head>
</head>
<body>
<i frame src="http://localhost:2893/IFrame/Index"></i frame>

window.addEventListener( "message",
function (e) {
//e.origin ---current domain
alert(e.data);

false);

</body>
</html>

3 Mayıs 2017 Çarşamba

Mongodb Replica Set

Merhaba arkadaşlar,

Bugün sizlere mongodb de replica set nedir,ve nasıl yapılır onu göstereceğim.

Öncelikle replica set;cluster olarak bulunan database sunucularının senkronize şekilde çalışmasıdır. İlk önce database sunucuları arasında 1 tane Primary(Master) sunucu belirtilir diğer sunucular ise secondary(Slave)'dir ve ayrıca bir tane Arbiter sunucu vardır. Arbiter üye hiçbir şekilde veri işlemi yapmaz sadece Primary üye seçimi yapılırken seçmen sayısının tek sayının katı olması için vardır. Yani sadece seçim işleminde rol oynar. Replica Set üye sayısı tek sayı olmalıdır.  Primary sunucu bir şekilde down olursa diğer secondary sunucular kendi aralarında seçim yaparak bir tanesini Primary sunucu belirler. Genelde okuma işlemleri primary sunucudan yapılır ama bu isteğe göre değiştirilip secondary üyelerden de okuma işlemi yapılabilir. Primary sunucuya gelen yazma işlemlerini, primary sunucu oplog'a yazarak secondary sunucularda buradan veriyi okuyarak kendi databaselerine yazar. Doğrudan secondary databaselere veri yazamazsınız. Primary database durduğunda diğer database sunucularından bir tanesi otomatik olarak devreye girerek sistem kaldığı yerden aynı şekilde çalışmaya devam eder. Gel gelelim biz bu işlemi mongodb de ve kendi bilgisayarımızda nasıl gerçekleştireceğiz.

Öncelikle şu bağlantıya girerek mongodb nasıl kurulur öğreniyoruz ;

https://gumusburak.wordpress.com/2014/10/12/windows-uzerinde-mongodb-kurulumu/

DİKKAT ! Yalnız kurulumda birinci resimden sonrasını yapmayalım Replica Set için şuanlık. Daha sonradan MongoDB'yi auto start haline getiririz.

İlk önce komut satırımızı açıyoruz.
C:\MongoDB>bin\mongod --dbpath data\data1 --port 27021 --replSet mySet

şeklinde konsol ekranına kodumuzu yazıyoruz ve enter'a basıyoruz en altta bir problem çıkmadıysa "waiting for connection on port 27017" şeklinde bilgi mesajı yazar. Yalnız buradaki yollara dikkat edelim ben kendi bilgisayarımdaki yolları verdim.

Daha sonra yeni bir konsol ekranı açıyoruz ve ya varsa RoboMongo,Mongovue toolunu kullanabilirsiniz MongoDB için.Yalnız bir önceki konsolu kapatmayın açık dursun kapatırsanız DB'ye erişim sağlayamazsınız.

Yeni konsol ekranına aşağıdaki kodu yazarak oluşturmuş oldugumuz DB'ye bağlanıyoruz.
C:\MongoDB>bin\mongo --port 27021

şeklinde bağlanıyoruz.

Bu sunucu bizim Primary sunucumuz olacağı için bu sunucumuzu primary olarak belirtmemiz gerekmekte onun içinde aşağıdaki kodu yazıyoruz.
rs.initiate();

Cevap olarak bize problem yoksa aşağıdaki gibi mesaj dönecektir.
 {
"info2" : "no configuration explicitly specified -- making one",
"me" : "DESKTOP-U223FLP:27021",
"ok" : 1
}

Sunucumuzun Primary olup olmadığını kontrol etmek için ise aşağıdaki kodu yazıyoruz.
rs.status();

members array'i altında stateStr alanı PRIMARY ise ilk sunucumuz Primary olmuş demektir.
{
"set" : "mySet",
"date" : ISODate("2017-05-03T21:00:57.905Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "DESKTOP-U223FLP:27021",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 481,
"optime" : Timestamp(1493845155, 1),
"optimeDate" : ISODate("2017-05-03T20:59:15Z"),
"electionTime" : Timestamp(1493845155, 2),
"electionDate" : ISODate("2017-05-03T20:59:15Z"),
"configVersion" : 1,
"self" : true
}
],
"ok" : 1
}

Şimdi secondary databaseleri oluşturalım.

2 yeni komut satırı daha açıyoruz. Ve aşağıdaki gibi diğer 2 database sunucusunu oluşturuyoruz. replSet isimlerini değiştirmiyoruz. Primary sunucuda ne kullandıysak aynısını kullanacağız.
C:\MongoDB>bin\mongod --dbpath data\data2 --port 27022 --replSet mySet

C:\MongoDB>bin\mongod --dbpath data\data3 --port 27023 --replSet mySet

2 farklı komut satırında yukarıdaki komutları çalıştırdıysak yine başarılı şekilde bittiyse en altta "waiting for connections on port 2702.." şeklinde mesaj yazar.

Şimdi gelelim secondary sunucularımızı primary sunucuya tanıtmaya.Öncelikle primary sunucuya bağlanıyoruz. Aslında yukarıda bağlanmıştık kendisi primary yaparken falan eğer konsolu kapatmadıysanız oradan devam edebilirsiniz veya yeni bir komut satırı açabilirsiniz.
mySet:PRIMARY> rs.add('DESKTOP-U223FLP:27022');

olarak yazıyoruz fakat burada dikkat etmeniz gereken kural porttan önce bilgisayar adınızı yazmanızdır. Eğer hiç bir problem yok ise aşağıdaki gibi
{ "ok" : 1 }

mesajını verecektir. Hemen diğer sunucuyuda tanıtalım
mySet:PRIMARY> rs.add('DESKTOP-U223FLP:27023');

yine mesaj olarak { "ok" : 1 } cevabını aldım.

Şimdi gerçekten yukarıdaki database sunucularım secondary olmuş mu önce onları bir kontrol edeyim. aşağıdaki komutu çalıştırıyorum.
rs.status();

Cevap olarak
{
"set" : "mySet",
"date" : ISODate("2017-05-03T21:21:18.900Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "DESKTOP-U223FLP:27021",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1702,
"optime" : Timestamp(1493846249, 1),
"optimeDate" : ISODate("2017-05-03T21:17:29Z"),
"electionTime" : Timestamp(1493845155, 2),
"electionDate" : ISODate("2017-05-03T20:59:15Z"),
"configVersion" : 3,
"self" : true
},
{
"_id" : 1,
"name" : "DESKTOP-U223FLP:27022",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 332,
"optime" : Timestamp(1493846249, 1),
"optimeDate" : ISODate("2017-05-03T21:17:29Z"),
"lastHeartbeat" : ISODate("2017-05-03T21:21:17.261Z"),
"lastHeartbeatRecv" : ISODate("2017-05-03T21:21:18.788Z"),
"pingMs" : 0,
"syncingTo" : "DESKTOP-U223FLP:27021",
"configVersion" : 3
},
{
"_id" : 2,
"name" : "DESKTOP-U223FLP:27023",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 229,
"optime" : Timestamp(1493846249, 1),
"optimeDate" : ISODate("2017-05-03T21:17:29Z"),
"lastHeartbeat" : ISODate("2017-05-03T21:21:17.267Z"),
"lastHeartbeatRecv" : ISODate("2017-05-03T21:21:17.290Z"),
"pingMs" : 0,
"configVersion" : 3
}
],
"ok" : 1
}

yukarıdaki gibi bir sonuç döndü görmüş olduğunuz gibi 2 tane secondary ve  tane primary database sunucum mevcut. Fakat secondary database sunucularımla henüz tam işim bitmedi hemen onlarada bağlanıp onların slave olduğunu söylemem gerekmekte. Sırayla girip aşağıdaki kodu iki secondary sunucumda çalıştırıyorum.
mySet:SECONDARY> rs.slaveOk();

Mesaj olarak geriye bir şey dönmeyecektir.

Şimdi gelelim bu replica set mimarimizi test etmeye.
mySet:PRIMARY>  db.test.insert({name:'Replica Set Testi'});

Şeklinde primary database'ime bir kayıt ekliyorum ve ardından tekrar primary database'nde select çekip kayıdın gelip gelmediğini kontrol ediyorum.
mySet:PRIMARY> db.test.find();

Yukarıdaki gibi sorgumu yazdım ve aşağıdaki gibi kayıt geldi.
{ "_id" : ObjectId("590a4ba6a4ba2414af09b658"), "name" : "Replica Set Testi" }

Aynı sorguyu gidip diğer secondary database sunucularımda çekiyorum.
mySet:SECONDARY> db.test.find();

veee sonuuuçç :)
{ "_id" : ObjectId("590a4ba6a4ba2414af09b658"), "name" : "Replica Set Testi" }

Diğer secondary database sunucularımda da aynı kayıt geldi artık database'im çökerse datalarım ne olacak gibi bir problemimiz olmayacak. Hatta test etmek isterseniz primary sunucuyu durdurun diğer secondary üyelerden hemen bir tanesi Primary olarak çalışmaya devam edecektir.

Ayrıca

MongoDB1.bat
bin\mongod --dbpath data\data1 --port 27021 --replSet mySet

MongoDB2.bat
bin\mongod --dbpath data\data2 --port 27022 --replSet mySet

MongoDB3.bat
bin\mongod --dbpath data\data3 --port 27023 --replSet mySet

MongoDB.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\MongoDB\MongoDB1.bat", 0, False
WshShell.Run "C:\MongoDB\MongoDB2.bat", 0, False
WshShell.Run "C:\MongoDB\MongoDB3.bat", 0, False

dosyalarına yazarak , mongoDB.vbs dosyasına çift tıklayarak tüm databaseleri tek tuşla ayağa kaldırabilirsiniz. Dilerseniz MongoDB.vbs dosyasınıda task scheduler'a on start windows özelliğinde tanımlayarakta her bilgisayar açılışında otomatik ayağa kaldırabilirsiniz.

ve son olarak primary sunucu üzerinde hangi sunucunun primary olması gerektiğini söyleyebilirsiniz

Örneğin 2'nolu sunucu Primary olsun.
cfg = rs.conf()
cfg.members[0].priority = 0.5
cfg.members[1].priority = 1
cfg.members[2].priority = 0.5
rs.reconfig(cfg)

 

umarım yardımcı olmaya çalışmışımdır.

teşekkürler.

17 Ocak 2017 Salı

oracle 11 g application express urls

http://127.0.0.1:8080/apex/f?p=4550:10:3531949381628214

http://127.0.0.1:8080/apex/f?p=4550:1:4449460144545911

http://127.0.0.1:8080/apex/f?p=4950:1:2218014527849835

 

https://www.youtube.com/watch?v=y_IQCFQs7ak

JavaScript

JavaScript Nedir?    JavaScript web tabanlı bir programlama dilidir. Mayıs 1995 yılında Brendan Eich tarafından tasarlanmıştır. Kullanıcı et...