Skip to content

Instantly share code, notes, and snippets.

View matsubara0507's full-sized avatar
:bowtie:
Working with Ruby

MATSUBARA Nobutada matsubara0507

:bowtie:
Working with Ruby
View GitHub Profile
def radix(d: Int, n: Int): List[Int] = {
def loop(x: Int): List[Int] =
if (x == 0) Nil else { val a = x / d; val b = x % d; b :: loop(a) }
loop(n).reverse
}
def isPalin(ns: List[Int]): Boolean = ns == ns.reverse
def isMultiPalin(n: Int): Boolean =
(2 to n).toList.map(radix(_, n)).count(xs => xs.length > 2 && isPalin(xs)) >= 2
@matsubara0507
matsubara0507 / graph-fluent.java
Last active June 27, 2017 16:10
ジェネリクス勉強会(https://connpass.com/event/56773/) の Haochen の発表ネタの実装をしてみた(合ってないかも)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.function.Consumer;
public class Main {
public static void main(String[] args) throws Exception {
System.out.println("hello!!!");
CanvasObj obj = Graphics.builder()
.newGroup()
import Control.Applicative (liftA2)
import Data.List (unfoldr)
import Data.Tuple (swap)
solve :: Int -> [Int]
solve = fmap (radix10 3 . uncurry gen) . filter (uncurry check)
. zip [(2,0),(1,0),(0,1),(0,2)] . repeat . radix 3
check :: (Int, Int) -> [Int] -> Bool
check (x,y) = liftA2 (&&) (not . null) ((== x) . head) . dropWhile (== y) . reverse
@matsubara0507
matsubara0507 / _brainfuck.hs
Last active June 14, 2018 10:49
Brainf*ck in Haskell
import Data.Char (chr)
brainfuck :: String -> IO String
brainfuck cmds = loop ([], (return 0), (repeat $ return 0)) 0 []
where
max = length cmds
loop :: ([IO Int], IO Int, [IO Int]) -> Int -> [IO Char] -> IO String
loop (xs,y,zs) index outs
| index == max = sequence (reverse outs)
| otherwise = cnd (cmds !! index)
@matsubara0507
matsubara0507 / int_sqrt_min.py
Created November 6, 2017 13:53
1から1000までの整数に対して最小連続平方根を求めそれが10以下であればその数と最小連続平方根を出力するスクリプト
# coding: utf-8
import math
def is_int(n):
return n % 1 == 0
def int_sqrt(n):
a = math.sqrt(n)
if is_int(a):
return int(a)
@matsubara0507
matsubara0507 / line-echo-bot-on-cloud-functions.md
Last active December 27, 2018 13:16
LINE の Echo Bot を Google Cloud Functions に作る ref: https://qiita.com/matsubara0507/items/04ab3c2197aa5f68e499

LINE の Echo Bot を Google Cloud Functions に作る LINE Bot を Cloud Functions で作りたくて、試しに echo bot を書いてみようとしたんですが、意外とまとまってる資料が無かったので残しておきます。

全体のリポジトリはココにあります。

Cloud Functions

Google Cloud Platform 版の AWS Lambda ですね。 まだ Beta 版で、正直 Lambda の方が機能豊富な気がします(ちゃんと比較はしてないけど)。 特に Lambda と比べて以下の点が今回は引っかかりました。

@matsubara0507
matsubara0507 / oragon.gs
Last active May 11, 2018 17:17
Add meshi cmd
function doPost(e) {
var prop = PropertiesService.getScriptProperties().getProperties();
if (prop.VERIFY_TOKEN != e.parameter.token) {
throw new Error('invalid token.');
}
/* Load Spread Sheet */
var ss = SpreadsheetApp.openById(prop.SPREAD_SHEET_ID)
var membersSheet = ss.getSheetByName(prop.MEMBERS_SHEET_NAME);
@matsubara0507
matsubara0507 / app.elm
Created December 26, 2017 13:08
elm-nankatsukuro#4
module Main exposing (..)
import Html exposing (Html, a, div, span, text, textarea)
import Html.Attributes exposing (class, readonly, type_, value, wrap)
import Html.Events exposing (onClick)
import List.Extra as List
type alias Key =
{ view : String
@matsubara0507
matsubara0507 / pandoc_kanshi.hs
Created January 16, 2018 14:21
MD -> LaTeX を監視してもらうんやー
-- stack --resolver lts-10.3 runghc --package text --package shelly --package fsnotify
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (FilePath)
import Data.Text (pack, unpack)
import qualified Data.Text.IO as T
import Data.Bool (bool)
import Data.List (scanl1, scanr1)
main :: IO ()
main = print $ all ((==) <$> snd <*> (show . solve . fst)) testSet
solve = sum . fmap (sum . (zipWith (-) =<< (zipWith min . scanl1 max <*> scanr1 max)) . fmap (read . (: []))) . words . fmap (bool ' ' <*> (/=) '0')
testSet :: [(String, String)]
testSet =