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()
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.")
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.
C# kodları ile bir MySQL veritabanına bağllantı yapılıp gelen sql komutunu çalıştırmaya yarayan fonksiyon örneği
// using MySql.Data.MySqlClient;
// using System.Configuration;
public static void ExecuteQuery(string sqlstr)
{
string db = ConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString;
using (MySqlConnection conn = new MySqlConnection(db))
{
conn.Open();
MySqlCommand mycommand = new MySqlCommand(sqlstr, conn);
mycommand.ExecuteNonQuery();
}
}
// using System.Configuration;
public static void ExecuteQuery(string sqlstr)
{
string db = ConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString;
using (MySqlConnection conn = new MySqlConnection(db))
{
conn.Open();
MySqlCommand mycommand = new MySqlCommand(sqlstr, conn);
mycommand.ExecuteNonQuery();
}
}
Foreach Loop
CSHARPForeach döngüsü bir dizideki elemanları listelemek için kullanılır.
var names = new List<string>() { "Defne", "Tom", "Zeynep" };
foreach (string name in names)
{
MessageBox.Show(name);
}
foreach (string name in names)
{
MessageBox.Show(name);
}
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.
Kullanıcının başka bir URL adresine yönlendirilmesini sağlar.
<?
header("Location: http://www.google.com");
?>
header("Location: http://www.google.com");
?>
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.
İstenilen mesajın sayfa yüklenirken ekrana gelmesini sağlayan basit bir JavaScript örneği.
<SCRIPT LANGUAGE="JavaScript">
alert("Hardiske format atmak için OK 'e tıklayınız");
</SCRIPT>
alert("Hardiske format atmak için OK 'e tıklayınız");
</SCRIPT>
Javascript ile yapılmış hareket eden bir menü örneği. Sayfada linklerinizin değişik bir biçimde gözükmesini istiyorsanız deneyebilirsiniz.
///// ADIM 1 <HEAD> Bölümleri arasına eklenecek olan bölüm
<style type="text/css">
.menulinks {position:relative;}
#menucont a{color:#006699; font-weight:bold; text-decoration:none;}
#menucont a:hover{color:#ff0000; font-weight:bold; text-decoration:underline overline; text-transform: uppercase;}
</style>
<SCRIPT LANGUAGE="JavaScript">
nSpace=7 // how many space maximum between each letter
nSpeed=200 // Animasyonun Hızı
timerLSM=null;
function LetterSpacingMenu() {
if(document.getElementById){
lnks = Math.floor(Math.random()*lnk.length);
letterSpacing = Math.floor(Math.random()*nSpace);
lnk[lnks].style.letterSpacing = letterSpacing + "px";
timerLSM = setTimeout("LetterSpacingMenu()", nSpeed);
}
}
function StopMenu() {
if(document.getElementById) {
clearTimeout(timerLSM);
for(i=0;i<lnk.length;i++)
lnk[i].style.letterSpacing = 0 + "px";
}
}
function LSMenuInit() {
if(document.getElementById) {
lnk = document.getElementById("menucont").getElementsByTagName("a");
cnt = document.getElementById("menucont");
cnt.style.textAlign= "center";
cnt.onmouseover=StopMenu;
cnt.onmouseout=LetterSpacingMenu;
LetterSpacingMenu();
}
}
onload=LSMenuInit;
</script>
// ***********************************************************
//// ADIM 2.. BODY tagları arasına eklenecek olan bölüm
// ***********************************************************
<div id="menucont">
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Anasayfa</a><br>
<a href="http://www.ipucu.web.tr/forums" id="a2" class="menulinks" title="Forumlar bölümü">Forumlar</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">ASP İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">PHP İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Javascript İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Haberler</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Yeni Başlayanlar İçin</a><br>
</div>
<style type="text/css">
.menulinks {position:relative;}
#menucont a{color:#006699; font-weight:bold; text-decoration:none;}
#menucont a:hover{color:#ff0000; font-weight:bold; text-decoration:underline overline; text-transform: uppercase;}
</style>
<SCRIPT LANGUAGE="JavaScript">
nSpace=7 // how many space maximum between each letter
nSpeed=200 // Animasyonun Hızı
timerLSM=null;
function LetterSpacingMenu() {
if(document.getElementById){
lnks = Math.floor(Math.random()*lnk.length);
letterSpacing = Math.floor(Math.random()*nSpace);
lnk[lnks].style.letterSpacing = letterSpacing + "px";
timerLSM = setTimeout("LetterSpacingMenu()", nSpeed);
}
}
function StopMenu() {
if(document.getElementById) {
clearTimeout(timerLSM);
for(i=0;i<lnk.length;i++)
lnk[i].style.letterSpacing = 0 + "px";
}
}
function LSMenuInit() {
if(document.getElementById) {
lnk = document.getElementById("menucont").getElementsByTagName("a");
cnt = document.getElementById("menucont");
cnt.style.textAlign= "center";
cnt.onmouseover=StopMenu;
cnt.onmouseout=LetterSpacingMenu;
LetterSpacingMenu();
}
}
onload=LSMenuInit;
</script>
// ***********************************************************
//// ADIM 2.. BODY tagları arasına eklenecek olan bölüm
// ***********************************************************
<div id="menucont">
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Anasayfa</a><br>
<a href="http://www.ipucu.web.tr/forums" id="a2" class="menulinks" title="Forumlar bölümü">Forumlar</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">ASP İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">PHP İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Javascript İpuçları</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Haberler</a><br>
<a href="http://www.ipucu.web.tr" id="a1" class="menulinks" title="Yeni ipucu siteniz">Yeni Başlayanlar İçin</a><br>
</div>