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.
Python'un popüler web çatısı Flask kullanarak, dış dünyaya JSON veri dönen basit bir REST API uç noktası (endpoint) hazırlama örneği.
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/selamla', methods=['GET'])
def selamla():
return jsonify({"mesaj": "Merhaba, Kod Örnekleri API servisine hoş geldiniz!", "durum": "aktif"})
if __name__ == '__main__':
app.run(debug=True)
app = Flask(__name__)
@app.route('/api/selamla', methods=['GET'])
def selamla():
return jsonify({"mesaj": "Merhaba, Kod Örnekleri API servisine hoş geldiniz!", "durum": "aktif"})
if __name__ == '__main__':
app.run(debug=True)
Hiçbir kütüphane kurmadan, sadece Python yerleşik modülleriyle yerel bir ağ üzerinde dosya paylaşımı için sunucu başlatma kodu.
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Sunucu {PORT} portunda çalışıyor...")
httpd.serve_forever()
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Sunucu {PORT} portunda çalışıyor...")
httpd.serve_forever()
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 başka bir exe programını çalıştırmaya yarayan kod örneği.
Process process = new Process();
process.StartInfo.FileName = @"C:\cmd.exe";
process.StartInfo.Arguments = "123";
process.Start();
process.WaitForExit();
process.StartInfo.FileName = @"C:\cmd.exe";
process.StartInfo.Arguments = "123";
process.Start();
process.WaitForExit();
Klasörleri içindeki dosyalar ile silmek için bir örnek
string strTempFolder = "C:\\temp";
DirectoryInfo dir = new DirectoryInfo(strTempFolder);
foreach (DirectoryInfo di in dir.GetDirectories())
{
System.Array.ForEach(Directory.GetFiles(di.FullName),delegate(string path)
{ File.Delete(path); });
Directory.Delete(di.FullName, true);
}
DirectoryInfo dir = new DirectoryInfo(strTempFolder);
foreach (DirectoryInfo di in dir.GetDirectories())
{
System.Array.ForEach(Directory.GetFiles(di.FullName),delegate(string path)
{ File.Delete(path); });
Directory.Delete(di.FullName, true);
}
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 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" )
?>
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!");
?>
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.
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>
Kullanıcının bağlandığı tarayıcı (browser)'ın türüne bakarak sayfaların başka adreslere yönlendirmesi mümkündür. Bu amaçla hazırlanan bir scripti sizlere sunuyoruz.
// ADIM-1 kodları body tagları arasına kopyalayınız
<script LANGUAGE="JavaScript">
function BrowserCheck()
{
BrowserName = navigator.appName;
BrowserVersion = parseInt(navigator.appVersion);
DetermineOutcome(BrowserName, BrowserVersion)
}
function DetermineOutcome(BrowserName, BrowserVersion)
{
<!-- Tarayıcı Netscape ise index2.html'ye yönlendiriliyor. -->
if (BrowserName == "Netscape" && BrowserVersion >=3)
{
location.href="index2.html"
}
<!-- Tarayıcı Netscape değil ise index.html'ye yönlendiriliyor. -->
else
{
location.href="index.html"
}
}
</script>
<script LANGUAGE="JavaScript">
function BrowserCheck()
{
BrowserName = navigator.appName;
BrowserVersion = parseInt(navigator.appVersion);
DetermineOutcome(BrowserName, BrowserVersion)
}
function DetermineOutcome(BrowserName, BrowserVersion)
{
<!-- Tarayıcı Netscape ise index2.html'ye yönlendiriliyor. -->
if (BrowserName == "Netscape" && BrowserVersion >=3)
{
location.href="index2.html"
}
<!-- Tarayıcı Netscape değil ise index.html'ye yönlendiriliyor. -->
else
{
location.href="index.html"
}
}
</script>