Skip to content

Instantly share code, notes, and snippets.

View kamataryo's full-sized avatar
🦢
winter season

Kamata, Ryo kamataryo

🦢
winter season
View GitHub Profile
@kamataryo
kamataryo / export Ingress Portal Submission Progress
Last active August 29, 2015 14:23
This is Google app scripts snippet to export Ingress Portal Submission Review Progression from your gmail inbox into a google spreadsheet
function myFunction() {
var youremail = "youremail@example.com";
var mailtitle = "Portal Submission Review Progress";
var subjectqueries = {
"submit" : 'in:anywhere from:"Ingress Operations", subject:"Ingress Portal Submitted: "',
"review" : 'in:anywhere from:"Ingress Operations", subject:"Portal review complete: "',
"Live" : 'in:anywhere from:"Ingress Operations", subject:"Ingress Portal Live: "',
"Reject" : 'in:anywhere from:"Ingress Operations", subject:"Ingress Portal Rejected: "',
"accept" : 'in:anywhere from:"Ingress Operations", "1000 AP"'
@kamataryo
kamataryo / spliter.scpt
Last active August 29, 2015 14:24
this AppleScript positions 2 windows (ex. text editor and terminal) in ratio of 8:2 vertically
tell application "Finder"
set display_size to bounds of the window of the desktop
end tell
(* bounds == {0, 0, width, height} *)
set width to item 3 of display_size
set height to item 4 of display_size
set editor to { name : "Sublime Text", top : 0, height : height * 0.8 }
set terminal to { name : "Terminal", top : height * 0.8, height : height * 0.2 }
@kamataryo
kamataryo / yo_back_attack.js
Last active August 29, 2015 14:25
YO back against Ingress portal attack in google app script
// Google App Scriptの実行トリガーを時間主導型の1分ごとに設定する
function myFunction(){
//AgentIDとYoNameの対応リストを自力で作成
var AgentList = {
"Agent1" : "yoname1",
"Agent2" : "yoname2"
};
//履歴保存用スプレッドシート指定
@kamataryo
kamataryo / .bashrc
Last active July 4, 2016 16:23
bash/zsh prompt support to check if Vagrantfile exists.
# Add or custome for your .bashrc
source ~/.vagrant-prompt.sh
export PS1='\u@\h \W\[\033[33m\]$(__vagrant_pt)\[\033[00m\] $ '
# filename => abc012ABC~`!@#$%^&*()_+-={}[]|":;'?><,./マルチバイトxyz
# url => https://gist.github.com/KamataRyo/e087a7b3d070a04704126a87e302dbe1#file-abc012abc-_-xyz
imort $switch from '@kamataryo/extypes/Object/$switch'
'ABC'[$switch]
.case('abc', () => console.log('not matched..'))
.case('ABC', () => console.log('matched!'))
.default(() => console.log('not matched..'))
@kamataryo
kamataryo / timeout-proxy.js
Last active August 25, 2018 06:21
Add snippet
/**
* タイムアウト機能を埋め込むプロキシ
* targetが一定時間呼ばれなかったら固有の処理を実行する
* タイムアウトすると、呼ばれた回数のカウンタはリセットされる
* @param {function} target プロキシされる関数
* @param {{timeout: number, callback: function}} opts オプション
* @return {function} プロキシされた関数
*/
const timeoutProxy = (target, opts) => {
/**
@kamataryo
kamataryo / deploy.bash
Created June 1, 2019 23:52
Lambda をデプロイする AWS CLI のスクリプト
ZIP_FILENAME="./archive-$npm_package_version.zip"
rm -rf node_modules
npm install --only=prod
zip -r $ZIP_FILENAME node_modules index.js
aws lambda create-function \
--function-name $AWS_LAMBDA_FUNCTION_NAME \
--runtime nodejs10.x \
--role $AWS_LAMBDA_ROLE \
@kamataryo
kamataryo / delayPromise.ts
Created September 21, 2019 13:46
Delay your promise
const wait = (msec: number) =>
new Promise(resolve => setTimeout(resolve, msec));
const catched = Symbol("is-catched");
const delayPromise = (promise: Promise<any>, msec: number) => {
const catchedPromise = promise.catch(err => ({ [catched]: err }));
return Promise.all([catchedPromise, wait(msec)]).then(result => {
if (result[0][catched]) {
@kamataryo
kamataryo / typeguard-example-with-side-effect.ts
Created October 4, 2019 07:15
TypeScript TypeGuard example with side effects
type Ref = { message?: string; isValid?: boolean };
const isValid = (value: any, ref: Ref): value is string => {
if (typeof value === "string") {
if (value.length > 10) {
ref.isValid = false;
ref.message = "Value should have length less than 10.";
} else {
ref.isValid = true;
ref.message = "OK";