ㅍ
ㅍ
창업일지 - 무소득사실확인서 제출
페르미 패러독스
errordlg의 활용 matlab alert의 기능 수행
Create and display an error dialog box
Syntax
errordlg
errordlg('errorstring
')
errordlg('errorstring
','dlgname
')
errordlg('errorstring
','dlgname
','on')
h = errordlg(...)
Description
[Workers] Cloudflare Workers로 서버리스 코딩
Cloudflare 는 https를 쉽게 제공해주는 서비스로 출발하였다.
해당 기능은 라우팅이나 호스팅과 관련이 있는데, 마이크로 서비스를 사용할 수 있는 Workers를 제공한다.
현재는 nodejs 밖에 사용하지 못한다고 하나, aws에서 nodejs를 lambda로 사용해 봤기 때문에 조금은 수월하게 접근할 수 있었다.
간단한 예제들을 통해 실행, json 다루기, json을 html로 표현하기 등을 해보았다.
json 샘플에서는 header를 json으로 클라이언트에 전달하므로 html이 text로 나온다.
그래서 해당 부분만 수정하여 html 표가 그려질 수 있도록 수정했다.
추후에는 실제 API와 연결하여 활용해 보도록 해야겠다.
'content-type': 'text/html;charset=UTF-8',
[flex] flex를 이용한 영상처리(소스 및 라이브러리)
[notion] API를 사용하여 데이터베이스의 목록 출력
여러 설명페이지에 데이터베이스 기본 정보를 출력하는 예제는 많으나, 목록을 출력하는 예제는 부족하다.
query라는 api를 이용하여 POST 방식으로 호출해야 한다.
데이터의 내용이 있을 경우 results의 배열로 리턴되며, 속성 중 column(여기서는 column)를 추가하여 존재하는 목록을 출력해 보았다.
img 파일의 저장
[push챗봇] 구글 앱스 스크립트 X 행아웃 채트(구글 채트)
행아웃 채트가 구글채트로 이름이 변경되었다.
개별 도메인 사용자만 이용할 수 있는데, 무료 계정도 모바일은 가능하다.
(chat.google.com) 로 접속하면 PC에서도 이용 가능하고 대화방의 이름을 얻을 수 있기 때문에, 6의 예제 코드에 space.name 에 하드 코딩 가능하다.
https://suritam9.pe.kr/index.php?mid=imp&document_srl=1405 에서 이미 대화형 봇을 다뤘으며, 이번 건은 push형이다.
그동안은 integramat 이나 다른 수단을 이용했는데, 구글 앱스 스크립트로 바로 가능한 방법이 있어 시도해 봤다.
https://medium.com/@stephane.giron/send-push-message-to-hangouts-chat-with-apps-script-274ddadcbc55
1. 구글 클라우드 플랫폼 서비스 계정에서 계정 생성 및 키를 만든다.(JSON 형태 다운로드 파일 보관)
2. 앱스 스크립트 라이브러리에서 Oauth2 를 설치하는데, 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF 로 검색한다.
3. 1에서 다운 받은 파일에 PRIVATE_KEY 와 CLIENT_EMAIL를 복사하고 서비스 생성 스크립트를 실행시킨다.
var PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n';
var CLIENT_EMAIL = '...';/**
* Configures the Chatbot service.
*/
function getChatbotService() {
return OAuth2.createService(‘MyChatBot’)
// Set the endpoint URL.
.setTokenUrl(‘https://accounts.google.com/o/oauth2/token')// Set the private key and issuer.
.setPrivateKey(PRIVATE_KEY)
.setIssuer(CLIENT_EMAIL)// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getScriptProperties())// Set the scope.
.setScope(‘https://www.googleapis.com/auth/chat.bot');
}
4. 토큰이 발행되는지 테스트 한다.
/**
* Test for getting access token
*/
function getAccessTokenTest() {
var service = getChatbotService();
if (service.hasAccess()) {
Logger.log(service.getAccessToken());
} else {
Logger.log(service.getLastError());
}
}
5. 참고 URL 에 빠져 있는 부분인데, 봇을 만들어 채팅방에 추가해야 한다. (봇 만들기는 다른 사이트를 검색하여 아이콘 등을 설정한다.)
권한은 도메인 내로 해야 head 배포 id 사용이 가능하다.
배포 id는 게시에 메니페스트에서 배포를 선택하여 lastesthead deployment 배포에서 getid 를 선택하여 확인한다.
6. 예제 코드를 이용해 해당 채팅방에 메시지를 보내본다.
/**
* Authorizes and makes a request to the Hangouts Chat API for :
* - Getting all spaces the bot is installed
* - Sending message when space is a Direct Message space
*/
function sendPushMessage() {
var service = getChatbotService();
if (service.hasAccess()) {
//WE retrieve all the spaces bot has been added
var url = 'https://chat.googleapis.com/v1/spaces';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
}
});
var rep = JSON.parse(response.getContentText());
if(rep.spaces && rep.spaces.length > 0){
for(var i = 0; i < rep.spaces.length; i++) {
var space = rep.spaces[i];
if(space.type == "DM"){
//We send message only to Direct Message room.
var url = 'https://chat.googleapis.com/v1/'+space.name+'/messages';
var options = {
method : 'POST',
contentType: 'application/json',
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
},
payload : JSON.stringify({ text: "Hello world !" })
}
//We send message to the DM room
UrlFetchApp.fetch(url, options);
}else{
//If Type is 'ROOM' or 'TYPE_UNSPECIFIED' we don't send notification.
}
}
}else{
Logger.log('Bot is not added to any spaces');
}
} else {
Logger.log(service.getLastError());
}
}
7. 오류가 발생한다면 구글 개발자 콘솔에서 행아웃 채트 API 활성화를 누락했거나, 채팅방이 잘 확인되는지, space 에 대한 참여 멤버, 대화방 명 등을 확인해 보면 디버깅에 도움이 된다.
https://developers.google.com/hangouts/chat/reference/rest/v1/spaces
https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.members
https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages
[AIR] 클립보드 내용 보기
flex 페이지 이동
활용한 함수
json encoding, decoding
flex 외부 변수 이용, 받기, 현재 url
travelling salesman problem
|
travelling salesman problem
|
melfb.m
function m = melfb(p, n, fs)
p=9;
n=2048;
fs=2000;
f0 = 700 / fs;
fn2 = floor(n/2);
lr = log(1 + 0.5/f0) / (p+1);
% convert to fft bin numbers with 0 for DC term
bl = n * (f0 * (exp([0 1 p p+1] * lr) - 1));
b1 = floor(bl(1)) + 1;
b2 = ceil(bl(2));
b3 = floor(bl(3));
b4 = min(fn2, ceil(bl(4))) - 1;
pf = log(1 + (b1:b4)/n/f0) / lr;
fp = floor(pf);
pm = pf - fp;
r = [fp(b2:b4) 1+fp(1:b3)];
c = [b2:b4 1:b3] + 1;
v = 2 * [1-pm(b2:b4) pm(1:b3)];
m = sparse(r, c, v, p, 1+fn2);
size_m = size(m);
plot(linspace(0, (fs/2), (n/2)+1),m);
%title('Mel-scale filter bank');
xlabel('Frequency (Hz)');
set(get(gca,'xlabel'),'FontSize',20);
ylabel('Amplitude');
set(get(gca,'ylabel'),'FontSize',20);
set(gca, 'XTick',[0:100:2000], 'XTickLabel',[0:100:1000],'fontsize',20);
set(gca, 'YTick',[0:1:2], 'YTickLabel',[0:1:2],'fontsize',20);
댓글 달기