Kod Örnekleri & Teknik Rehberler
Python, C#, PHP ve modern web teknolojileri üzerine profesyonel örnekler.
Python & Veri Bilimi
PopülerÖğrenmesi kolay ve son derece güçlü. Yapay Zeka, Veri Analizi ve Otomasyon dünyasının lider dili Python ile ilgili en güncel snippetları keşfedin.
requests kütüphanesi kullanarak bir API üzerinden anlık döviz kurlarını çeken ve JSON verisini işleyerek ekrana yazdıran örnek.
import requests
url = "https://api.exchangerate-api.com/v4/latest/USD"
response = requests.get(url)
data = response.json()
usd_try = data['rates']['TRY']
print(f"1 Dolar şu an: {usd_try} TL")
url = "https://api.exchangerate-api.com/v4/latest/USD"
response = requests.get(url)
data = response.json()
usd_try = data['rates']['TRY']
print(f"1 Dolar şu an: {usd_try} TL")
Saniyeler içinde bir HTTP sunucusu kurup JSON yanıtı dönen API örneği.
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def home():
return jsonify(message="Merhaba Dünyadan API!")
if __name__ == "__main__":
app.run()
app = Flask(__name__)
@app.route("/")
def home():
return jsonify(message="Merhaba Dünyadan API!")
if __name__ == "__main__":
app.run()
C# (CSharp) & .NET Core
KurumsalModern, nesne yönelimli ve yüksek performanslı. ASP.NET Core ve Entity Framework ile profesyonel web ve masaüstü projeleri geliştirin.
QueryString ile Değer Alma
CSHARPSayfadan kullanıcının seçmiş olduğu değişkeni QueryString ile almak için kullanılan kod örneğidir.
string myidstr;
int myid;
if (Request.QueryString["x"] != null)
{
myidstr = Request.QueryString["x"];
myid = Int32.Parse(Request.QueryString["x"]);
}
else
{
return;
}
int myid;
if (Request.QueryString["x"] != null)
{
myidstr = Request.QueryString["x"];
myid = Int32.Parse(Request.QueryString["x"]);
}
else
{
return;
}
Veritabanında tarih alanından gelen değerin kullanıcının belirlediği tarih formatında gösterilmesini sağlar.
<asp:DataGrid id="dataGrid" runat="server">
<Columns>
<asp:BoundColumn DataField="gelis_tarihi" HeaderText="Geliş <br> Tarihi" dataformatstring="{0:dd/MM/yyyy}">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:BoundColumn DataField="gelis_tarihi" HeaderText="Geliş <br> Tarihi" dataformatstring="{0:dd/MM/yyyy}">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
PHP & Web Programlama
DinamikWeb dünyasının emektar ve güçlü dili. PDO veritabanı yönetimi, API işlemleri ve modern PHP 8.x tekniklerini inceleyin.
Bir dosyaya yazı yazdırmak için fwrite() komutu kullanılmaktadır. fputs() komutu ile dosyanın sonuna ekleme yapılmaktadır.
<?
$dosya_adi = "/wwwroot/deneme.txt";
$dosya = fopen ($dosya_adi , 'w') or die ("Dosya açılamadı!");
$metin = "Bu satır dosyaya yazılacak: Merhaba Dünya!\n";
fwrite ( $dosya , $metin ) ;
fputs ( $dosya , "Bu satır ise sonradan eklenecek\n" ) ;
fclose ($dosya);
?>
$dosya_adi = "/wwwroot/deneme.txt";
$dosya = fopen ($dosya_adi , 'w') or die ("Dosya açılamadı!");
$metin = "Bu satır dosyaya yazılacak: Merhaba Dünya!\n";
fwrite ( $dosya , $metin ) ;
fputs ( $dosya , "Bu satır ise sonradan eklenecek\n" ) ;
fclose ($dosya);
?>
Bir durumu bakarak karar vermeyi sağlar. Çeşiştli alternatiflerden seçim yapmak için kullanılır.
<?
$site = "www.ME.com.tr";
Switch $site {
Case "www.ME.com.tr";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr");
Case "www.ME.com.tr/forums";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr/forums");
default;
echo ("Şu anda ME.com sitesinde değilsiniz.");
}
?>
$site = "www.ME.com.tr";
Switch $site {
Case "www.ME.com.tr";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr");
Case "www.ME.com.tr/forums";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr/forums");
default;
echo ("Şu anda ME.com sitesinde değilsiniz.");
}
?>
JavaScript (ES6+)
Frontendİnteraktif web sayfalarının kalbi. Modern JS, Async/Await ve DOM manipülasyonu üzerine en pratik kod parçacıkları burada.
İstenilen mesajın butona basıldığı zaman ekrana gelmesini sağlayan basit bir JavaScript örneği.
<FORM>
<INPUT TYPE=BUTTON VALUE="Click me"
onClick="alert('Mesajınızı buraya yazınız')">
</FORM>
<INPUT TYPE=BUTTON VALUE="Click me"
onClick="alert('Mesajınızı buraya yazınız')">
</FORM>
Sayfalarınızda kullanıcıların mouse (fare)'un sağ tuş fonksiyonlarına ulaşmasını istemiyorsanız bu scripti rahatlıkla kullanabilirsiniz.
<style>
#ie5menu { position: absolute; width: 210px; background-color: menu; font-family: Tahoma; font-size: 12px; line-height: 20px; cursor: default; visibility: hidden; border: 2px outset default }
.menuitems { padding-left: 15px; padding-right: 15px }
//-->
</style>
<script>
var display_url=0
function showmenuie5(){
ie5menu.style.left=document.body.scrollLeft+event.clientX
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
return false
}
function hidemenuie5(){
ie5menu.style.visibility="hidden"
}
function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}
function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status=''
}
}
function jumptoie5(){
if (event.srcElement.className=="menuitems")
window.location=event.srcElement.url
}
</script>
<script>
function correct(){
if (finished){
setTimeout("begin()",1000)
}
return true
}
window.onerror=correct
function begin(){
if (!document.all)
return
if (maxheight==null)
maxheight=temp.offsetHeight
whatsnew.style.height=maxheight
temp.style.display="none"
c=1
finished=true
change()
}
</script>
<!-- İSTEDİĞİNİZ LİNKLERİ AŞAĞIDAKİ BÖLÜMLERE YERLEŞTİRİNİZ.. -->
<!--[if IE]><div id="ie5menu" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
<div class="menuitems" url="http://www.ipucu.web.tr">ipucu siteniz</div>
<div class="menuitems" url="http://www.adres2.com">LİNK2</div>
<div class="menuitems" url="http://www.google.com">Google</div>
<div class="menuitems" url="http://www.altavista.com">Altavista</div>
<div class="menuitems" url="http://www.hotmail.com">Hotmail</div></div>
<![endif]-->
<script>
document.oncontextmenu=showmenuie5
if (document.all&&window.print)
document.body.onclick=hidemenuie5
</script>
#ie5menu { position: absolute; width: 210px; background-color: menu; font-family: Tahoma; font-size: 12px; line-height: 20px; cursor: default; visibility: hidden; border: 2px outset default }
.menuitems { padding-left: 15px; padding-right: 15px }
//-->
</style>
<script>
var display_url=0
function showmenuie5(){
ie5menu.style.left=document.body.scrollLeft+event.clientX
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
return false
}
function hidemenuie5(){
ie5menu.style.visibility="hidden"
}
function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}
function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status=''
}
}
function jumptoie5(){
if (event.srcElement.className=="menuitems")
window.location=event.srcElement.url
}
</script>
<script>
function correct(){
if (finished){
setTimeout("begin()",1000)
}
return true
}
window.onerror=correct
function begin(){
if (!document.all)
return
if (maxheight==null)
maxheight=temp.offsetHeight
whatsnew.style.height=maxheight
temp.style.display="none"
c=1
finished=true
change()
}
</script>
<!-- İSTEDİĞİNİZ LİNKLERİ AŞAĞIDAKİ BÖLÜMLERE YERLEŞTİRİNİZ.. -->
<!--[if IE]><div id="ie5menu" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
<div class="menuitems" url="http://www.ipucu.web.tr">ipucu siteniz</div>
<div class="menuitems" url="http://www.adres2.com">LİNK2</div>
<div class="menuitems" url="http://www.google.com">Google</div>
<div class="menuitems" url="http://www.altavista.com">Altavista</div>
<div class="menuitems" url="http://www.hotmail.com">Hotmail</div></div>
<![endif]-->
<script>
document.oncontextmenu=showmenuie5
if (document.all&&window.print)
document.body.onclick=hidemenuie5
</script>