Skip to content

Instantly share code, notes, and snippets.

View swkwon's full-sized avatar

Kwon Sangwook swkwon

  • Korea, Republic of
View GitHub Profile
@swkwon
swkwon / gist:7411069
Last active December 28, 2015 00:09
MySql에서는 connection을 Open한 후 wait_timeout이 만료 될때까지 아무런 request가 없으면 DB Server에서 connection을 끊어버립니다. Application에서는 connection을 사용하기 전에 항상 ping을 날려 상태를 파악한 후 다시 Open해주어야 합니다. 기본 timeout은 28800초 즉, 8시간 입니다.
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
// no job until expired wait_timeout... default timeout is 28800 seconds.
conn.Ping();
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
// Then you can use connection!
@swkwon
swkwon / StringSplit.cs
Last active December 28, 2015 04:39
string split
string test1 = "word1:word2";
string[] test1Result = test1.Split(':');
foreach (string s in test1Result)
{
Console.WriteLine(s);
}
string test2 = "word1<>word2";
string[] test2Result = System.Text.RegularExpressions.Regex.Split(test2, "<>");
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace MyProgram
{
class Program
@swkwon
swkwon / DllSample.cs
Last active December 31, 2015 21:59
Dll sample
using System;
namespace DllLibrary
{
public class MyClass
{
public static int ReturnInputValue(byte[] test)
{
return BitConverter.ToInt32(test, 0);
}
@swkwon
swkwon / servicetest.cs
Created December 23, 2013 07:41
windows service
using System.ServiceProcess;
namespace WindowsService2
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
@swkwon
swkwon / random_unque_key.cs
Last active January 1, 2016 06:58
generate random unique key
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace ConsoleApplication32
{
class Program
{
static HashSet<string> set = new HashSet<string>();
@swkwon
swkwon / sqlserverprogramming.cs
Created December 31, 2013 07:56
SQL Server custom function, custom stored procedure
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
namespace SqlServerProject5
{
public class Class1
{
[SqlFunction]
public static SqlInt32 GetSquare(SqlInt32 param)
@swkwon
swkwon / concat1.cs
Created January 6, 2014 07:59
string concatenation
static void Main()
{
string text = "In formal language theory and computer programming, " +
"string concatenation is the operation of joining two character strings end-to-end. " +
"For example, the concatenation of 'snow' and 'ball' is 'snowball'. " +
"In some but not all formalizations of concatenation theory, " +
"also called string theory, string concatenation is a primitive notion.";
Console.WriteLine(text);
}
@swkwon
swkwon / concat2.cs
Created January 6, 2014 08:07
concat2
static void Main(string[] args)
{
// To run this program, provide a command line string.
// In Visual Studio, see Project > Properties > Debug.
string userName = args[0];
string date = DateTime.Today.ToShortDateString();
// Use the + and += operators for one-time concatenations.
string str = "Hello " + userName + ". Today is " + date + ".";
System.Console.WriteLine(str);
@swkwon
swkwon / concat3.cs
Created January 6, 2014 08:10
concat3
class StringBuilderTest
{
static void Main()
{
string text = null;
// Use StringBuilder for concatenation in tight loops.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < 100; i++)
{