Skip to content

Instantly share code, notes, and snippets.

@azcoov
azcoov / ObjectToXElement.cs
Created November 29, 2011 22:34
ObjectToXElement
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
public static class GenericExtensions
{
public static XElement ToXElement<T>(this T obj)
{
@azcoov
azcoov / gist:1148589
Created August 16, 2011 07:11
U.S. Postal Code Validation
private Boolean IsValidUSZip(String number)
{
String pattern = @"^(\d{5}-\d{4}|\d{5}|\d{9})$";
var match = new Regex(pattern);
return match.IsMatch(number);
}
@azcoov
azcoov / batchdelete.sql
Created August 16, 2011 07:08
SQL Simple Batch Delete
declare
@CurCount int, @MaxCount int
set @CurCount = 0
set @MaxCount = 100000
set nocount on;
while 1 = 1
begin
@azcoov
azcoov / ssis_expression.vb
Created August 16, 2011 07:03
Custom File Name Expression for SSIS
"\\\\filepath" +
(DT_WSTR, 4) YEAR( DATEADD("d", -1, getdate()) ) +
( MONTH( DATEADD("d", -1, getdate()) ) < 10 ? "0" : "" ) + (DT_WSTR, 2) MONTH( DATEADD("d", -1, getdate()) ) +
( DAY( DATEADD("d", -1, getdate()) ) < 10?"0":"" ) + (DT_WSTR, 2) DAY( DATEADD("d", -1, getdate()) ) +
".txt"
@azcoov
azcoov / fn_htmlencode.sql
Created August 16, 2011 07:01
SQL HTML Encoding
create function dbo.fn_HtmlEncode (
@Html as varchar ( max )
)
returns varchar ( max )
as
/*
select dbo.fn_HtmlEncode('<This is a T&st #>')
*/
@azcoov
azcoov / sqlmoneytypesclae.sql
Created August 16, 2011 06:57
SQL Money Data Type Scale example
DECLARE
@mon1 MONEY ,
@mon2 MONEY ,
@mon3 MONEY ,
@mon4 MONEY ,
@num1 DECIMAL ( 19 , 4 ),
@num2 DECIMAL ( 19 , 4 ),
@num3 DECIMAL ( 19 , 4 ),
@num4 DECIMAL ( 19 , 4 )
@azcoov
azcoov / MonoTouch.Dialog.JsonExample.cs
Created April 15, 2011 04:31
MonoTouch.Dialog Json parsing example
using System;
using System.Collections.Generic;
using System.IO;
using System.Json;
using System.Net;
using MonoTouch.Dialog;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace MonoTouch.Dialog.JsonExample
@azcoov
azcoov / ReadCSVFileToArray.vb
Created April 13, 2011 21:25
Reading a CSV file with VB
'From http://www.fryan0911.com/2009/05/vbnet-how-to-read-csv-file-into-array.html
Imports System.IO
Private Sub ReadCSVFileToArray()
Dim strfilename As String
Dim num_rows As Long
Dim num_cols As Long
Dim x As Integer
Dim y As Integer
@azcoov
azcoov / monotouch.dialog.easyview.cs
Created April 7, 2011 06:39
Example of creating a UIView with MonoTouch.Dialog
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window.AddSubview (navigationController.View);
demoRoot = CreateRoot(String.Empty, String.Empty);
controller = new DialogViewController (demoRoot) {
Autorotate = true
};
navigationController.PushViewController (controller, true);
window.MakeKeyAndVisible ();
return true;
@azcoov
azcoov / linqtoxml.cs
Created March 23, 2011 03:02
Read a Twitter feed with Linq to XML
public class TwitterSearch
{
private const string urlTemplate = "http://search.twitter.com/search.atom?q={0}";
private static XNamespace atomNS = "http://www.w3.org/2005/Atom";
public static List<Tweet> Query(string query)
{
XDocument xDoc = XDocument.Load(string.Format(urlTemplate, query));
var tweets =