The document contains 7 code samples from different programming domains:
1. Data modeling and user interface design
2. SQL stored procedure
3. C# regular expressions
4. C# error logging to file
5. C#/ADO.NET method to retrieve a library member
6. XML web configuration file
7. ASP.NET web form with controls and validation
The samples provide snippets of code related to various programming tasks like data access, validation, error handling, and user interfaces.
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
This talk takes a deep dive into asynchronous programming patterns and practices, with an emphasis on the promise pattern.
We go through the basics of the event loop, highlighting the drawbacks of asynchronous programming in a naive callback style. Fortunately, we can use the magic of promises to escape from callback hell with a powerful and unified interface for async APIs. Finally, we take a quick look at the possibilities for using coroutines both in current and future (ECMAScript Harmony) JavaScript.
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
This talk takes a deep dive into asynchronous programming patterns and practices, with an emphasis on the promise pattern.
We go through the basics of the event loop, highlighting the drawbacks of asynchronous programming in a naive callback style. Fortunately, we can use the magic of promises to escape from callback hell with a powerful and unified interface for async APIs. Finally, we take a quick look at the possibilities for using coroutines both in current and future (ECMAScript Harmony) JavaScript.
Xlab #1: Advantages of functional programming in Java 8XSolve
Presentation from xlab workshop about functional programming components introduced to the Java 8. How to operate the streams and lambdas in theory and practice.
자프링(자바 + 스프링) 외길 12년차 서버 개발자가 코프링(코틀린 + 스프링)을 만난 후 코틀린의 특징과 스프링의 코틀린 지원을 알아가며 코프링 월드에서 살아남은 이야기…
코드 저장소: https://github.com/arawn/kotlin-support-in-spring
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
While Singletons have become a Pattern-Non-Grata over the years, you still find it surprisingly often in PHP applications and frameworks. This talk will explain what the Singleton pattern is, how it works in PHP and why you should avoid it in your application.
Implementing CQRS and Event Sourcing with RavenDBOren Eini
CQRS stands for Command Query Responsibility Segregation. That is, that command stack and query stack are designed separately. This leads to a dramatic simplification of design and potential enhancement of scalability.
Events are a new trend in software industry. In real-world, we perform actions and these actions generate a reaction. Event Sourcing is about persisting events and rebuilding the state of the aggregates from recorded events.
In this talk I will share a lot of examples about how to effective implementing CQRS and Event Sourcing with RavenDB
PHP 5.3 and Lithium: the most rad php frameworkG Woo
Presentation given to the Orange County PHP meetup on Feb 24 2010. The presentation covers the new features in php 5.3 and goes on to show how they are used in Lithium, the most rad php framework.
Xlab #1: Advantages of functional programming in Java 8XSolve
Presentation from xlab workshop about functional programming components introduced to the Java 8. How to operate the streams and lambdas in theory and practice.
자프링(자바 + 스프링) 외길 12년차 서버 개발자가 코프링(코틀린 + 스프링)을 만난 후 코틀린의 특징과 스프링의 코틀린 지원을 알아가며 코프링 월드에서 살아남은 이야기…
코드 저장소: https://github.com/arawn/kotlin-support-in-spring
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
While Singletons have become a Pattern-Non-Grata over the years, you still find it surprisingly often in PHP applications and frameworks. This talk will explain what the Singleton pattern is, how it works in PHP and why you should avoid it in your application.
Implementing CQRS and Event Sourcing with RavenDBOren Eini
CQRS stands for Command Query Responsibility Segregation. That is, that command stack and query stack are designed separately. This leads to a dramatic simplification of design and potential enhancement of scalability.
Events are a new trend in software industry. In real-world, we perform actions and these actions generate a reaction. Event Sourcing is about persisting events and rebuilding the state of the aggregates from recorded events.
In this talk I will share a lot of examples about how to effective implementing CQRS and Event Sourcing with RavenDB
PHP 5.3 and Lithium: the most rad php frameworkG Woo
Presentation given to the Orange County PHP meetup on Feb 24 2010. The presentation covers the new features in php 5.3 and goes on to show how they are used in Lithium, the most rad php framework.
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
We rarely dive into current programming languages, touting the next new framework or the new features that will be out next year. This is about JavaScript the language as it exists today, what I picked up in going from C# to JS, and what C# picked up from JS along the way as well. It is based on Douglas Crockford's seminal book "JavaScript: The Good Parts".
3. Sample 2 (SQL INSERT Stored Procedure):
GO
/****** Object: StoredProcedure [dbo].[GetMemberByItem] Script Date:
01/22/2008 14:33:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Nii Amah Hesse>
-- Create date: <Create Date,,12/20/2007>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetMemberByItem]
-- Add the parameters for the stored procedure here
@isbn int
,@copy_no smallint
AS
IF NOT EXISTS
(SELECT * FROM dbo.copy WHERE isbn = @isbn AND copy_no = @copy_no)
BEGIN
RETURN -17 --ItemNotFound
END
IF NOT EXISTS
(SELECT member_no FROM dbo.loan WHERE isbn = @isbn AND copy_no = @copy_no)
BEGIN
RETURN -19 --ItemNotOnLoan
END
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF EXISTS
(SELECT a.member_no FROM dbo.adult AS a
INNER JOIN dbo.loan AS l
ON a.member_no = l.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no)
BEGIN
SELECT
m.member_no
,m.lastname
,m.firstname
,m.middleinitial
,a.street
,a.city
,a.state
,a.zip
,a.phone_no
,a.expr_date
FROM dbo.member AS m
INNER JOIN dbo.adult AS a
ON m.member_no = a.member_no
INNER JOIN dbo.loan AS l
ON m.member_no = l.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no
END
ELSE
4. SELECT
m.member_no
,m.lastname
,m.firstname
,m.middleinitial
,a.street
,a.city
,a.state
,a.zip
,a.phone_no
,a.expr_date
,j.adult_member_no
,j.birth_date
FROM dbo.juvenile AS j
INNER JOIN dbo.adult AS a
ON j.adult_member_no = a.member_no
INNER JOIN dbo.member AS m
ON m.member_no = j.member_no
INNER JOIN dbo.loan AS l
ON l.member_no = j.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no
IF @@error <> 0
BEGIN
RETURN -18 --NoSuchMember
END
END
Sample 3 (C# Regular Expressions):
private void ZipCodeTextBox_Validating(object sender, CancelEventArgs e)
{Regex zipExp = new Regex(@"^d{5}$");
if (!zipExp.IsMatch(((Control)sender).Text))
{Regex zipExp2 = new Regex(@"^d{5}(-d{4})$");
if (!zipExp2.IsMatch(((Control)sender).Text))
{errorProvider1.SetError(ZipCodeTextBox, "ZipCode format: ##### or #####-####");
e.Cancel = true;}}}
Sample 4 (C# Error File Logging):
private void PrintError(string myErrorMessage, SystemException se)
{
string mydatetime = "Date" + DateTime.Today.Year.ToString();
mydatetime = mydatetime + "_" + DateTime.Today.Month.ToString();
mydatetime = mydatetime + "_" + DateTime.Today.Day.ToString();
mydatetime = mydatetime + "Time" + DateTime.Now.Hour.ToString();
mydatetime = mydatetime + "_" + DateTime.Now.Minute.ToString();
mydatetime = mydatetime + "_" + DateTime.Now.Second.ToString();
string myfile = @"C:error_" + mydatetime + ".txt";
StreamWriter sw = File.CreateText(myfile);
sw.WriteLine("Error Date: " + DateTime.Today.ToShortDateString());
sw.WriteLine("Error Time: " + DateTime.Now.ToLongTimeString());
sw.WriteLine("Custom Message: " + myErrorMessage);
sw.WriteLine("Message: " + se.Message);
sw.WriteLine("Source: " + se.Source);
sw.Close();
}
Sample 5 (C#/ADO.NET: Get Member Method):
#region GetMember Method
6. elder.ExpirationDate = (DateTime)libReader["expr_date"];
elder.FirstName = libReader["firstname"].ToString();
elder.LastName = libReader["lastname"].ToString();
elder.MemberID = (short)libReader["member_no"];
elder.MiddleInitial =
libReader["middleinitial"].ToString();
elder.PhoneNumber = libReader["phone_no"].ToString();
elder.State = libReader["state"].ToString();
elder.Street = libReader["street"].ToString();
elder.ZipCode = libReader["zip"].ToString();
}
}
if (Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value) !
= 0)
{
LibraryException ex = new LibraryException();
ex =
ex.ErrCodeGenerator(Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value));
if (ex.OtherMemberID > 0)
{
throw new LibraryException(ex.LibraryErrorCode,
ex.OtherMemberID);
}
else
{
throw new LibraryException(ex.LibraryErrorCode);
}
}
if (adult == true)
{
return elder;
}
else
{
return youth;
}
}
catch (LibraryException ex)
{
if (ex.OtherMemberID > 0)
{
throw new LibraryException(ex.LibraryErrorCode,
ex.OtherMemberID);
}
else
{
throw new LibraryException(ex.LibraryErrorCode);
}
}
finally
{
//Close Connection
if (!libReader.IsClosed)
{
libReader.Close();
}
if (libCon.State != ConnectionState.Closed)
{
libCon.Close();
}
}
}
7. #endregion
Sample 6 (Web Service Web Config (XML)):
<?xml version="1.0" encoding="utf-8"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
WindowsMicrosoft.NetFrameworkv2.xConfig
-->
<configuration>
<configSections>
<section name="microsoft.web.services3"
type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</configSections>
<appSettings />
<connectionStrings>
<add name="library" connectionString="Data Source=localhost;Initial
Catalog=library;Integrated Security=True" />
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="Microsoft.Web.Services3, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
-->
<customErrors mode="On" />
<webServices>
<soapExtensionImporterTypes>
<add type="Microsoft.Web.Services3.Description.WseExtensionImporter,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,