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.
PyPDF2 kütüphanesi kullanarak, bir klasördeki birden fazla PDF dosyasını tek bir PDF belgesi haline getiren pratik otomasyon örneği.
import PyPDF2
import os
merger = PyPDF2.PdfMerger()
path = "./belgeler/"
for file in os.listdir(path):
if file.endswith(".pdf"):
merger.append(path + file)
merger.write("birlesik_dosya.pdf")
merger.close()
print("PDF dosyaları başarıyla birleştirildi.")
import os
merger = PyPDF2.PdfMerger()
path = "./belgeler/"
for file in os.listdir(path):
if file.endswith(".pdf"):
merger.append(path + file)
merger.write("birlesik_dosya.pdf")
merger.close()
print("PDF dosyaları başarıyla birleştirildi.")
Pandas ile Veri Filtreleme
PYTHONCSV dosyasındaki verileri belirli bir kritere göre (Örn: Maaş > 5000) filtreleyen analiz kodu.
import pandas as pd
df = pd.read_csv("data.csv")
filtered_df = df[df["salary"] > 5000]
print(filtered_df.head())
df = pd.read_csv("data.csv")
filtered_df = df[df["salary"] > 5000]
print(filtered_df.head())
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.
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>
XML Dosyasından verilerin okunmasını ve okunan verilerin bir dropdownliste ekleyen kod örneğii.
string XMLFile = "D:\\ogrenciler.xml";
XmlDocument xDoc = new XmlDocument();
xDoc.Load(XMLFile);
XmlNodeList adi = xDoc.GetElementsByTagName("adi");
XmlNodeList soyadi = xDoc.GetElementsByTagName("soyadi");
XmlNodeList numarasi = xDoc.GetElementsByTagName("numarasi");
XmlNodeList sinifi = xDoc.GetElementsByTagName("sinifi");
string ogrenci;
for (int i = 0; i < adi.Count; i++)
{
ogrenci = adi[i].InnerText + " " + soyadi[i].InnerText + " " + sinifi[i].InnerText + " " + numarasi[i].InnerText;
DropDownListOgrenci.Items.Add(ogrenci);
}
XmlDocument xDoc = new XmlDocument();
xDoc.Load(XMLFile);
XmlNodeList adi = xDoc.GetElementsByTagName("adi");
XmlNodeList soyadi = xDoc.GetElementsByTagName("soyadi");
XmlNodeList numarasi = xDoc.GetElementsByTagName("numarasi");
XmlNodeList sinifi = xDoc.GetElementsByTagName("sinifi");
string ogrenci;
for (int i = 0; i < adi.Count; i++)
{
ogrenci = adi[i].InnerText + " " + soyadi[i].InnerText + " " + sinifi[i].InnerText + " " + numarasi[i].InnerText;
DropDownListOgrenci.Items.Add(ogrenci);
}
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);
?>
32 karaktere kadar şifre üretmek için kullanışlı bir fonksiyon
<?php
function sifreuret($uzunluk)
{
if(!is_numeric($uzunluk) || $uzunluk <= 0)
{
$uzunluk = 8;
}
if($uzunluk > 32)
{
$uzunluk = 32;
}
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
mt_srand(microtime() * 1000000);
for($i = 0; $i < $uzunluk; $i++)
{
$key = mt_rand(0,strlen($chars)-1);
$pwd = $pwd . $chars{$key};
}
for($i = 0; $i < $uzunluk; $i++)
{
$key1 = mt_rand(0,strlen($pwd)-1);
$key2 = mt_rand(0,strlen($pwd)-1);
$tmp = $pwd{$key1};
$pwd{$key1} = $pwd{$key2};
$pwd{$key2} = $tmp;
}
return $pwd;
}
//fonksiyonun 8 karakter uzunlukta bir şifre üretmek için çağrılması
$password = sifreuret(8);
echo $password;
?>
function sifreuret($uzunluk)
{
if(!is_numeric($uzunluk) || $uzunluk <= 0)
{
$uzunluk = 8;
}
if($uzunluk > 32)
{
$uzunluk = 32;
}
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
mt_srand(microtime() * 1000000);
for($i = 0; $i < $uzunluk; $i++)
{
$key = mt_rand(0,strlen($chars)-1);
$pwd = $pwd . $chars{$key};
}
for($i = 0; $i < $uzunluk; $i++)
{
$key1 = mt_rand(0,strlen($pwd)-1);
$key2 = mt_rand(0,strlen($pwd)-1);
$tmp = $pwd{$key1};
$pwd{$key1} = $pwd{$key2};
$pwd{$key2} = $tmp;
}
return $pwd;
}
//fonksiyonun 8 karakter uzunlukta bir şifre üretmek için çağrılması
$password = sifreuret(8);
echo $password;
?>
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.
Web sayfanızdaki resimlere sağ fare tuşu ile tıklandığında uyarı mesajı görüntüler.
<!-- 2 ADIMDA SAYFANIZA EKLEYEBİLİRSİNİZ:
1. Sayfanızın HEAD bölümüne aşağıdaki HEAD bölümünü ekleyin
2. IMG elemanlarınızı aşağıdaki şekilde düzenleyiniz. -->
<!-- ADIM 1 : HEAD Bölümü -->
<HEAD>
<script type="text/javascript">
function resimKoru(event) {
var tname
tname=event.srcElement.tagName
if (event.button==2 && tname=="IMG"){pressed="picture"}
if (pressed=="picture")
{window.alert("Bu sitedeki resimleri kopyalamayınız!")}
pressed=0
}
</script>
</HEAD>
<!-- ADIM 2 : IMG elemanı örneği -->
<BODY>
<img src="resminiz.gif" width="150" height="58" border="0" onmousedown="resimKoru(event)">
1. Sayfanızın HEAD bölümüne aşağıdaki HEAD bölümünü ekleyin
2. IMG elemanlarınızı aşağıdaki şekilde düzenleyiniz. -->
<!-- ADIM 1 : HEAD Bölümü -->
<HEAD>
<script type="text/javascript">
function resimKoru(event) {
var tname
tname=event.srcElement.tagName
if (event.button==2 && tname=="IMG"){pressed="picture"}
if (pressed=="picture")
{window.alert("Bu sitedeki resimleri kopyalamayınız!")}
pressed=0
}
</script>
</HEAD>
<!-- ADIM 2 : IMG elemanı örneği -->
<BODY>
<img src="resminiz.gif" width="150" height="58" border="0" onmousedown="resimKoru(event)">
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>