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
@matsubara0507
matsubara0507 / odeEuler.hs
Created February 28, 2018 04:28
odeEuler
import Data.List (mapAccumL)
showTupleWith :: (Show a, Show b) => String -> (a, b) -> String
showTupleWith sep (a, b) = show a ++ sep ++ show b
dxList :: (Enum a, Floating a) => a -> a -> [a]
dxList dx xmax = [0.0, dx..xmax]
odeEuler :: (Enum a, Floating a) => (a -> a) -> a -> a -> a -> [(a, a)]
odeEuler f yinit dx xmax = snd $ mapAccumL calc yinit $ zip xs (tail xs)
@matsubara0507
matsubara0507 / fizzbuzz.hs
Last active February 27, 2018 11:37
FizzBuzz
fizzbuzz = flip maybe id <$> show <*> foldl1 mappend . map fst . filter snd . flip map [(Just "Fizz", 3), (Just "Buzz", 5), (Nothing, 1)] . fmap . (fmap (== 0) . mod)
@matsubara0507
matsubara0507 / example.hs
Last active February 22, 2018 13:27
Tangle で Do 記法レスプログラミング
-- stack script --resolver ./snapshot.yaml -- example.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
module Main where
@matsubara0507
matsubara0507 / brittany-rec.hs
Created February 21, 2018 10:36
brittany を再帰的にかける
-- stack script --resolver lts-10.6 -- .\.temp\brittany-all.hs src --write-mode inplace
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text (Text, pack)
import qualified Filesystem.Path as P
import Shelly
import System.Environment (getArgs)
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 =
@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
@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 / 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 / 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 / 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)