28 Haziran 2015 Pazar

BASH NEDİR??

genel olarak linux sistemlerinin yapısına bakalım. merkezde kernel diye bi sey var ve bu kernel donanımla shell arasında iletişimi saglar. shell dediğimizde kodları yazdıgımız ısım diger bi adıyla kabuk, terminal, ucbirim.shell komutlar yardımıyla kullanıcıyla iletişim kurar.bunu kernel e iletir. kernelde donanıma iletir.sonra olusan sonuc donanımdan kernele , kernelden de shelle ve en nihayetinde kullanıcıya iletilir.
peki gelelim BASH e. bash de bir shell dir.açılımı bourne-again shell dir. BASH e nası ulasılır peki?ctrl+alt+f1 ile ulaşırız.çıkmak içinse ctrl+alt+f7 kullanılır.
                         BAZI PARAMETRELER
  • echo : echo dan sonra yazılan karakterler echo ya parametre olarak gönderilir. bir örnek yazalım. 
    >>echo merhaba linux ben gamze
         merhaba linux ben gamze          yazacaktır.
    >>pwd
        /home/gamze    yazarak hangi klasörde oldugumuzu ögreniriz.
   >>ls  bulundugumuz klasordeki ögeleri listeler.
   >>ls -a gizli ögeleri de listeler.
     eger bulundugumuz klasoru degiştirmek istersek?cd(change directory kullanırız.)Diyelim home dayız.artık home da olmak degildeki home da bulunan Pictures klasorunde olmak istiyoruz.O zaman nası yapcaz?
>>ls
/home/gamze
>>cd Pictures
~Pictures$  artık Pictures klasorundeyiz. Eger cıkmak, tekrar home a donmek istersek!
>>cd ..
/home/gamze    cıkıp home a geri donduk :)
Şimdi de gecerli klasorumuzde dosya olusturmak istiyoruz.
>>ls
a b     home da ab diye dosyalar varmıs diye farzedelim.
>>touch c   c diye bir dosya olustırduk.
>>ls   
a b c       baktık home a. gercekten de olusmus.
  • Şimdi ise klasor olusturmak isteyelim.
>>mkdir d    d adlı bir klasor olusturduk.mkdir acılımı make directory dir.
>>ls
a b c d     baktık gercekten de olusmus.
  •  peki eger bir dosyanın ne zaman olusturuldugunu ögrenmek istersek?Ya da daha dogrusu en son ne zaman degişiklik yapıldıgını merak edersek?c dosyası için bakalım:
>>ls -l c
-rw -rw -r -- 1 gamze gamze 0 Nis 22 17:12 c  En son bu vakitte degişiklik yapılmış.Şimdi de biz bi degişiklik yapalım. yeniden touch c diyelim bakalıım bi degişikilik olacak mı ?
>>touch c
>>ls -l c
-rw -rw -r -- 1 gamze gamze 0 Nis 22 17:18 c
Gordugumuz gibi degişikligi gosterdi.
  • Dosya ve Klasörleri Silme
     rm komutu kullanılır. remove dan gelir. eger bir dosyayı silmek istiyorsak(mesela demin olusturdugumuz c dosyası):
>> rm c
>>ls
a b d   silindi.
Ama eger bir klasor silmek istiyorsak bize hata verir.(mesela demin olusturdugumuz d klasoru):
>>rm d
rm: cannot remove ‘d’: No such file or directory   seklinde bir hata alırız.Bunun sebebi bizi yanlışlıkla silecegimiz bir seye karsı bizi uyarmaktır.
Eger klasoru sillmek istersek
>>rm -r d      yazarız.
  •  Dosya ve klasorleri kopyalama
Dosya kopyalarken(c dosyasını kopyalarken)
>>cp c f
c dosyasını f adlı bir dosyanın içine kopyaladık.(f önceden olusturulmus bir dosya degil)

Değişkenlerin Kullanımı

>>mesaj="aksama yemege geliyorum"

>>echo $mesaj

aksam yemege geliyorum

>>echo yarın $mesaj

yarın aksam yemege geliyorum









PROLOG CALISMALARIM #1

There are 3 main things.
1.FACTS : Basically what is known. Axioms about some objects and their relationship.
  • Johnny is fat.
  • The dog is brown.
  • Suzie likes bobby.
     If we want to write relationship  in terms of Prolog ;
   fat(johnny).
   brown(dog).
   likes(suzie,bobby).

Some of one argument , some of them are 2 arguments.It is normal. Arity is number of arguments.

2.RULES :  Extends facts.

likes(ryan,britney).
likes(britney,ryan).
likes(dan,josh).

 Now lets define a rule for dating.
dating(X,Y):- likes(X,Y),likes(Y,X).

and ,
or ;
if :-
NOT not

3.QUERIES : Complex form  of facts and rules.









VARIABLES

wthr.pl
>/*weather(City, Season, Temp).*/

weather(phoenix, summer, hot).
weather(la, summer, warm).
weather(phoenix, winter, warm).


  • We write the program.Now for Prolog 
['/Users/Gamze/Desktop/wthr.pl'].

  • When we get true answer we can move.We want to write cities hot in summer.For this 

?- weather(City, summer, hot).

City = phoenix.

  • Now we want to write  cities that is warm no matter what season is.
 ?-weather(City,_, warm).
City = la
City = phoenix .
  • We want to write a city hot in summer and warm in winter. 
?-weather(City,summer , hot) ,weather(City,winter,warm).
City = phoenix.

  • Now we add some codes to whtr.pl.
>warmer_than(C1,C2) :- weather(C1, summer ,hot) , weather(C2, summer, warm), write(C1),
write(' is warmer than '), write(C2), nl.

nl means new line.

For running this write:

warmer_than(phoenix,la).

We get :

 phoenix is warmer than la
true.

STRUCTS :

 For a course we can write name of the course, date of the course, time of the course etc.

course(cse110,mon,wed,11,12,11,12,holton,bryce,coor105,coor321).
But this so long and complicated.In order to do this we can write these by using structs.

course(
    cse110,
    date(mon,wed),
    time(11,12),
    prof(holton,bryce),
    coor105
     ).

This is for monday's course.Now for wednesday's course:

course(
    cse110,
    date(mon,wed),
    time(11,12),
    prof(holton,bryce),
   coor321
        ).

 This is more suitable :)

LISTS: The first element in the list is  head.The second and rest of the list is tail. 
[Head|Tail].


Ex: 
[Head|Tail] = [john,josh,eat(cheese)].
Head=>john
Tail=>josh,eat(cheese).

Ex: If we want to print put first two item of the list.

We should choose seperation part correctly.

[X, Y | W] = [[],ryan, josh,eat(cheese)].

X=[]
Y=ryan
W=josh,eat(cheese).

NESTED LIST:

means we do not care  about that element.


[_,_,[_|X]|_] = [[],dead(z),[2,[b,c]],[],z,[2,[b,c]]].

If we write this we get : [[b,c]]

MEMBER FUNCTION:

member(X,[X|T]).      /* If X is the head of the list stop, do nothing.Returns true.*/
/* if not */
member(X,[H|T]) :-
    member(X,T).         /*If not now do the function for tail of the list.Recursive*/

For example
  • member(john, [john,jan,judy]).    /* this returns true.Because john is the head of the list.*/
  • member(troy,[john,judy,troy]).   /*this returns true.Because of recursion function evetually find troy in the list.*/
  • member(troy,[john,jan,judy]).    /* This returns false.Because there is no troy in the list.*/
  • member(X,[23,25,67,12,25,19,9,6] ), Y is X*X, Y<400.   /*it shows the nımbers whose square is smaller than 400.*/
X=12 ,Y=144
X=19,Y=361
X=9,Y=81
X=6,Y=36

man(adam).
man(peter).
man(paul).

woman(mary).
woman(eve).

parent(adam,peter).
parent(eve,peter).
parent(mary,paul).

father(F,C) :- man(F), parent(F,C).
mother(M,C) :- woman(M), parent(M,C).

is_father(F):- father(F,_).
is_mother(M):- mother(M,_).
is_son(X,Y):-man(X), parent(Y,X).
is_daughter(X,Y):-woman(X), parent(Y,X).
siblings(A,B):-parent(X,A),parent(X,B), A\=B.
uncle(U,A):- man(U), siblings(X,U),parent(X,A).
aunt(X,Y):-woman(X), siblings(Z,X),parent(Z,X).
grand_parent(G,N):-parent(X,N), parent(G,X).


APPEND FUNCTION IN LISTS
For  concatinating two lists.For example

>append([1,2,3],[a,b,c],[1,2,3,a,b,c]).
If we write this we get true.

>append([1,2,3],[a,b,c],[a,b,c,1,2,3]).
If we write thiswe get false.

If we want to write function of append:

> append([],L,L).
   append([H|T],L2,[H|L3]) :- append(T,L2,L3).
This is the function of append.If we want to process we should look at below.

  append([a,  b,  c],  [1,  2,  3],  _G518)
   append([b,  c],  [1,  2,  3],  _G587)
   append([c],  [1,  2,  3],  _G590)
   append([],  [1,  2,  3],  _G593)
   append([],  [1,  2,  3],  [1,  2,  3])
   append([c],  [1,  2,  3],  [c,  1,  2,  3])
   append([b,  c],  [1,  2,  3],  [b,  c,  1,  2,  3])
   append([a,  b,  c],  [1,  2,  3],  [a,  b,  c,  1,  2,  3])
   
   X  =  [a,  b,  c,  1,  2,  3]
   yes 

Ex:?- append(X,Y,[a,b,c,d]).
       As we see from this we concatinate X and Y lists and we get [a,b,c,d].If we run this :
X = [],
Y = [a, b, c, d]
X = [a],
Y = [b, c, d]
X = [a, b],
Y = [c, d]
X = [a, b, c],
Y = [d]
X = [a, b, c, d],
Y = []
false
  • The prefixes of [a,b,c,d] are [] , [a] , [a,b] , [a,b,c] , and [a,b,c,d] .
    prefix(P,L) :- append(P,_,L).

 
 ?-  prefix(X,[a,b,c,d]).
   
   X  =  []  ;
   
   X  =  [a]  ;
   
   X  =  [a,b]  ;
   
   X  =  [a,b,c]  ;
   
   X  =  [a,b,c,d]  ;
   
  false
  • The suffixes of [a,b,c,d] are [] , [d] , [c,d] , [b,c,d] , and [a,b,c,d] .
   suffix(S,L):-  append(_,S,L).  


 ?-  suffix(X,[a,b,c,d]).
   
   X  =  [a,b,c,d]  ;
   
   X  =  [b,c,d]  ;
   
   X  =  [c,d]  ;
   
   X  =  [d]  ;
   
   X  =  []  ;
   
   false

  • The sublists of [a,b,c,d] are [] , [a] , [b] , [c] , [d] , [a,b] , [b,c] , [c,d] , [a,b,c] , [b,c,d] , and [a,b,c,d] .
  sublist(SubL,L):-  suffix(S,L),  prefix(SubL,S). 


 BACTRACKING:
  Consider  a piece-wise function:
- if x < 3 then y = 0
- if x >= 3 and x < 6 then y =2
- if x >= 6 then y= 4

Lets encode this in Prolog

f(X,0) :- X <3.
f(X,2) :- 3 =< X, X < 6.
f(X,4) :- 6 =< X.

 Consider f(1,Y), 2<Y.
  • First it looks f(X,0). Y is instantiated to 0 . But second part fails 2 < Y. So Prolog bactracks and tries the other predicates. But the first predicate was true , the others will always fail !
  • We want to tell Prolog that if the first one succeds, there is no need to try the others.
  • We do this with a cut .

f(X,0) :- X <3, !.
f(X,2) :- 3 =< X, X < 6, !.
f(X,4) :- 6 =< X.
  • The cut (!) prevents Prolog from backtracking backwards through the cut.

  • If the first predicate fails, we know that x >= 3.So we don't have to check it in the second one.Simirlarly with x>=6 for the second and third predicates. 
f(X,0) :- X <3, !.
f(X,2) :- X < 6, !.
f(X,4) .
  •  What if we remove cuts.
f(X,0) :- X <3.
f(X,2) :- X < 6.
f(X,4) .

 ?-f(1,X).
 
 The result will (0,2,4).

Ex: Maximum of two values without a cut:

max(X,Y,X) :- X >= Y.
max(X,Y,Y) :- X < Y.

Ex: Maximum of two values with a cut :

max(X,Y,X) :- X >= Y, !.
max(X,Y,Y) .



































































 
































































































24 Haziran 2015 Çarşamba


  • MongoDb is schemaless. Yani diyelim bir obje için tanımladıgımız 3 özellik var.Diğeri içinde 3 özellik olmak zorunda değil.Diğeri için 4 özellik olabilir.Ya da demin tanımladığımız 3 özelliği olan objeyi 4 özellikli olrak değişitirebiliriz.
->mongo
>use test
>db.users.insert({'name':'Gamze Sen','city_of_birth':'Izmir'})
>db.users.find().pretty()
{
"_id" : ObjectId("557d63066d2ca190ccde6bf1"),
"name" : "Gamze Sen",
"city_of_birth" : "Izmir"
}
Bir eleman ekleyelim.Onun da 3 özelliği olsun.
>db.users.insert({'name':'Tugce','city_of_birth':'Izmir','favorite_color':'pink'})
>db.users.find().pretty()
{
"_id" : ObjectId("557d63066d2ca190ccde6bf1"),
"name" : "Gamze Sen",
"city_of_birth" : "Izmir"
}
{
"_id" : ObjectId("557d63756d2ca190ccde6bf2"),
"name" : "Tugce",
"city_of_birth" : "Izmir",
"favorite_color" : "pink"
}
Şimdi istersen 'name':'Gamze' olan elemana bir eleman daha ekleyerek onu da 3 elemanlı yapabiliriz.
>var j =  db.users.findOne('name':'Gamze')
>j.favorite_color:'Blue'
>db.users.save(j)
>db.users.find().pretty()
{
"_id" : ObjectId("557d63756d2ca190ccde6bf2"),
"name" : "Tugce Sen",
"city_Of_birth" : "Izmir",
"favorite_color" : "pink"
}
{
"_id" : ObjectId("557d63066d2ca190ccde6bf1"),
"name" : "Gamze Sen",
"city_of_birth" : "Izmir",
"favorite_color" : "Blue"
}

JSON DATA STRUCTURES
      There are 2 types of data structures in JSON.They are arrays and dictionaries.Arrays are list of things.Dictionaries are associative maps.
Arrays are written in [......]
Dictionaries are written in {key:value,......}
Documents are starts with dictionaries.
{"name":"value", "city":"value", interests: [.......this is array.these are dictionaries.written in {}]}

JSON SUBDOCUMENT
Example : Write a JSON document with a single key, "address" that has as it value another document with the keys “street_address”, “city”, “state”, “zipcode”, with the following values: “street_address” is "23 Elm Drive", “city” is "Palo Alto", “state” is "California", “zipcode” is "94305".
{"address":{"street_address":"23 Elm Drive","city":"Palo Alto","state":"California","zipcode":"94305"}}
Conditional Statements in Python
LIST:
>>fruit=['apple','orange','banana']
>>if 'apple' in fruit:
...   print("there is an apple")
>>
>>there is an apple
DICTIONARIES IN PYTHON
Like in Json. But there is no order in Python Dictionaries.
>>g={"name":"gamze","surname":"sen"}
>>g

{'surname': 'sen', 'name': 'gamze'}
>>g['surname']="abc"
>>g
{'surname': 'abc', 'name': 'gamze'}
>> g.keys()
{'surname', 'name'}
>>'surname' in g
True
>>'last_name' in g
False
*If we check the item in the list, it only looks whether or not key.   
>>'gamze' in g
False

Example:
Initialize a new dict named "colors" with the following key values pairs: sky is blue, sea is blue. earth is brown. Note: Please preserve the order of these keys when you enter your answer.
>>colors = {'sky': 'blue', 'sea' : 'blue', 'earth': 'brown'}

EXCEPTIONS IN PYTHON
Exception hata demektir.Yazdığımız kodda hatalar çıktığı zaman bunu bilmek isteriz.Bu yüzden kodumuzda try exception bloğunu kullanırız.Bunun içinse kodumuzun başına import sys yazmamız gerekir.
exception.py adıda örnek bir program yazalım:
import sys
try:
    print 5/0
except Exception as e:
    print "exception: ", type(e) , e
print "but life goes on"

Çalıştırdığımızda şu outputu elde ederiz:

>>exception:  <type 'exceptions.ZeroDivisionError'> integer division or modulo by zero
but life goes on



20 Haziran 2015 Cumartesi

SCHEME PAIRS AND LISTS

PROCEDURES IN SCHEME: Procedure dediğimiz şey fonksiyon gibidir.(procedure-name argument-1 .... argument-n) 

PAIRS: cons fonksiyonu girilen argumanları pair yapar.
>(cons 1 2)
(1 . 2)
>(cons (cons 1 2) 3)
((1 . 2) . 3)

LISTS:
 Listler pairlardan oluşur.
>(cons 1 (cons 2 null))
'(1 2)
>(define my-list (cons 1 (cons 2 (cons 3 null))))
>my-list
'( 1 2 3)
Genel olarak şu şekilde yazabiliriz.
list (el-1 el-2 el-3 .....el-n) 
(cons el-1 (cons el-2 (cons el-3 (cons el-4 null))))

Scheme de listelere istediğimiz şeyleri yazabiliriz.

>(define lst (list 1 2 3 'a 'b 'c "hello"))
lst
'( 1 2 3 a b c "hello")
Örnek: Bir fonksiyon yazalım bizden bir sayı alsın ve 0 dan o sayıya kadar olan sıralamayı bize liste olarak yazdırsın.
 >(define (compile-list-helper x lst)
     (cond[(zero? x) (append (list 0) lst)]
              [else (compile-list-helper (- x 1) (append (list x) lst))]))
>(define (compile-list num)
    (compile-list-helper num empty))   ; basta elimizdeki listenin empty oldugunu gosteriyor. Bu fonksiyonun calısması için bir helper fonksyon yazalım ve onu bu fonksyonun uzerine yazalım.

Bir de listeler için car cdr gibi özellikler var. car listenin ilk elemanı , cdr ise listenin ilk elemanını çıkardığımızda kalan halidir.car ile first , cdr ile rest fonksiyonu aynıdır.

>(define lst (list 1 2 3 'a 'b 'c "hello"))
>(first lst)  => 1
>(car lst)    => 1
>(rest lst)   => '(2 3 a b c "hello")
>(cdr lst)    => '(2 3 a b c "hello")

Bir de caddr cdddr gibi bunların kompleks hali var.Bunları sondan okumaya başlıyoruz.Mesela cadr ise önce listenin cdr sini alıcaz sonra cdr listesinin car ını alıcaz.Yani daha açık haliyle önce ilk elemanı çıkarıp kalan listeyi elde edicez ve cdr yi elde etmiş olcaz.Sonra kalan listenin ilk elemanını alıcaz.Bu şekilde cdr nin car ını alıcaz yani cadr.

>(define lst (list 1 2 3 'a 'b 'c "hello"))
>(cadr lst)   => 2
>(caddr lst)  => 3
>(cdddr lst)  =>'(a b c "hello")
>(equal? (list 1 2 3) lst)   =>list ile lst yi karşılaştırır.True ya da false döndürür.
#f

Örnek: Bir procedure yazalım.Bir liste ve bir sayı alsın.Mesela 0 girdiysem listenin ilk elemanını, 1 girdiysem 2. elemanını, 3 girdiysek 2. elemanını göstersin.
>(define (my-list-ref lst n)
    (cond[(zero? n) (car lst)]
             [else (my-list-ref (cdr lst) (- n 1))]))
(my-list-ref (list 'a 'b 'c 'd) 1)
'b
(my-list-ref (list 'a 'b 'c 'd) 3)
 'd

 Örnek: Verilen bir listedeki seçtiğimiz bir elemanın kaç tane olduğunu bulan kod yazalım.Mesela
 (member-count '(1 1 2 2 3 4 4 5 5 5) 5)    =>   3 outputunu vermeli.
>(define (member-count-helper counter lst member)
  (cond[(null? lst) counter]
       [(eq? (car lst) member) (member-count-helper (+ counter 1) (cdr lst) member) ]
       [else (member-count-helper counter (cdr lst) member)]))
(define (member-count list member1)
  (member-count-helper 0 list member1))

ya da
>(define (member-count list member)
  (if (null? list)
      0
      (if (= (car list) member)
          (+ 1 (member-count (cdr list) member))
          (member-count (cdr list) member)
          )
      )) 


USING LET TO DEFINE LOCAL VARIABLES:
 Mesela elimizde f fonksiyonu olsun ve şu şekilde tanımlanmış olsun.
f(x,y) = x(1+xy)^2 + y(1-y) + (1+xy)(1-y)

a= (1 + xy)
b= (1 - y)
O zaman  f(x,y) = xa^2 + yb + ab olur.

>(define (f x y)

    (define a (+ 1 (* x y)))

    (define b  (- 1 y))

        (+ (* x (* a a)) (* y b) (* a b)))


>(define (f x y)
    (let ((a (+ 1 (* x y)))
            (b (- 1 y)))
     (+ (* x (* a a)) (* y b) (* a b))))


>(define (f x y)

    ((lambda ( a b)

       (+ (* x (* a a)) (*  y b) (* a b)))

   (+ 1 (* x y))

   (- 1 y)))


Let in genel şeklini yazacak olursak:
(let ((var-a (def-a))
        (var-b (def-b))
         ..........
        (var-n (def-n)) (body))

Lamda ile Türev: D = f(x+dx) -f(x)     şeklindedir.
                                              dx           

>(define (cube x) (* x (* x x)))
>(define (deriv f dx)
    (lambda (x)
       (/ (- (f (+ x dx)) (f x)) dx)))
((deriv cube 0.001) 5)
75.01500100002545  sonucunu alırız.


Lambda genel şekilde yazılırsa:
(lambda (<parameters>) (body))

LAMBDA
Procedure ları lambda kullanarak yazabiliriz.
>(define (plus4 x) (+ x 4))

>(define plus4 (lambda (x) (+ x 4)))

Örnek: İkili bir liste girdiğimizde 2.elemanı büyük olan pairin ilk elemanını gösteren kod yazalım:
Mesela '((2 3)(3 7) (7 98) (1 34) (9 45)) bu listede en büyük ikinci eleman 98 dir.Onun başındaki eleman olan 7 yi output olarak vermeli.

>(define (find-largest list largest element)
    (cond[(null? list) element]
             [(> (cadar list) largest) (find-largest (cdr list) (cadar list) (caar list))]
             [else (find-largest (cdr list) largest element)]))

(find-largest '((2 3)(3 7) (7 98) (1 34) (9 45)) 0 0)
7
Örnek : Listedeki elemanı silen kod yazınız:Mesela '((2 3)(3 7) (19 98) (1 34) (9 45)) '(3 7)
'((2 3) (19 98) (1 34) (9 45)) olsun.

>(define (f list n)
      (cond ((null? list) '())
        ((equal? (car list) n) (cdr list))
        (else (cons (car list) (f (cdr list) n)))))


(f '((2 3)(3 7) (19 98) (1 34) (9 45)) '(3 7))
'((2 3) (19 98) (1 34) (9 45))

Örnek : Listeyi istediğimiz şekilde sıralayan kod yazalım: Mesela:'((-5 3) (9 17) (8 32) (3 6)) descending
dediğimizde '((9 17) (8 32) (3 6) (-5 3)) olsun.
 
>(define (ascending a b)
  (if (< a b)
      #t
      #f))
(define (descending a b)
  (if (> a b)
      #t
      #f))
(define (remove-list list element)
  (cond[(null? list) '()]
       [(= (car element) (caar list)) (cdr list)]
       [else (cons (car list)(remove-list (cdr list) element))]))


(define (find-order list element sort-type)
  (cond[(null? list) element]
       [(sort-type (caar list) (car element)) (find-order (cdr list) (car list) sort-type)]
       [else (find-order (cdr list) element sort-type)]))


(define (sort-list list sort-type)
  (if  (null? list) list
       (cons (find-order list (car list) sort-type) (sort-list (remove-list list (find-order list (car list) sort-type)) sort-type))))

      


(sort-list '((-5 3) (9 17) (8 32) (3 6)) descending)

'((9 17) (8 32) (3 6) (-5 3))


MAP:

>(map + '(1 2 3) '(4 5 6))
'(5 7 9)

>(map (lambda (x) (* x x)) '(1 2 3))
'(1 4 9)

SORTING:

>(sort '(8 6 7 2 -1 4 3) <)
'(-1 2 3 4 6 7 8)

LOCAL VARIABLE:

>(let ((i 2) (j 3))
  (* i j))

6
>(let ((i 1))
  (let ((j (+ i 1)))
    (+ i j)))


3

>(let* ((i 1) (j (+ i 2)))
  (* i j))


3


>(reverse '(1 2 3 4 5))
'(5 4 3 2 1)

karekok
(define (sqrt x)



       (the y (and (>= y 0) (= (square y) x))))































12 Haziran 2015 Cuma

JSON:JAVASCRİPT OBJECT NOTATION

JSON: javascript object notation: javascript nesne gösterimi
    Amacı veri alışverişi yaparken daha küçük boyutlarda veri alıp göndermektir.Bu şeklide daha hızlı web uygulamaları geliştirilebilir.XML e alternatif olarak kullanılır.(Extensible Markup Language)

KULLANIMI:

Nesne{ a: ..., b : ... }şeklinde kullanılır.Her isimden sonra  : gelir ve sonrasına değer yazılır. Bu şekilde key-value ikilisi oluşturulur.

Örnek1:
{
"tur":"blog",
"yazar":"gamze sen"
}

Örnek2:
{
"tur":"blog",
"yazar":"gamze sen",
"yayınlar":[
{"ad":"Bazı islemler","tarih":"2015"}
{"ad:"Yeni Terimler","tarih":"2015"}
]
}

XML: Extensible Markup Language
W3C(world wide web) uygulaması tarafından geliştirilen XML tree yapısında bir dildir.

KULLANIMI:

<root>

<child>

<subchild>Abc.......</subchild>

</child>

</root>

JSON ile XML KULLANIMINDAKİ FARKLAR:

XML ile:

<tv>

<dizi>

<adi>Pretty Little Liars </adi>
<kanali>abc</kanalı>

</dizi>

</tv>

JSON ile:

"tv":[
{
"adi":"Pretty Little Liars",
"kanali": "abc"
}
{
"adi":"How I Met Your Mother",
"kanali":"cbs"
}
]

5 Haziran 2015 Cuma


ps => process information.Bu komut bize şu an çalışmakta olan işlemleri gösterir. Terminale ps yazarak çalıştırırız.
echo komutunu kullanarak terminalde istediğimiz seyleri print edebiliriz. Mesela:
>>echo 'Goodbye my lover'
Goodbye my lover         çıktısını alacağız.
Variables
 Terminalde değişken kullanalım. atamayı = işareti kullanarak yapıyoruz.
>>name=gamze
>>echo "my name is $name"
my name is gamze cıktısını alıyoruz.

Terminalde Bazı İşlemler

->pwd ile nerde oldugumuzu bulalım. Mesela /home dayız. Önce orda deneme.txt adında bi dosya olusturalım.
>touch deneme.txt
Şimdi bunu ordaki Documents klasorune tasımak isteyelim.
>mv deneme.txt ~/Documents yazalım.
>ls ~/Documents yazıp deneme.txt nin Documenst klasorunde oldugunu gorelim.
Şimdi de Documents klasorundeki deneme.txt dosyasını Music klasorune kopyalamak istedigimizi dusunelim.
>cp ~/Documents/deneme.txt ~/Music yazarız.
>ls ~/Music dedigimizde deneme.txt dosyası artık Music klasorunde de bulunur.
>rm ~/silmek_istegimiz_klasor/deneme.txt
>ls ~/silmek_istegimiz_klasor/     artık yok :)
Bir dosyanın içindekileri başka bir dosyaya aktarmak istedigimizi dusunelim. bunun için:
>cat aktarılcak_dosya > yeni_dosya bu sekilde içerik yeni dosya adlı dosyaya aktarıldı. Görmek için
>cat yeni_dosya.txt yazıp içerigi görebiliriz.

>gamze@gamze:~/Documents$ ls
bidaha.txt   deneme.txt  New Document.ott     uyan
deneme1.txt  gamze.txt   New Spreadsheet.ots

Mesela bu Documents klasorundeki bidaha.txt ve deneme.txt dosyalarını uyan adlı klasore kopyalamak isteyelim:
>cp bidaha.txt deneme.txt uyan     görmek için
>ls uyan/       yazalım ve görelim.
Şimdi ise aynı anda Documents içindeki uyan dosyasına yazdıgımız bidaha.txt ve deneme.txt yi silmek isteyelim:
>rm ~/Documents/uyan/bidaha.txt ~/Documents/uyan/deneme.txt yazarız. 
Bir dosyayı silmek içinse , mesela uyan dosyasını silmek isteyelim.
>rm -rf uyan           deriz.
Klasör kopyalamak istersek:
>cp -r kopyalanacak_dosya yeni_dosya deriz.

YENİ ŞEYLER - PYTHON

pythonda string tanımlarken tırnak işaretleri arasında yazıyoruz.
>>age = 21
name = " gamze "
print age
print name
dediğimizde alacagımız outputlar : 
21
gamze     olacaktır.
python multiple assignment yapmamıza izin verir.
a=b=c=1       dediğimizde 3 degişkenin de degeri 1 e atanmış oldu.
ayrıca
age,name,number=21,"gamze",32     yazarak ta 3 degişkene degerler atayabiliriz.
pythonda bölme işlemi yaparken 
->eger 2 tam sayıyı bölüyorsak sonuc tam sayı cıkar.
>> print 22/78
0
->eger sayılardan biri floating number ise sonucta floating number cıkar.
>>print 10.0/3
3.33333333333
PYTHON STRINGS
    Stringler bildigimiz gibi ilk karakteri 0dan baslar.
>>str = 'hello world!'
>>print str
hello world!
>>print str[0]
h
>>print str[2:5]  2.karakterden 4.karaketere kadar yazar.
llo
>>print str[2:]    2.karakterden stringin sonuna kadar yazar.
llo world!
>>print str *2     stringi 2 kez yazar.
hello word!hello world!
>>print str + "TEST"      stringe TEST kelimesini ekler.
hello world! TEST
PYTHON LISTS
>>list = ['gamze' , 123 , 22.6 , 'john' , 21]
>>tiny = [ 125 , 'john']
>>print list
['gamze' , 123 , 22.6 , 'john' , 21]
>>print list[0]
gamze
>>print list[1:3]       listenin 1. ve 2. elemanını yazırır.
123 , 22.6
>>print list[1:]
123 , 22.6 , john , 21
>>print tinylist*2
125, john , 125, john
>>print list+tinylist            iki listeyi birbirine ekler.
gamze , 123 , 22.6 , john , 21 , 125 , john
PYTHON KEY-VALUE 
>>dict={}
>>dict['one'] = "this is one"
>>dict[2] = "this is two"
>>tinydict = { 'name' : 'john', 'code' : 8567 , 'dept':'sales'}
>>print dict['one']
this is one
>>print dict[2]
this is two
>>print tinydict
{'dept': 'sales', 'code': 6748, 'name': 'john'}
>>print tinydict.keys()
['dept , 'code' , 'name']
>>print tinydict.values()
['sales' , 6748 , 'john' ]
KULLANICIDAN BİLGİ ALMA
2 yöntem vardır.input ve raw_input.Bu iki fonksiyon birbirinin aynısı gibi görünse de aralarında bir fark vardır.
>>#!/usr/bin/env python
#-*- coding: utf-8 -*-
a = input("bir sayı giriniz:")
b = input("bir sayı daha giriniz:")
print a+b

Bu kodu çalıştırdığımızda output : 45 12
57 olur.
>>#!/usr/bin/env python 
# -*- coding: utf-8 -*-
a = raw_input("bir sayi giriniz:")
b= raw_input("bir sayi daha giriniz:")
print a+b

Bu kodu çalıştırdığımızda ise output : 45    12
45+12    olur.YANİ input fonksiyonu toplama yaparken raw_input fonksiyonu sadece yanyana yazdırır.
Yani raw_input gelen inputları stringe dönüştürür.input fonksiyonu ise girilen inputu olduğu gibi alır.
CASTING
Değişken typelarını değiştirmektir.
>>a = "23"
a şu an string olarak tanımlandı.Bunu int tipine çevirmek için
>>int(a)
23       
Ancak tabiki her karakter dizisini int tipine çevirmemiz mümkün değil.
>>a = " gamze"
>>int (a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'gamze'   şeklinde hata alırız.
>>a  = 12
>>str(a)
'12'
>>float(a)
12.0
Comments:python da yorum yapmak için # işareti kullanılır.
PYTHON DA IF-ELSE-ELIF STATEMENT
Bir dosya açıp içine kodlarımızı yazalım:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
sayi = int(raw_input("bir sayi giriniz:"))
if sayi>100:
    print "girdiginiz sayi 100 den buyuktur."
elif sayi == 100:
    print "girdiginiz sayi 100 dur."
else:
    print "girdiginiz sayi 100 den kucuktur."

Bu kodu çalıstırdıgımızda if-else-elif yapısını anlarız.







BAZI TERİMLER

The rules that determine what is allowed are called the syntax of the language.Syntax rules specify the basic vocabulary of the language and how programs can be constructed using things like loops, branches, and subroutines.However, syntax is only part of the story. It's not enough to write a program that will run.You want a program that will run and produce the correct result! That is, the meaning of the program has to be right. The meaning of a program is referred to as its semantics. More correctly,the semantics of a programming language is the set of rules that determine the meaning of a program written in that language. A semantically correct program is one that does what you want it to.Furthermore, a program can be syntactically and semantically correct  but still be a pretty bad program. Using the language correctly is not  the same as using it well. For example, a good program has "style." It is written in a way that will make it easy for people to read and to understand.  It follows conventions that will be familiar to other programmers. And it has an overall design that will make sense to human readers. The computer is completely oblivious to such things, but to a human reader, they are paramount. These aspects of programming are sometimes referred to as pragmatics.