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)
Belirlenen bir haber sitesinden anlık başlıkları çekip listeleyen temel scraping örneği.
import requests
from bs4 import BeautifulSoup
url = "https://news.ycombinator.com/"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
for story in soup.find_all("span", class_="titleline")[:10]:
print(story.text)
from bs4 import BeautifulSoup
url = "https://news.ycombinator.com/"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
for story in soup.find_all("span", class_="titleline")[:10]:
print(story.text)
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.
Textboxa girilen değeri SQL database'e aktarmaya yarayan örnek
//Öncelikle bunu en üstteki kütüphaneye ekleyin
System.Data.SqlClient;
//bu kod public alanda tanımlanacak
SqlConnection baglanti = new SqlConnection=("Data Source=SQLserverinAdı;Initial Catalog=VeriTabanının adı;Integrated Security=True"");
SqlCommand komut = new SqlCommand();
//bu kodlar ise button tıkalndığında yazılacak
baglanti.Open();
komut.Connection=baglanti();
komut.commandText="insert into urun (urun_no,urun_adi) values ("+textBox1.text+","textBox2.text");
komut.exeNonQuery();
baglanti.close();
System.Data.SqlClient;
//bu kod public alanda tanımlanacak
SqlConnection baglanti = new SqlConnection=("Data Source=SQLserverinAdı;Initial Catalog=VeriTabanının adı;Integrated Security=True"");
SqlCommand komut = new SqlCommand();
//bu kodlar ise button tıkalndığında yazılacak
baglanti.Open();
komut.Connection=baglanti();
komut.commandText="insert into urun (urun_no,urun_adi) values ("+textBox1.text+","textBox2.text");
komut.exeNonQuery();
baglanti.close();
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.
Veritabanından çekilen verileri comboboxta yazdıran güzel bir kod. Herhangi bir formun içerisinde <SELECT></SELECT> blokları arasına yerleştirilmesi gerekiyor.
<SELECT NAME='kategori_id'>
<?
$dbh=mysql_connect ("localhost", "", "") or die (' Veritabanına bağlantı sağlanamıyor. Nedeni: ' . mysql_error());
mysql_select_db ("veritabanı_adı");
$sql = "SELECT * FROM tablo";
$sonuc = mysql_query($sql);
while ($satir = mysql_fetch_row($sonuc))
{
?>
<OPTION Value="<?=$satir[0]?>"><?=$satir[1]?></OPTION>
<?
}
?>
</select>
<?
$dbh=mysql_connect ("localhost", "", "") or die (' Veritabanına bağlantı sağlanamıyor. Nedeni: ' . mysql_error());
mysql_select_db ("veritabanı_adı");
$sql = "SELECT * FROM tablo";
$sonuc = mysql_query($sql);
while ($satir = mysql_fetch_row($sonuc))
{
?>
<OPTION Value="<?=$satir[0]?>"><?=$satir[1]?></OPTION>
<?
}
?>
</select>
Herhangi bir dosyayı açıp satır satır okumamız gerekebilir. PHP'de dosyanın içeriğini satır satır okutmamızı fgets() fonksiyonu sağlamaktadır.
<?
$dizin = "/wwwroot/";
if ($dosya_adi = (fopen ("$dizin/deneme.txt" , 'r') ) ) {
echo ("Dosya açıldı!<br>");
}
else {
echo ("Dosya açılamadı!");
}
while ( ! feof ($dosya_adi ) ) {
$mysatir = fgets ( $dosya_adi) ;
echo ("$mysatir<br>");
}
fclose ($dosya_adi);
?>
$dizin = "/wwwroot/";
if ($dosya_adi = (fopen ("$dizin/deneme.txt" , 'r') ) ) {
echo ("Dosya açıldı!<br>");
}
else {
echo ("Dosya açılamadı!");
}
while ( ! feof ($dosya_adi ) ) {
$mysatir = fgets ( $dosya_adi) ;
echo ("$mysatir<br>");
}
fclose ($dosya_adi);
?>
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 script web sayfanızın sunucudan tekrar yüklenmesini sağlar.
<!-- ADIM 1:Aşağıdaki kodu web sayfanızın HEAD kısmına ekleyin -->
<HEAD>
<script type="text/javascript">
<!-- Başlangıç
function reFresh() {
location.reload(true)
}
/* Aşağıdaki değişkeni istediğiniz sayfayı yeniden yükleme aralığı olarak ayarlayın (Milisaniye).
1 dakika = 60000 milisaniye. */
window.setInterval("reFresh()",300000);
// Son -->
</script>
</HEAD>
<HEAD>
<script type="text/javascript">
<!-- Başlangıç
function reFresh() {
location.reload(true)
}
/* Aşağıdaki değişkeni istediğiniz sayfayı yeniden yükleme aralığı olarak ayarlayın (Milisaniye).
1 dakika = 60000 milisaniye. */
window.setInterval("reFresh()",300000);
// Son -->
</script>
</HEAD>