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)
Büyük veri setleri içerisinde belirli kriterlere göre filtreleme yapmayı ve istatistiksel özet almayı sağlayan profesyonel veri analizi örneği.
import pandas as pd
# Veri setini yükle
df = pd.read_csv('satislar.csv')
# Filtreleme: Satışı 5000'den büyük olan ve Ankara şubesi verileri
filtre = df[(df['Satis'] > 5000) & (df['Sehir'] == 'Ankara')]
# Genel istatistiksel özet
print(filtre.describe())
# Gruplandırarak toplam alma
print(df.groupby('Kategori')['Satis'].sum())
# Veri setini yükle
df = pd.read_csv('satislar.csv')
# Filtreleme: Satışı 5000'den büyük olan ve Ankara şubesi verileri
filtre = df[(df['Satis'] > 5000) & (df['Sehir'] == 'Ankara')]
# Genel istatistiksel özet
print(filtre.describe())
# Gruplandırarak toplam alma
print(df.groupby('Kategori')['Satis'].sum())
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.
Bütün dosyaları silmek
CSHARPBir klasördeki bütün dosyaları (*.*)silmek için kullanılan kod örneği
using System.IO;
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);
Veritabanında tarih alanından gelen değerin kullanıcının belirlediği tarih formatında gösterilmesini sağlar.
<asp:DataGrid id="dataGrid" runat="server">
<Columns>
<asp:BoundColumn DataField="gelis_tarihi" HeaderText="Geliş <br> Tarihi" dataformatstring="{0:dd/MM/yyyy}">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:BoundColumn DataField="gelis_tarihi" HeaderText="Geliş <br> Tarihi" dataformatstring="{0:dd/MM/yyyy}">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
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 dosya oluşturmak için PHP'de kullanılacak komut touch()' tır. Bu fonksiyonu kullanırken oluşturulması istenilen dosyanın adının verilmesi gerekmektedir.
<?
$dizin = "/wwwroot/";
touch ("$dizin/yeni.txt");
echo ("yeni.txt dosyası oluşturuldu!");
?>
$dizin = "/wwwroot/";
touch ("$dizin/yeni.txt");
echo ("yeni.txt dosyası oluşturuldu!");
?>
Bir durumu bakarak karar vermeyi sağlar. Çeşiştli alternatiflerden seçim yapmak için kullanılır.
<?
$site = "www.ME.com.tr";
Switch $site {
Case "www.ME.com.tr";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr");
Case "www.ME.com.tr/forums";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr/forums");
default;
echo ("Şu anda ME.com sitesinde değilsiniz.");
}
?>
$site = "www.ME.com.tr";
Switch $site {
Case "www.ME.com.tr";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr");
Case "www.ME.com.tr/forums";
echo ("Şu anda bulunduğunuz sitenin adresi: www.ME.com.tr/forums");
default;
echo ("Şu anda ME.com sitesinde değilsiniz.");
}
?>
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.
Sayfanın sol tarafında duran ve mouse üzerine geldiği zaman açılan bir gizli menü örneği..
// *****************************************************************
// ADIM 1 <HEAD> Bölümleri arasına eklenecek olan bölüm
// *****************************************************************
<script language="JavaScript1.2">
function move(x) {
if (document.all) {
object1.style.pixelLeft += x;
object1.style.visibility = "visible"}
else if (document.layers) {
document.object1.left += x;
document.object1.visibility = "show"}};
function makeStatic() {
if (document.all) {object1.style.pixelTop=document.body.scrollTop+20}
else {eval(document.object1.top=eval(window.pageYOffset+20));}
setTimeout("makeStatic()",0);}
</script>
<style>
<!--
.hl {
Background-Color : yellow;
Cursor:hand;
}
.n {
Cursor:hand;
}
-->
</style>
// *****************************************************************
// ADIM 2 <BODY> Bölümleri arasına eklenecek olan bölüm
// *****************************************************************
<LAYER visibility="hide" top="20" name="object1" bgcolor="black" left="0" onmouseover="move(132)" onmouseout="move(-132)">
<script language="JavaScript1.2">
function positionmenu(){
move(-132)
}
if (document.all) {document.write('<DIV ID="object1" style="visibility:hidden;cursor:hand; Position : Absolute ;Left : 0px ;Top : 20px ;Z-Index : 20" onmouseover="move(132)" onmouseout="move(-132)">')}
</script>
<table border="0" cellpadding="0" cellspacing="1" width="150" bgcolor="#000000">
<tr><td bgcolor="#0099FF"> <font size="4" face="Arial"><b>Menu</b></font></td>
<script language="JavaScript1.2">
document.write('<td align="center" rowspan="100" width="16" bgcolor="#FF6666"><span style="font-size:13px"><p align="center"><font face="Arial Black">G<br>İ<br>Z<br>L<br>İ<br>M<br>E<br>N<BR>U</font></p></span></TD>')
</script>
</tr>
<script language="JavaScript1.2">
<!--
if (document.all||document.layers) {
makeStatic();}
var text=new Array();
var thelink=new Array();
// Linklerinizi ve başlıklarınızı bu bölümde ayarlıyorsunuz.
text[0]="Yeni ipucu siteniz";
text[1]="ASP ipuçları";
text[2]="PHP ipuçları";
text[3]="Javascript ipuçları";
text[4]="Forumlar";
thelink[0]="http://www.ipucu.web.tr";
thelink[1]="http://www.ipucu.web.tr/aspipucu.php";
thelink[2]="http://www.ipucu.web.tr/phpipucu.php";
thelink[3]="http://www.ipucu.web.tr/jsipucu.php";
thelink[4]="http://www.ipucu.web.tr/forum/";
var linktarget=''
/// BU bölümde değişiklik yapmayınız.
function navigateie(which){
if (linktarget=='')
window.location=thelink[which]
else if (linktarget=='new')
window.open(thelink[which])
else{
temp_var=eval("window.parent."+linktarget)
temp_var.location=thelink[which]
}
}
for (i=0;i<=text.length-1;i++)
if (document.all) {
document.write('<TR><TD height=20 bgcolor=white onclick="navigateie('+i+')" onmouseover="className=\'hl\'" onmouseout="className=\'n\'"><FONT SIZE=2 FACE=ARIAL> '+text[i]+'</FONT></TD></TR>')}
else {
document.write('<TR><TD bgcolor="white"><ILAYER><LAYER HEIGHT="18" onmouseover="this.bgColor=\'yellow\'" onmouseout="this.bgColor=\'white\'" width=131><FONT SIZE=2 FACE=ARIAL> <A HREF="'+thelink[i]+'" target="'+linktarget+'" id="nounderline">'+text[i]+'</A></FONT></LAYER></ILAYER></TD></TR>')}
//-->
</script>
<tr>
<td bgcolor="#0099FF"><font size="1" face="Arial"> </font></td>
</TR>
</table>
<script language="JavaScript1.2">
if (document.all) {document.write('</DIV>')}
window.onload=positionmenu
</script>
</LAYER>
// ADIM 1 <HEAD> Bölümleri arasına eklenecek olan bölüm
// *****************************************************************
<script language="JavaScript1.2">
function move(x) {
if (document.all) {
object1.style.pixelLeft += x;
object1.style.visibility = "visible"}
else if (document.layers) {
document.object1.left += x;
document.object1.visibility = "show"}};
function makeStatic() {
if (document.all) {object1.style.pixelTop=document.body.scrollTop+20}
else {eval(document.object1.top=eval(window.pageYOffset+20));}
setTimeout("makeStatic()",0);}
</script>
<style>
<!--
.hl {
Background-Color : yellow;
Cursor:hand;
}
.n {
Cursor:hand;
}
-->
</style>
// *****************************************************************
// ADIM 2 <BODY> Bölümleri arasına eklenecek olan bölüm
// *****************************************************************
<LAYER visibility="hide" top="20" name="object1" bgcolor="black" left="0" onmouseover="move(132)" onmouseout="move(-132)">
<script language="JavaScript1.2">
function positionmenu(){
move(-132)
}
if (document.all) {document.write('<DIV ID="object1" style="visibility:hidden;cursor:hand; Position : Absolute ;Left : 0px ;Top : 20px ;Z-Index : 20" onmouseover="move(132)" onmouseout="move(-132)">')}
</script>
<table border="0" cellpadding="0" cellspacing="1" width="150" bgcolor="#000000">
<tr><td bgcolor="#0099FF"> <font size="4" face="Arial"><b>Menu</b></font></td>
<script language="JavaScript1.2">
document.write('<td align="center" rowspan="100" width="16" bgcolor="#FF6666"><span style="font-size:13px"><p align="center"><font face="Arial Black">G<br>İ<br>Z<br>L<br>İ<br>M<br>E<br>N<BR>U</font></p></span></TD>')
</script>
</tr>
<script language="JavaScript1.2">
<!--
if (document.all||document.layers) {
makeStatic();}
var text=new Array();
var thelink=new Array();
// Linklerinizi ve başlıklarınızı bu bölümde ayarlıyorsunuz.
text[0]="Yeni ipucu siteniz";
text[1]="ASP ipuçları";
text[2]="PHP ipuçları";
text[3]="Javascript ipuçları";
text[4]="Forumlar";
thelink[0]="http://www.ipucu.web.tr";
thelink[1]="http://www.ipucu.web.tr/aspipucu.php";
thelink[2]="http://www.ipucu.web.tr/phpipucu.php";
thelink[3]="http://www.ipucu.web.tr/jsipucu.php";
thelink[4]="http://www.ipucu.web.tr/forum/";
var linktarget=''
/// BU bölümde değişiklik yapmayınız.
function navigateie(which){
if (linktarget=='')
window.location=thelink[which]
else if (linktarget=='new')
window.open(thelink[which])
else{
temp_var=eval("window.parent."+linktarget)
temp_var.location=thelink[which]
}
}
for (i=0;i<=text.length-1;i++)
if (document.all) {
document.write('<TR><TD height=20 bgcolor=white onclick="navigateie('+i+')" onmouseover="className=\'hl\'" onmouseout="className=\'n\'"><FONT SIZE=2 FACE=ARIAL> '+text[i]+'</FONT></TD></TR>')}
else {
document.write('<TR><TD bgcolor="white"><ILAYER><LAYER HEIGHT="18" onmouseover="this.bgColor=\'yellow\'" onmouseout="this.bgColor=\'white\'" width=131><FONT SIZE=2 FACE=ARIAL> <A HREF="'+thelink[i]+'" target="'+linktarget+'" id="nounderline">'+text[i]+'</A></FONT></LAYER></ILAYER></TD></TR>')}
//-->
</script>
<tr>
<td bgcolor="#0099FF"><font size="1" face="Arial"> </font></td>
</TR>
</table>
<script language="JavaScript1.2">
if (document.all) {document.write('</DIV>')}
window.onload=positionmenu
</script>
</LAYER>
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>