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.
Belirli bir klasör içindeki tüm .txt dosyalarını tarayıp uzantılarını toplu halde .log olarak değiştiren pratik bir otomasyon scripti.
import os
klasor_yolu = './belgeler'
for dosya_adi in os.listdir(klasor_yolu):
if dosya_adi.endswith(".txt"):
eski_yol = os.path.join(klasor_yolu, dosya_adi)
yeni_yol = os.path.join(klasor_yolu, dosya_adi.replace(".txt", ".log"))
os.rename(eski_yol, yeni_yol)
print(f"{dosya_adi} -> Uzantı değiştirildi.")
klasor_yolu = './belgeler'
for dosya_adi in os.listdir(klasor_yolu):
if dosya_adi.endswith(".txt"):
eski_yol = os.path.join(klasor_yolu, dosya_adi)
yeni_yol = os.path.join(klasor_yolu, dosya_adi.replace(".txt", ".log"))
os.rename(eski_yol, yeni_yol)
print(f"{dosya_adi} -> Uzantı değiştirildi.")
Bilgisayarlı görü (Computer Vision) projelerinde sık kullanılan, bir görseli gri tonlamaya çevirip kenar tespiti (Canny Edge Detection) yapan örnek.
import cv2
# Resmi oku
resim = cv2.imread('input.jpg')
# Gri tona çevir
gri_resim = cv2.cvtColor(resim, cv2.COLOR_BGR2GRAY)
# Kenarları tespit et
kenarlar = cv2.Canny(gri_resim, 100, 200)
# Sonucu kaydet
cv2.imwrite('kenar_tespiti.jpg', kenarlar)
print("Görüntü işlendi ve kaydedildi.")
# Resmi oku
resim = cv2.imread('input.jpg')
# Gri tona çevir
gri_resim = cv2.cvtColor(resim, cv2.COLOR_BGR2GRAY)
# Kenarları tespit et
kenarlar = cv2.Canny(gri_resim, 100, 200)
# Sonucu kaydet
cv2.imwrite('kenar_tespiti.jpg', kenarlar)
print("Görüntü işlendi ve kaydedildi.")
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.
Text dosyasına yazdırma
CSHARPAçılan text dosyasına satır eklemeye yarayan kod örneyi
string lines = "First line.\r\nSecond line.\r\nThird line.";
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Close();
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Close();
Bütün dosyaları silmek
CSHARPBir klasördeki bütün dosyaları (*.*)silmek için kullanılan kod örneği
using System.IO;
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);
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.
Herhangi bir dosya silmek için PHP'de kullanılacak komut unlink()' tir. Bu fonksiyonu kullanırken silinmesi istenilen dosyanın adının verilmesi gerekmektedir.
<?
$dizin = "/wwwroot/";
unlink ("$dizin/yeni.txt");
echo ("yeni.txt dosyası silindi!");
?>
$dizin = "/wwwroot/";
unlink ("$dizin/yeni.txt");
echo ("yeni.txt dosyası silindi!");
?>
For döngüsü
PHPFor döngüsü, belirtilen bir numaraya kadar, devam eden ifadeleri tekrarlamaktadır. For döngüsünde bir sayaç değişkeni kullanılır ve belirtilen değere kadar sayaç arttırılır ve azaltılır.
<?
for ($sayac = 1; $sayac <= 7 ; $sayac++ )
{
echo ("<font size= $sayac >");
echo ("<b><p>www.ME.com.tr</b></p>");
echo ("</font>");
}
?>
for ($sayac = 1; $sayac <= 7 ; $sayac++ )
{
echo ("<font size= $sayac >");
echo ("<b><p>www.ME.com.tr</b></p>");
echo ("</font>");
}
?>
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.
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>
Bu kod ile sayfanızda geri dön butonu oluşturabilirsiniz.
<input onclick="history.back();" type="button" value="<<geri dön">