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.
Haar Cascade sınıflandırıcılarını kullanarak bir fotoğraf üzerindeki insan yüzlerini tespit eden ve çerçeve içine alan görüntü işleme örneği.
import cv2
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
img = cv2.imread("insanlar.jpg")
gri = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
yuzler = face_cascade.detectMultiScale(gri, 1.1, 4)
for (x, y, w, h) in yuzler:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
cv2.imshow('Yuz Tespiti', img)
cv2.waitKey()
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
img = cv2.imread("insanlar.jpg")
gri = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
yuzler = face_cascade.detectMultiScale(gri, 1.1, 4)
for (x, y, w, h) in yuzler:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
cv2.imshow('Yuz Tespiti', img)
cv2.waitKey()
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)
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.
Mükemmel Sayılar
CSHARPKendisi hariç bütün pozitif çarpanları (tam bölenleri) toplamı, yine kendisine eşit olan sayılara ?mükemmel sayı? denir.
Örneğin 6=1+2+3 ve 28=1+2+4+7+14 gibi.
int sayi;
double bolumtopla = 0;
Console.Write("Bir sayı giriniz: ");
sayi = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <sayi; i++)
{
if (sayi % i == 0)
{
bolumtopla += i;
}
}
double bolumtopla = 0;
Console.Write("Bir sayı giriniz: ");
sayi = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <sayi; i++)
{
if (sayi % i == 0)
{
bolumtopla += i;
}
}
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.
MySQL veritabanına bağlantının yapılması ve sorgulama sonunda kayıtların listelenmesini sağlar.
<?
$dbh=mysql_connect ("localhost", "", "") or die (Veritabanına bağlantı kurulamıyor. Hatanın sebebi: ' . mysql_error()); mysql_select_db ("veritabanı_adı");
// bağlantı yapıldıktan sonra sorgulamaların yapılması
$sql="Select * from veritabanı";
$veriseti = mysql_query($sqi);
while ($Mysatir = mysql_fetch_row($veriseti))
{
echo $Mysatir[0.]."<br>";
}
?>
$dbh=mysql_connect ("localhost", "", "") or die (Veritabanına bağlantı kurulamıyor. Hatanın sebebi: ' . mysql_error()); mysql_select_db ("veritabanı_adı");
// bağlantı yapıldıktan sonra sorgulamaların yapılması
$sql="Select * from veritabanı";
$veriseti = mysql_query($sqi);
while ($Mysatir = mysql_fetch_row($veriseti))
{
echo $Mysatir[0.]."<br>";
}
?>
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>
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>