Skip to content

Instantly share code, notes, and snippets.

@lisysolution
lisysolution / cs6-null-conditional.cs
Last active August 29, 2015 14:26
C# 6.0 새기능 - Null 조건 연산자
/*
출처 : http://www.csharpstudy.com//CS6/CSharp-null-conditional-operator.aspx
*/
// rows가 NULL이면 cnt 도 NULL
// rows가 NULL이 아니면 cnt는 실제 rows 갯수
int? cnt = rows?.Count;
// customers 컬렉션이 NULL이면 c는 NULL
// 아니면, c는 첫번째 배열요소
@lisysolution
lisysolution / cs6-string-interpolation.cs
Created August 2, 2015 13:51
C# 6.0 새기능 - 문자열 내에 코드 서식 직접 삽입 가능
Rectangle r = new Rectangle();
r.Height = 10;
r.Width = 32;
// Format string 앞에 $ 를 붙인다
// {} 안에 속성 혹은 계산식 등을 넣을 수 있다.
string s = $"{r.Height} x {r.Width} = {(r.Height * r.Width)}";
Console.WriteLine(s);
@lisysolution
lisysolution / ps-basic.ps1
Last active January 30, 2023 14:23
파워쉘 - 기본 코드
# =====================================
# 초기 스크립트 실행 허용으로 설정하는 방법
# =====================================
Set-ExecutionPolicy RemoteSigned -Force
# =====================================
# 파라미터 지정 방법
# =====================================
# 소스의 최상단에 있어야 함
param (
@lisysolution
lisysolution / ps-automatic-variables.ps1
Created August 18, 2015 15:19
파워쉘 - 자동 할당 변수
# 마지막 결과값 문자열
$$
@lisysolution
lisysolution / ps-server-management.ps1
Last active August 29, 2015 14:27
파워쉘 - Server 관리
# ===================================
# Host명 변경
# ===================================
$old_hostname = hostname
$new_hostname = "새로운 Host명"
netdom renamecomputer $old_hostname /newname:$new_hostname /force
# ===================================
# 터미널 접속 포트 방화벽에 추가
# ===================================
@lisysolution
lisysolution / ps-http-getpost.ps1
Created August 19, 2015 14:20
파워쉘 - HTTP POST/GET
# POST 방식 전송
$postParams = @{
name1=val1;
name2=val2;
}
Invoke-WebRequest -Uri http://api.service.com/call.aspx -Method POST -Body $postParams
@lisysolution
lisysolution / ps-sqlserver-management.ps1
Created August 25, 2015 00:05
파워쉘 - SQL Server 관리
# =====================================
# SQL Server를 제어하기 위한 어셈블리 로드
# =====================================
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
# =====================================
# SQL Server 버전
# =====================================
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" "."
@lisysolution
lisysolution / ps-iis-management.ps1
Created August 26, 2015 13:23
파워쉘 - IIS 관리
# ==========================
# IIS 사이트 일괄 삭제
# ==========================
Import-Module webadministration
foreach ($i in get-childitem IIS:\Sites\ -Name) {remove-item ("IIS:Sites\"+$i) -R}
@lisysolution
lisysolution / cs-thread-start-abort.cs
Last active April 19, 2016 14:44
C# Thread / ThreadPool 시작 후 이벤트를 받아서 종료하는 예제
public Program()
{
// Thread의 처리 완료 이벤트를 받기 위한 클래스
ManualResetEvent doneEvent = new ManualResetEvent(false);
// Thread를 정의하고 시작 한다.
Thread t1 = new Thread(new ThreadStart(new ThreadExam(doneEvent).ThreadMethod));
// Thread 시작
t1.Start();
@lisysolution
lisysolution / cs-socket-beginconnect.cs
Last active April 19, 2016 14:51
C# 비동기 소켓 연결 대기하는 방법 - 1개의 연결만 사용 하도록
while (true)
{
Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult result = _socket.BeginConnect(host, port, (ar) =>
{
}, null);
// 연결이 될때 까지 timeout 시간 동안 대기 한다.
result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeout), false);