This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- coding:utf-8 -*- | |
from fabric.api import * | |
from fabric.decorators import runs_once | |
from datetime import datetime | |
env.hosts = ['ホスト名'] | |
env.user = 'ユーザー名' | |
env.key_filename = '鍵の場所' | |
env.project_name = 'プロジェクトネーム' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @t = 2; | |
SELECT | |
SUM(A.counter) AS counter | |
FROM | |
(SELECT | |
FROM_UNIXTIME(CEILING(UNIX_TIMESTAMP(access_date) / (@t * 60)) * (@t * 60)) AS access_date, | |
1 AS counter | |
FROM | |
tmp_user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOAD DATA LOCAL INFILE 'CSVファイルのフルパス' INTO TABLE [テーブル名] FIELDS TERMINATED BY ',' ENCLOSED BY '"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE `[データベース名]`; | |
DROP PROCEDURE IF EXISTS `[ストアドプロシージャの名前]`; | |
DELIMITER $$ | |
USE `[データベース名]`$$ | |
CREATE DEFINER =`root`@`localhost` PROCEDURE `[ストアドプロシージャの名前]`(IN targetDate DATE) | |
BEGIN | |
/************************ | |
テンポラリーテーブルをDROP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ストアドプロシージャを使用したいDBを選択 */ | |
USE [データベース名]; | |
/* 今回使用したいストアドプロシージャの名前(初めて作成するときはいらない) */ | |
DROP procedure IF EXISTS `[プロシージャ名]`; | |
/************************ | |
通常のSQLだと「;(セミコロン)」でSQLの区切りを意味しているが今回はそれを「$$」に変えますよという意味。 | |
これを使用することでSQLを一気に終端の$$まで実行することができる。 | |
*************************/ | |
DELIMITER $$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
アナリティクスからデータを取得してくる | |
@param startDate 開始日 | |
@param endDate 終了日 | |
@param optArgs metricsやfilterなど | |
@return analyticsの結果 | |
**/ | |
function getAnalyticsData(startDate, endDate, optArgs) { | |
var profileId = [ビューID]; | |
var tableId = 'ga:' + profileId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
指定日を文字列で取得する | |
@param nDaysAgo 何日前か | |
@return date | |
**/ | |
function getLastNdays(nDaysAgo) { | |
var today = new Date(); | |
var before = new Date(); | |
before.setDate(today.getDate() - nDaysAgo); | |
return DateFormat(before); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bk = SpreadsheetApp.getActiveSpreadsheet(); | |
var weeklySh = bk.getSheetByName("[シート名]"); | |
/** | |
先週分のanalyticsのデータをセットする | |
**/ | |
function setLastWeekData() { | |
// 毎週月曜日に実行されるので7日前が月曜日で1日前は日曜日 | |
var today = new Date(); | |
// 実行日が月曜日のとき |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* Base trait for CSV | |
*/ | |
trait BaseCsv { | |
def toStringSeq: Seq[String] = { | |
this.productIterator.map(_.asInstanceOf[Option[String]].getOrElse("")).toSeq | |
} | |
def productIterator: Iterator[Any] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Linux | |
START_DATE="20160902" | |
END_DATE="20170303" | |
for (( DATE=${START_DATE}; ${DATE} < ${END_DATE}; DATE=`date -d "${DATE} 1 day" '+%Y%m%d'`)) | |
do | |
TARGET_DATE=`date -d ${DATE} '+%Y-%m-%d'` |
OlderNewer