Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

14 Nisan 2010 Çarşamba

Kodla javascript breakpoint oluşturmak


C#

#if DEBUG
System.Diagnostics.Debugger.Break();
#endif


JavaScript

function MyCustomValidator(ctl, args)
{
debugger
var grid = igtbl_getGridById("MyGrid");
args.IsValid = grid != null;
}

9 Nisan 2010 Cuma

VS.NET içinde collapse yapan macro

Visual Studio 2008 de herhangi bir dosyanızı (değiştirdiğim için hepsinde deneyemedim ama, hepsini diyelim şimdilik) "//_" karakterleri ile başlayıp "//- " karakterleri ile biten yere kadar katlamaya (collapse için attım bu kelimeyi) yarayan macro aşağıdadır.

Emeği geçen herkese şimdiden teşekkür ederim.

Referans: stackOverFlow.com

Option Explicit On
Option Strict On

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Collections.Generic

Public Module JsMacros


Sub OutlineRegions()
Dim selection As EnvDTE.TextSelection = CType(DTE.ActiveDocument.Selection, EnvDTE.TextSelection)

'//_ işaretini gördüğü yerden
Const REGION_START As String = "//_ "
'//- işaretine kadar
Const REGION_END As String = "//- "
' xxx karakterSonra başlayarak collapse edecek.
Const karakterSonra As Integer = 20

selection.SelectAll()
Dim text As String = selection.Text
selection.StartOfDocument(True)

Dim startIndex As Integer
Dim endIndex As Integer
Dim lastIndex As Integer = 0
Dim startRegions As New Stack(Of Integer)

Do
startIndex = text.IndexOf(REGION_START, lastIndex)
endIndex = text.IndexOf(REGION_END, lastIndex)

If startIndex = -1 AndAlso endIndex = -1 Then
Exit Do
End If

If startIndex <> -1 AndAlso startIndex < endIndex Then
startRegions.Push(startIndex + karakterSonra)
lastIndex = startIndex + 1
Else
' Outline region ...
Dim tempStartIndex As Integer = CInt(startRegions.Pop())
selection.MoveToLineAndOffset(CalcLineNumber(text, tempStartIndex), CalcLineOffset(text, tempStartIndex))
selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
selection.OutlineSection()

lastIndex = endIndex + 1
End If
Loop

selection.StartOfDocument()
End Sub

Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer) As Integer
Dim lineNumber As Integer = 1
Dim i As Integer = 0

While i < index
If text.Chars(i) = vbLf Then
lineNumber += 1
i += 1
End If

If text.Chars(i) = vbCr Then
lineNumber += 1
i += 1
If text.Chars(i) = vbLf Then
i += 1 'Swallow the next vbLf
End If
End If

i += 1
End While

Return lineNumber
End Function

Private Function CalcLineOffset(ByVal text As String, ByVal index As Integer) As Integer
Dim offset As Integer = 1
Dim i As Integer = index - 1

'Count backwards from //#region to the previous line counting the white spaces
Dim whiteSpaces = 1
While i >= 0
Dim chr As Char = text.Chars(i)
If chr = vbCr Or chr = vbLf Then
whiteSpaces = offset
Exit While
End If
i -= 1
offset += 1
End While

'Count forwards from //#region to the end of the region line
i = index
offset = 0
Do
Dim chr As Char = text.Chars(i)
If chr = vbCr Or chr = vbLf Then
Return whiteSpaces + offset
End If
offset += 1
i += 1
Loop

Return whiteSpaces
End Function

End Module

7 Nisan 2010 Çarşamba

Javascript ile class tanımı ve metottan fonksiyona parametre geçirerek çağırma

Sınıf tanımı ve public, private ayrımları


Nesne üzerinden yeni property eklemek








Bu da benden bir örnek:
<script type="text/javascript">
function Ogrenci(adi, soyadi, numarasi) {
this.Adi = adi;
this.Soyadi = soyadi;
this.Numarasi = numarasi;
}

Ogrenci.prototype.f_Ekle = function
(f_Basarili, prmB, f_Hatali, prmH) 
{
alert(this.Adi);

//f_Basarili != undefined
//   aynıdır
//f_Basarili != null
if (f_Basarili != undefined) {
f_Basarili.call(this, "Basarilidan =>" + prmB);
}

if (f_Hatali != null) {
f_Hatali.call(this, "Hatalidan =>" + prmH);
}
}


function Basarili(prmBasarili) {
alert("Fonk. Başarılı: " + prmBasarili);
}

function Hatali(prmHatali) {
alert("Fonk. Hatalı: " + prmHatali);
}

var ogr = new Ogrenci("Cem", "Topkaya", 123);

// Her iki metoduda çağırmak istesek
ogr.f_Ekle(Basarili, " _Başarılıya_", Hatali, " _Hatalıya_");

ogr.f_Ekle(null, undefined, Hatali, " _Hatalıya_");

// Hataliyi cagirmadan metodu tetikleyelim.
ogr.f_Ekle(Basarili, " _Başariliya_"); 
</script>



Bu da ajax eventleri ile ilgili özet örneğim:
<script type="text/javascript">
$(document).bind("ajaxSend", function() {
// global event bind edilir 
// local before'dan sonra çalışacak
alert("ajax send bind edilmiş");
}).bind("beforeSend", function() {
//alert Çalışmayacak
alert("local event global gibi bind edilemez");
}).bind("ajaxSuccess", function() {
// global event bind edilir [çalışacak]
alert("ajaxSuccess binde edilmiş");
}).bind("ajaxComplete", function() {
// global event bind edilir [çalışacak]
alert("complete binde edilmiş");
});

// Ajax send olduğunda ve complete olduğunda 
// otomatik çalışsın diye güzel bir örnek.
// Ama global event lerde böyle bir bağlamanın
// olabileceğinin altını bir kez daha çizelim.
$("#loading").bind("ajaxSend", function(){
$(this).show();
}).bind("ajaxComplete", function(){
$(this).hide();
});


function TabloEkleri(
_tabloEkId,
_refEkId,
_refTabloPKId, _refTabloId,
_ekMetni, _anaResim, _sirasi) {

this.TabloEkId = _tabloEkId;
this.RefEkId = _refEkId;
this.RefTabloPKId = _refTabloPKId;
this.RefTabloId = _refTabloId;
this.EkMetni = _ekMetni;
this.AnaResim = _anaResim;
this.Sirasi = _sirasi;
}

TabloEkleri.prototype.f_Ekle = function(fBefore, fSuccess, fComplete, fError) {
// $.ajaxSetup metodu ile $.ajax içinde 
// eventleri bağlamamız gerekmez.
$.ajaxSetup({
beforeSend: fBefore,
complete: fComplete,
success: fSuccess,
error: fError
});
// Ya da $.ajaxSetup metodunu bir fonk. içine alarak
// fAjaxSetup(fBefore, fSuccess, fError, fComplete);
// şeklinde çağırabiliriz. Böylece aşağıdaki
// event bağlamalarına gerek kalmadığı gibi
//
// $.ajax({
//        type: "get",
//        contentType: "application/json; charset=utf-8",
//        url: "hihi.txt",
//        data: "{}",
//        dataType: "json",
// });
//
// şeklinde bir ajax metot çağrısı yapılabilir.
//
// Ama biz aşağıdaki gibi iki yöntemlede (yorum satırı 
// yapılmışlar ve açık satırlar olarak) ajax çağrısını
// görelim.

$.ajax({
type: "get",
contentType: "application/json; charset=utf-8",
url: "hihi.txt",
data: "{}",
dataType: "json",
//              beforeSend: function() {
//                    if (fBefore != undefined) {
//                        fBefore.call();
//                    }
//              },
beforeSend: fBefore,
//              success: function(data, textStatus, XMLHttpRequest) {

//                    if (fSuccess != undefined) {
//                        fSuccess.call(this, data);
//                    }
//                    /**
//                    if (data.d.Sonuc) {
//                    $.fn.colorbox({ html: data.d.Basarili });
//                    return;
//                    } else {
//                    $.fn.colorbox({ html: data.d.Hatali });
//                    }
//                    */
//              },
success: fSuccess,
//                error: function(XMLHttpRequest, textStatus, errorThrown) {
//                    //f_AjaxError(XMLHttpRequest, textStatus, errorThrown);

//                    if (fError != undefined) {
//                        fError.call(this, XMLHttpRequest, textStatus, errorThrown);
//                    }
//                    return;
//                },
error: fError,
//              complete: function(data) {
//                  if (fComplete != undefined) {
//                      fComplete.call(this, data),
//                  }
//              }
complete: fComplete
});
}        
</script>

<script type="text/javascript">
var tbl = new TabloEkleri(1, 2, 3, 4, "metin", 1, 666);

function before() {
alert("beforeeee");
}

function success(data, textStatus, XMLHttpRequest) {
alert("successsss: " + data);
}

function complete(data) {
alert("completeeeee");
}

tbl.f_Ekle(null, success, complete, null);
</script>



Ref:stackoverflow.com

Actually, your code will pretty much work as is, just declare your callback as an argument and you can call it directly using the argument name.
The basics

function doSomething(callback) {
// ...

// Call the callback
callback('stuff', 'goes', 'here');
}

function foo(a, b, c) {
// I'm the callback
alert(a + " " + b + " " + c);
}

doSomething(foo);

That will call doSomething, which will call foo, which will alert "stuff goes here".

Note that it's very important to pass the function reference (foo), rather than calling the function and passing its result (foo()). In your question, you do it properly, but it's just worth pointing out because it's a common error.
More advanced stuff

Sometimes you want to call the callback in a specific context -- e.g., so the this value inside the callback has a specific value. You can easily do that with the JavaScript call function:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.call(this);
}

function foo() {
alert(this.name);
}

var t = new Thing('Joe');
t.doSomething();  // Alerts "Joe" via `foo`

You can also pass parameters:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback, salutation) {
// Call our callback, but using our own instance as the context
callback.call(this, salutation);
}

function foo(salutation) {
alert(salutation + " " + this.name);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe" via `foo`

Sometimes it's useful to pass the arguments you want to give the callback as an array, rather than individually. You can use apply to do that:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.apply(this, ['Hi', 3, 2, 1]);
}

function foo(salutation, three, two, one) {
alert(salutation + " " + this.name + " - " + three + " " + two + " " + one);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe - 3 2 1" via `foo`




3 Nisan 2010 Cumartesi

break ve continue farkı


int[] arr = new[] {1,2,3,4,5,6};

foreach (int j in arr)
{
foreach (int i in arr)
{
if (i == 3)
{
// i for unu kırıp j forundan devam eder.
break;
}
}
}


foreach (int j in arr)
{
foreach (int i in arr)
{
if (i == 3)
{
// if içini işlemeden i forunun bir
// sonraki elemanından devam eder
continue;
}
}
}