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.
Web siteleri için görselleri optimize etmek amacıyla kullanılan, belirtilen bir görseli en-boy oranını koruyarak yeniden boyutlandıran kod örneği.
from PIL import Image
def resim_boyutlandir(dosya, genislik):
img = Image.open(dosya)
oran = (genislik / float(img.size[0]))
yukseklik = int((float(img.size[1]) * float(oran)))
yeni_img = img.resize((genislik, yukseklik), Image.Resampling.LANCZOS)
yeni_img.save('boyutlandirilmis_resim.jpg')
resim_boyutlandir('manzara.jpg', 800)
def resim_boyutlandir(dosya, genislik):
img = Image.open(dosya)
oran = (genislik / float(img.size[0]))
yukseklik = int((float(img.size[1]) * float(oran)))
yeni_img = img.resize((genislik, yukseklik), Image.Resampling.LANCZOS)
yeni_img.save('boyutlandirilmis_resim.jpg')
resim_boyutlandir('manzara.jpg', 800)
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ı okuma
CSHARPBu kod seçilen text dosyasını satır satır okumaktadır.
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
Modern C# projelerinde verileri foreach kullanmadan, SQL benzeri bir yapıyla hızlıca filtrelemeyi ve sıralamayı sağlayan LINQ örneği.
using System.Linq;
List<int> sayilar = new List<int> { 5, 12, 8, 20, 3, 15 };
var sonuc = sayilar.Where(x => x > 10).OrderBy(x => x).ToList();
foreach(var n in sonuc) Console.WriteLine(n);
List<int> sayilar = new List<int> { 5, 12, 8, 20, 3, 15 };
var sonuc = sayilar.Where(x => x > 10).OrderBy(x => x).ToList();
foreach(var n in sonuc) Console.WriteLine(n);
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.
MySQL veritabanına bağlantı yapılmasını sağlar.
$dbh=mysql_connect ("localhost", "", "") or die (Veritabanına bağlantı kurulamıyor. Hatanın sebebi: ' . mysql_error());
mysql_select_db ("veritabanı_adı");
mysql_select_db ("veritabanı_adı");
Herhangi bir dosyanın diskte kapladığı yeri öğrenmek için filesize() komutu kullanılmaktadır.
<?
echo ("Dosyanın boyutu");
echo filesize( "dene.txt" )
?>
echo ("Dosyanın boyutu");
echo filesize( "dene.txt" )
?>
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.
Ziyaretçinin sorduğu sorunun cevabını anında almasını istiyorsanız, bu scripti deneyin. Sayfa refresh edilmeden soruların cevaplarını görmek mümkün olmaktadır.
// ……………………………………………………………….
// ..1.. <HEAD></HEAD> Tagları arasına eklenecek bölüm
// ……………………………………………………………….
<SCRIPT LANGUAGE="JavaScript">
function showFAQ(form) {
form.cevap.value = form.question.options[form.question.selectedIndex].value;
}
</SCRIPT>
// ……………………………………………………………….
// ..2.. <BODY></BODY> Tagları arasına eklenecek bölüm
// ……………………………………………………………….
<form name=faqform>
<table border=1 cellspacing=0 cellpadding=5>
<tr bgcolor="#BEA78B">
<td align=center><font face="verdana,arial" size="-1" color="#000000">
<b>Soru Cevap Örnek Form</b></font></td>
</tr>
<tr bgcolor="#E8E4D0"><td><font face="verdana,arial" size="-1"><br>
<center> Soruların üzerine tıklayarak yanıtlarını görebilirsiniz.</center>
<p>
<ul><select size=10 name=question onChange="javascript:showFAQ(this.form);">
<option value="......CEVAPLARI BURAYI YAZINIZ......"> --> ......SORULARI BURAYA YAZINIZ......
<option value="www.ipucu.web.tr"> --> Şu anda hangi sayfadayız?
<option value="cevap 2"> --> Soru 2
<option value="Cevap 3"> --> Soru 3
<option value="Cevap 4"> --> Soru 4
</select>
</ul>
<p align="center">
Yanıtlar:
<p>
<ul>
<textarea name="cevap" rows=15 cols=50 wrap=virtual>
// ..1.. <HEAD></HEAD> Tagları arasına eklenecek bölüm
// ……………………………………………………………….
<SCRIPT LANGUAGE="JavaScript">
function showFAQ(form) {
form.cevap.value = form.question.options[form.question.selectedIndex].value;
}
</SCRIPT>
// ……………………………………………………………….
// ..2.. <BODY></BODY> Tagları arasına eklenecek bölüm
// ……………………………………………………………….
<form name=faqform>
<table border=1 cellspacing=0 cellpadding=5>
<tr bgcolor="#BEA78B">
<td align=center><font face="verdana,arial" size="-1" color="#000000">
<b>Soru Cevap Örnek Form</b></font></td>
</tr>
<tr bgcolor="#E8E4D0"><td><font face="verdana,arial" size="-1"><br>
<center> Soruların üzerine tıklayarak yanıtlarını görebilirsiniz.</center>
<p>
<ul><select size=10 name=question onChange="javascript:showFAQ(this.form);">
<option value="......CEVAPLARI BURAYI YAZINIZ......"> --> ......SORULARI BURAYA YAZINIZ......
<option value="www.ipucu.web.tr"> --> Şu anda hangi sayfadayız?
<option value="cevap 2"> --> Soru 2
<option value="Cevap 3"> --> Soru 3
<option value="Cevap 4"> --> Soru 4
</select>
</ul>
<p align="center">
Yanıtlar:
<p>
<ul>
<textarea name="cevap" rows=15 cols=50 wrap=virtual>
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>