Skip to content

Instantly share code, notes, and snippets.

@naosim
naosim / ValueObject.php
Last active September 25, 2017 12:56
ValueObject
<?php
declare(strict_types=1);
class StringVO {
protected $value; // string
function __construct(string $value) {
$this->value = $value;
}
public function getValue(): string {
return $this->value;
@naosim
naosim / ApiUtils.php
Created September 25, 2017 12:57
ApiUtils
<?php
function api_forminput_jsonoutput($get_action, $post_action) {
header('Content-Type: application/json; charset=utf-8');
try {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo json_encode($post_action());
} else {
echo json_encode($get_action());
}
} catch(RuntimeException $e) {
@naosim
naosim / File.php
Last active September 25, 2017 21:23
File
<?php
function rstrpos ($haystack, $needle) {
$size = strlen ($haystack);
$pos = strpos(strrev($haystack), $needle);
if ($pos === false) {
return false;
}
return $size - $pos;
}
@naosim
naosim / ArraySchema.php
Created September 26, 2017 22:25
ArraySchema
<?php
class ArraySchema {
private $value;
function __construct(array $value) {
$this->value = $value;
}
function getValue() {
return $this->value;
}
}
@naosim
naosim / BasicAuth.php
Created October 4, 2017 21:46
BasicAuth.php
<?php
function basic_auth_custom(Closure $auth) {
switch (true) {
case !isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']):
case !$auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
header('WWW-Authenticate: Basic realm="Enter username and password."');
header('Content-Type: text/plain; charset=utf-8');
die('このページを見るにはログインが必要です');
}
}
@naosim
naosim / post_chatwork_form_gas.js
Created November 2, 2017 11:02
GoogleAppsScriptからチャットワークにメッセージを飛ばす
function createChatworkClient(token) {
var header = {'X-ChatWorkToken' : token };
return {
postMessage: function(roomId, message) {
var url = "https://api.chatwork.com/v2/rooms/" + roomId + "/messages";
var payload = {
'body': message
};
var options = {
'method': 'post',
@naosim
naosim / getListFromSheet.js
Last active November 5, 2017 06:22
【GAS】spreadsheetのテーブルをオブジェクトに変換する
function getListFromSheet(sheetName) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
var range = sheet.getDataRange();
var map = range.getValues();
var header = map[0];
var ary = [];
for(var row = 1; row < map.length; row++) {
var obj = {};
@naosim
naosim / SheetTable.js
Last active December 20, 2017 01:33
GoogleSpreadSheetをテーブルっぽく使う
function SheetTable(sheetName) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var headers = sheet
.getDataRange()
.getValues()[0];
var headersIndexMap = headers.reduce(function(memo, key, i){
memo[key] = i;
return memo;
}, {});
@naosim
naosim / anpan.svg
Last active December 29, 2017 15:04
アンパン
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@naosim
naosim / myJarTask.gradle
Last active March 21, 2018 09:10
デフォルトのjarを自作のjarに差し替える
// デフォルトのjarをアーティファクトから削除
configurations.archives.artifacts.with { archives ->
def jarArtifact
archives.each {
if (it.file =~ 'jar') {
jarArtifact = it
}
}
println "JAR to delete: ${jarArtifact}"
remove(jarArtifact)