Skip to content

Instantly share code, notes, and snippets.

View tetsunosuke's full-sized avatar

ITO Tetsunosuke tetsunosuke

View GitHub Profile
@tetsunosuke
tetsunosuke / google_apps_checkboxes.gs
Created November 10, 2012 03:26
GoogleAppsScriptでチェックボックス の改造
// global にしておく
var checkBoxArray = ['幼少期(0~6歳頃)',
'学童期(6~12歳頃)',
'青年期(12~25歳頃)',
'成人期(25~40歳頃)',
'中年期(40~65歳頃)',
'老年期(65歳~)'];
function doGet() {
@tetsunosuke
tetsunosuke / checkbox_with_gui.js
Created November 13, 2012 03:41
CheckBox with GUI
// Script-as-app template.
function doGet() {
// GUIビルダーで初期表示
var app = UiApp.createApplication();
var myGui = app.loadComponent("MyGui");
app.add(myGui);
// 初期値設定
UserProperties.setProperty("red" ,false);
UserProperties.setProperty("blue" ,false);
@tetsunosuke
tetsunosuke / gmail2pdf.js
Created November 15, 2012 06:08
gmail2pdf
/**
* Retrieves all inbox threads and logs the respective subject lines.
* For more information on using the GMail API, see
* https://developers.google.com/apps-script/class_gmailapp
*/
function processInbox() {
// get all threads in inbox
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
@tetsunosuke
tetsunosuke / gmailsmap2inbox.gs
Created December 4, 2012 04:11
gmailsmap2inbox
/**
* Retrieves all inbox threads and logs the respective subject lines.
* For more information on using the GMail API, see
* https://developers.google.com/apps-script/class_gmailapp
*/
function processInbox() {
// get all threads in inbox
threads = GmailApp.getSpamThreads();
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
@tetsunosuke
tetsunosuke / Coverage.php
Created July 9, 2013 05:03
カバレッジを行ごとにファイルに記録する
<?php
function my_xdebug_shutdown() {
$result = xdebug_get_code_coverage();
foreach($result as $file => $covers) {
$lines = file($file);
if (!isCoverageTargetFile($file)) {
continue;
}
@tetsunosuke
tetsunosuke / spreadsheet2xml.js
Last active December 19, 2015 15:08
スプレッドシートからXMLを作成する習作。
/**
* スプレッドシート内のデータからXMLデータを生成します
* 1行目にXMLのタグ名を入れると、それに応じてデータをXML化します
* XMLオブジェクトを使うことで、& -> &amp; などの処理をAppsScript側に任せています
*
* 例)
*
* id | name | no
* 1 | miura | 18
* 2 | blanco | 42
@tetsunosuke
tetsunosuke / ga.gs
Created September 10, 2013 03:09
GoogleAnalyticsAPIからデータを取るサンプルです
function GoogleAnalytics_() {
this.apiBase = "https://www.googleapis.com/analytics/v3/data/ga";
this.tokenUrl = "https://accounts.google.com/o/oauth2/token";
/**
* 認証用のヘッダーを作る
*/
this.buildAuthorizationHeader = function(token) {
headers = {
"Authorization" : "Bearer" + " " + token
@tetsunosuke
tetsunosuke / gist:6710596
Created September 26, 2013 06:41
文字列を指定長で収まるようにするやつ
function Util_() {
/**
* mb_strwidth
* @param String
* @return int
* @see http://php.net/manual/ja/function.mb-strwidth.php
*/
this.mb_strwidth = function(str){
var i=0,l=str.length,c='',length=0;
for(;i<l;i++){
function padZero(v) {
return v < 10 ? "0" + new String(v) : new String(v);
}
function getBars(str) {
var result = 0;
var bars = {0: 6, 1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 4, 8: 7, 9: 6};
for (var i=0; i < str.length; i++) {
result += bars[str[i]];
}
return result;
<?php
error_reporting(E_ALL);
while($line=fgets(STDIN))
{
echo trim(solve($line)) . "\n";
}
function solve($str) {
for ($i = 0; $i < 26; $i++) {