분류 전체보기
-
[PowerShell 예제] ps1 에서 다른 ps1 파일 참조하기Shell & CMD/PowerShell 2022. 12. 20. 21:32
파워셀 스크립트(.ps1) 파일은 다른 스크립트 파일을 참조할 수 있다. 아래와 같이 각각 env.ps1 과 deploy.ps1 파일을 생성한 뒤 deploy.ps1을 실행해보자 env.ps1 파일 $dev = "is dev env"; $prod = "is prod env"; function Get-Environment([bool]$isDebug = $true) { if ($isDebug) { return $dev; } else { return $prod; } } env.ps1 파일 . .\env.ps1 # 파일의 경로 Get-Environment($true) | Write-Host 실행결과 > .\deploy.ps1 is dev env
-
[PowerShell Tips] .ps1 또는 함수실행시 정해진 파라메터만 받을 수 있도록 처리하는 ValidateSet 속성Shell & CMD/PowerShell 2022. 12. 19. 20:34
소개 ps1 파일을 통한 스크립트 실행 혹은 함수 실행시 특정 파라메터만 받아 처리할 수 있도록 셋을 정의하고 싶을 때가 존재한다. 그럴 땐 정의된 파라메터에 ValidateSet 을 붙이도록 하자 아래 예제는 스크립트 실행시 아래 동작 [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [ValidateSet('Development','QA','Staging', 'Production')] [string]$Environment ) Write-Host $Environment 파라메터 $Environmnet 를 받아 작업을 처리하는 ps1 파일 실행시, 필수로 'Development','QA','Staging', 'Produ..
-
[Svelte] 스벨트에서의 event capture와 bubblingJavascript & TypeScript 2022. 12. 17. 13:26
아래코드는 버튼 click 시 stopPropagation에 의해 button 이벤트만 실행된다. handleClick('div')}> handleClick('button')}> Click me 버튼을 눌렀을 때, 버튼 event 가 아닌, div의 click 이벤트가 동작하게 처리하려면 아래와 같이 수정해야 한다. handleClick('div')}> handleClick('button')}> Click me 링크 Events / Event modifiers • Svelte Tutorial developer.mozilla.org / 이벤트 버블링과 캡쳐
-
[zsh] zsh에 oh my posh 설치하기 (oh my zsh 아님)ETC 2022. 8. 13. 18:14
oh-my-posh는 powershell을 예쁘게 꾸며주는 도구로 잘 알려져 있지만, 사실 mac에서 사용하는 zsh 에서도 사용 가능하다. 아래 스크립트를 .zprofile 파일에 추가하면 쉽게 적용할 수 있다. 사전에 oh-my-posh가 설치되어 있어야 한다. (brew를 이용한 설치 방법 : https://formulae.brew.sh/formula/oh-my-posh) export POSH_THEME={테마 파일 경로} export POWERLINE_COMMAND="oh-my-posh" export CONDA_PROMPT_MODIFIER=false # set secondary prompt PS2="$(/opt/homebrew/bin/oh-my-posh print secondary --config..
-
[EFCore] EF Core Tool 로 C# 모델 클래스 -> DB 마이그레이션 하기.NET/개념 및 유용한 팁 2022. 8. 7. 20:38
닷넷 EF Core 툴 사용에 대한 설명 요약 목적으로 작성. 전역 도구 설치 dotnet tool install --global dotnet-ef DB 생성할 모델 및 Context 가 선언된 프로젝트에 Microsoft.EntityFrameworkCore.Design 설치 dotnet add package Microsoft.EntityFrameworkCore.Design 코드에서 DB로 마이그레이션하기. DBContext 및 모델 소스코드는 생성해야 한다. 첫 생성시엔 아래 명령어를 실행한다. dotnet ef database update 모델의 변경이나 Context 설정상 변경 발생 후 DB에 반영하려면 먼저 migrations 명령어로 변경사항을 생성해야 한다. 아래 예시는 개인적으로 개발중인 ..
-
[PowerShell 예제] 파일을 줄 단위로 나눠 저장하는 스크립트 예시Shell & CMD/PowerShell 2022. 8. 6. 18:01
파일을 10만줄 단위로 나눠 출력하는 파워셸 스크립트 예시이다. Get-Content error.csv -ReadCount 100000 | %{$i++; $_ | Out-File err_$i.csv} 출처 : How can I split a text file using PowerShell? - Stack Overflow How can I split a text file using PowerShell? I need to split a large (500 MB) text file (a log4net exception file) into manageable chunks like 100 5 MB files would be fine. I would think this should be a walk in the p..
-
[.NET] IServiceCollection기반 서비스에 args 값 의존성 주입(DI) 간단히 처리하기.NET/개념 및 유용한 팁 2022. 8. 3. 22:03
간혹 콘솔프로그램의 args를 IServiceCollection 및 Builder로 구성된 ASP.NET Core 및 Worker 에 그대로 의존성 주입하고 싶을때가 있다. 방법은 간단한다. AddSingleton(args); 한줄이면 끝난다. 아래코드는 .NET 6기반의 ASP.NET Core WebApi 프로젝트이다. [Program.cs] var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuc..
-
[PowerShell 예제] Start-ThreadJob을 이용한 동시 처리 스크립트 구현Shell & CMD/PowerShell 2022. 7. 30. 20:39
지난 시간에 where, foreach 를 이용하여 특정 폴더내에서 txt 파일을 EUC-KR로 읽어 UTF-8로 변환했었다. 주소 기반 데이터 정제작업에서 유용하긴 하지만 압축을 해제 한 후, 해당 폴더에 스크립트파일을 담은 뒤 실행해야 하는 선행 작업이 필요하기 때문에 자동화 작업이라 보긴 어려웠다. 그래서 스크립트를 아래와 같이 수정했다. # Parameter help description # Specifies a path to one or more locations. [CmdletBinding()] param ( [string[]] $zipfiles ) Write-Host "Convert Start :" ([DateTime]::Now).ToString("yyyy-MM-dd hh:mm:ss") $p..