All new code snippets I find/write can now be found here:
http://snipplr.com/users/blackf0rk/
-
The "Ten Commandments", if you will, of .NET development. Definitely not limited to ten, nor groundbreaking by any means, this blog emphasizes simple code that any .NET developer should know; without the fluff and bloated code examples. "Just show me how to..."
Function GetGeoCoords(ByVal inString as String) As String
Dim xmlString As String = GetHTML("http://maps.google.com/maps/geo?output=xml&key=abcdefg&q=" & inString, 1)
Chunks = Regex.Split(xmlString, "coordinates>", RegexOptions.Multiline)
outString = Replace(Chunks(1), ",0</", "")
End Function
Public Function GetHTML(ByVal sURL As String, ByVal e As Integer) As String
Dim oHttpWebRequest As System.Net.HttpWebRequest
Dim sChunk As String
oHttpWebRequest = (System.Net.HttpWebRequest.Create(sURL))
Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
oStream = oHttpWebResponse.GetResponseStream
sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
oStream.Close()
oHttpWebResponse.Close()
If e = 0 Then
Return Server.HtmlEncode(sChunk)
Else
Return Server.HtmlDecode(sChunk)
End If
End Function
Public Function GetGeoCoords(ByVal inString As String) As String
Dim Chunks As String()
Dim outString As String = ""
Chunks = Regex.Split(inString, "&")
For Each s As String In Chunks
If InStr(s, "ll") > 0 Then outString = s
Next
Return Replace(Replace(outString, "sll=", ""), "ll=", "")
End Function
Public Function GetHTML(ByVal sURL As String, ByVal e As Integer) As String
Dim oHttpWebRequest As System.Net.HttpWebRequest
Dim oStream As System.IO.Stream
Dim sChunk As String
oHttpWebRequest = (System.Net.HttpWebRequest.Create(sURL))
Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
oStream = oHttpWebResponse.GetResponseStream
sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
oStream.Close()
oHttpWebResponse.Close()
If e = 0 Then
Return Server.HtmlEncode(sChunk)
Else
Return Server.HtmlDecode(sChunk)
End If
End Function
$file = file_get_contents('http://www.yoururl.com');
Public Function EncryptString(ByVal InSeed As Integer, ByVal InString As String) As String
Dim c1 As Integer
Dim NewEncryptString As String
Dim EncryptSeed As Integer
Dim EncryptChar As String
NewEncryptString = ""
EncryptSeed = InSeed
For c1 = 1 To Len(InString)
EncryptChar = Mid(InString, c1, 1)
EncryptChar = Chr(Asc(EncryptChar) Xor EncryptSeed)
EncryptSeed = EncryptSeed Xor c1
NewEncryptString = NewEncryptString & EncryptChar
Next
EncryptString = NewEncryptString
End Function
For Each appSetting As String In ConfigurationManager.AppSettings.AllKeys
Dim appSettingValue = ConfigurationManager.AppSettings.Get(appSetting)
Next
CREATE TABLE #TempTable(FieldName1 VarChar(50), DateField1 DateTime, FieldName2 Int)Inserting into the temp table is executed like any other table:
INSERT INTO #TempTable () VALUES ()The table is dropped when the session is dropped. Otherwise:
DROP TABLE #TempTable
SELECT CONVERT(varchar, DateField, 101) AS DateField FROM [someTable]
ClientScript.RegisterStartupScript(GetType(Page), "keyname", "<script>//javascript here</script>")
Private Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
End Sub
Dim numRows As Integer = (e.ReturnValue).Tables(0).Rows.Count
Dim pn As String = "(444) 444-444"
Dim newPn As String = Replace(Replace(Replace(pn, "-", ""), "(", ""), ")", "")
newPn = String.Format("{0:###-###-####}", Convert.ToInt64(newPn))
<asp:Panel ID="Panel1" runat="server" DefaultButton="btn_search">
<asp:TextBox ID="txt_search" runat="server" Font-Names="Tahoma" Font-Size="12px"></asp:TextBox>
<asp:Button ID="btn_search" runat="server" Font-Italic="False" Font-Names="Tahoma" Font-Size="12px" Text="Search" />
</asp:Panel>
function fitMap(map, points) {
var bounds = new GLatLngBounds();
for (var i=0; i< points.length; i++) {
bounds.extend(points[i]);
}
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
}
var zoompoints = new Array();
zoompoints = [];
zoompoints[0] = new GLatLng(longitude,latitude);
zoompoints[1] = new GLatLng(longitude,latitude);
fitMap(map, zoompoints);
For Each DataRow As DataRow In ds.Tables(0).Rows
Dim outData as String
outData = DataRow("fieldName").toString
Next
Dim xGD As New Generic.Dictionary(Of String, String)
xGD.Add("key1", "value1")
Dim value as String = xGD("key1")
For Each xKVP As Generic.KeyValuePair(Of String, String) In xGD
Consoe.Writeline(xKVP.Key & ", " & xKVP.Value)
Next
XPathNavigator myField = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:fieldName", NamespaceManager);
string fooBar = fieldName.value
<script language="javascript" type="text/javascript" src="/protectedJavascript.php"></script>
if(!eregi("/originatingPage.html",$_SERVER['HTTP_REFERER'])) {
echo "Message to those snooping here.";
} else {
echo "//JAVASCRIPT CODE HERE";
}
function valNum(inNum {
var RegEx = /[0-9]{1,8}\.?[0-9]{0,2}/;
var ValidNumber = inNum.match(RegEx);
return ValidNumber;
}