나중에 써먹을 일 있을거 같아, 여기에 정리해 둠.
2 PDF에서 일부 페이지만 각각 발췌해서 머지하기
업무상 서명해서 스캔한 PDF와 Office에서 PDF로 변환한 두 PDF 문서를 머지할 일이 잦아
배운적은 없지만 python으로 야매코딩.
macOS의 미리보기에서 필요한 페이지만 드래그해서 머지하는게 가장 깔끔한 방법이지만,
Windows만 있는 환경에서 할 필요도 있어서 만듬
from PyPDF2 import PdfFileWriter, PdfFileReader
def usage():
print("#" * 100)
print('''
[PDFCAT] by alexken@TTA
A.pdf [a~b] + B.pdf [c~d] -> C.pdf
Usage:
$ python {} A.pdf a b B.pdf c d
'''.format(sys.argv[0]))
print("#" * 100)
def merge_pdf(pdf_a, pdf_b):
try:
in_pdf_a = PdfFileReader(pdf_a["name"])
in_pdf_b = PdfFileReader(pdf_b["name"])
out_c = PdfFileWriter()
if pdf_a["from"] == 0:
pdf_a["from"] = 1
if pdf_a["to"] == 0:
pdf_a["to"] = in_pdf_a.getNumPages()
if pdf_b["from"] == 0:
pdf_b["from"] = 1
if pdf_b["to"] == 0:
pdf_b["to"] = in_pdf_b.getNumPages()
for i in range(pdf_a["from"]-1, pdf_a["to"]):
print( "{} page:{}".format(pdf_a["name"], i+1) )
out_c.addPage(in_pdf_a.getPage(i))
print( "+" )
for i in range(pdf_b["from"]-1, pdf_b["to"]):
print( "{} page:{}".format(pdf_b["name"], i+1) )
out_c.addPage(in_pdf_b.getPage(i))
with open("C.pdf", "wb") as outputStream:
out_c.write(outputStream)
except:
print(">>>> Fail to Merge")
if __name__ == "__main__":
if len(sys.argv) == 7:
merge_pdf({"name":sys.argv[1],"from":int(sys.argv[2]),"to":int(sys.argv[3])},
{"name":sys.argv[4],"from":int(sys.argv[5]),"to":int(sys.argv[6])})
else:
usage()
Windows 특정 크기의 더미 파일 생성
CMD 창에서
POST로 JSON 전송후 node.js에서 처리하기
주의사항
1: 서버에 전송할 때 HTTP 헤더에 “Content-Type: application/json” 반드시 설정할 것
2: JSON의 string 표기할때 이스케이프 처리해서라도 쌍따옴표로 사용할 것
3: bodyParser에서 JSON 사용을 명시할 것
var bodyParser = require('body-parser')
var app = express();
var port = process.env.PORT || 8000;
const usage = 'curl "localhost:8000/get?a=3&b=4" or\n' +
'curl -d "{\"a\":3,\"b\":4}" ' +
'-H "Content-Type: application/json" localhost:8000/post';
app.use(bodyParser.json());
app.get('/', function(req, res) {
res.send(usage);
});
app.post('/', function(req, res) {
res.send(usage);
});
app.get('/get', function(req, res) {
res.send('' + (parseInt(req.query.a) + parseInt(req.query.b)));
});
app.post('/post', function(req, res) {
res.send('' + (req.body.a + req.body.b));
});
app.listen(port);
macOS에서 Instruments 성능 측정 결과 csv로 저장하기
macOS에서 XCode에 포함된 Instruments 도구로 macOS 시스템, macOS용 애플리케이션 또는 iOS용 모바일앱의 자원사용률을 측정하면, 과거에는 csv로 내보내기할 수가 있었는데, 언제부터인가(한 1~2년전) 빼버렸는지 찾을 수가 없었다.
하지만 라인단위로 선택해서 붙여넣기는 여전히 가능해서,
“Instruments의 한줄 선택 –> Microsoft Code 텍스트 에디터로 복사”하는
AppleScript를 작성해서 사용하고 있다.
더 멋진 방법이 있는지 모르겠지만 난 이렇게 사용하고 있다. 끝.
Instruments2Code Applescript
-- https://eastmanreference.com/complete-list-of-applescript-key-codes
display dialog "1. Open 'Instruments' and click the 'Active Monitor' area
2. Open the 'Microsoft Code'"
-- 복사할 라인수 입력
set x to the text returned of (display dialog "Enter line # to be copied" default answer "10")
-- 첫번째 줄로 이동 (option + ↑)
tell application "Instruments" to activate
tell application "System Events"
keystroke (ASCII character 30) using option down
end tell
-- 새문서 만들기 (ctrl + n)
tell application "Visual Studio Code" to activate
tell application "System Events"
keystroke "n" using command down
end tell
repeat x times
tell application "Instruments" to activate
delay 0.2
tell application "System Events"
-- ctrl + c
keystroke "c" using command down
-- 한줄 아래로(↓)
keystroke (ASCII character 31)
end tell
tell application "Visual Studio Code" to activate
delay 0.2
tell application "System Events"
-- ctrl + v
keystroke "v" using command down
end tell
end repeat
quit
Windows cmd에서 자원사용률 측정
Windows 에서 시스템 또는 특정 프로세스의 자원사용률(CPU, Memory…)을 측정할 때,
성능 모니터(perfmon.msc)를 주로 사용하는데, 동일한 작업을 cmd에서 수행하는 방법을 정리한 글이다.
GUI 도구인 perfmon.msc 대신 CUI 명령줄 도구인 typeperf가 동일한 기능을 수행한다.
typeperf -cf < filename > [options]
typeperf -q [object] [options]
typeperf -qx [object] [options]
사용 가능한 카운터 목록을 조회하려면
하면되지만 1.8MB짜리 40만개나 되는 목록을 얻게된다.
그냥
C:\>typeperf -sc 60 -si 1 "\Processor(_Total)\% Processor Time" "\Process(_Total)\Private Bytes"
60초 동안 1초 간격으로 시스템 전체의 CPU 사용률과 가용 메모리량을 SC1.csv에 저장함
(※파일로 저장할때는 %%)
Windows에서 SMB 접속이 안될때
1. gpedit.msc 실행
2. [로컬 컴퓨터 정책 > 관리 템플릿 > 네트워크 > Lanman 워크스테이션] 선택
2. 보안되지 않은 게스트 로그온 사용 –> 사용
Since Windows 10, Windows Server 2016
Realforce 101 키보드를 위한 키 리매핑(레지스트리)
메인 키보드로 10년전 산 Realforce 101을 사용하고 있다.
즉 한영키와 Windows 키가 없다.
한영 전환은 shift-space로 하기 때문에 내겐 문제되지 않지만,
Caps Lock → Ctrl로
Ctrl → Windows 키로 동작하게 할 필요가 있다.
램상주하는 키 리매핑 프로그램도 있는거 같지만,
그냥 레지스트리를 편집해서 쓰는게 별도의 프로그램도 필요없고, 깔끔하다.
그래서 늘 아래와 같이 reg파일을 만들어 적용해서 사용하고,
2006년 작성한 CapsLock을 Ctrl로…도 이렇게 만들어진 것이다.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,e0,5b,1d,00,00,00,00,00
00,00,00,00, // 버전 (항상 0)
00,00,00,00, // 헤더 플래그 (항상 0)
03,00,00,00, // 키 리매핑 2개 + NULL 1개 = 총 3개
1d,00,3a,00, // L Ctrl(1d,00) ← CapsLock(3a,00)
e0,5b,1d,00, // L Win(e0,5b) ← L Ctrl(1d,00)
00,00,00,00 // NULL (종결자)
주요정보통신기반시설 취약점 분석·평가 기준
[주요정보통신기반시설 취약점 분석·평가 기준]
[시행 2013. 8. 8.] [미래창조과학부고시 제2013-37호, 2013. 8. 8., 일부개정]
나중에 다시 찾을 일 있을거 같아 여기에 스크랩