Skip to content

Instantly share code, notes, and snippets.

@mattsan
mattsan / Makefile
Created Nov 29, 2020
C++のクラスをNIFでElixirにバインドしてみた
View Makefile
PREFIX = $(MIX_APP_PATH)/priv
BUILD = $(MIX_APP_PATH)/obj
NIF = $(PREFIX)/counter_nif.so
CFLAGS = -std=c++11 -fpic
LDFLAGS = -lpthread -dynamiclib -undefined dynamic_lookup
ERL_CFLAGS = -I$(ERL_EI_INCLUDE_DIR)
ERL_LDFLAGS = -L$(ERL_EI_LIBDIR) -lei
@mattsan
mattsan / ec2_stat
Created Aug 22, 2020
AWS EC2 インスタンスの状態を調べる
View ec2_stat
#!/usr/bin/env ruby
require 'aws-sdk-ec2'
require 'thor'
class Ec2Stat < Thor
default_command :stat
desc :stat, 'show statuses of ec2 instances'
option :profile, aliases: '-p', default: 'default'
@mattsan
mattsan / events
Created Aug 22, 2020
AWS Events の内容を一覧する
View events
#!/bin/sh
if [ "$1" = "production" ]; then
STAGE=production
elif [ "$1" = "staging" ] || [ "$1" = "" ]; then
STAGE=staging
else
cat <<EOS
usage:
@mattsan
mattsan / harndler.rb
Created Mar 14, 2020
Ruby で記述した AWS Lambda function を使って idobata に定期的にメッセージを post するサンプル
View harndler.rb
require 'json'
require 'net/https'
def hello(event:, context:)
uri = URI.parse(ENV['IDOBATA_HOOK_URL'])
source = event['source']
Net::HTTP.post_form(uri, {source: source})
end
@mattsan
mattsan / ads7846.ex
Created Jul 27, 2019
ADS7846 Touchscreen 用 Scenic.ViewPort.Driver の実装
View ads7846.ex
defmodule ADS7846 do
use Scenic.ViewPort.Driver
alias Scenic.ViewPort
require Logger
defguard is_pos(x, y) when is_number(x) and is_number(y)
@init_retry_ms 400
@device "ADS7846 Touchscreen"
@mattsan
mattsan / serverless.yml
Created Jul 24, 2019
Serverless で layers に gems を配置する
View serverless.yml
service: emattsan
provider:
name: aws
runtime: ruby2.5
stage: ${opt:stage, 'development'}
region: ap-northeast-1
package:
exclude:
@mattsan
mattsan / Gemfile
Created Jul 6, 2019
A sample of Sinatra + Slim
View Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'sinatra'
gem 'sinatra-contrib'
gem 'slim'
@mattsan
mattsan / bits.exs
Created Jun 9, 2019
Elixir の Stream.unfold/2 を使って整数をビット列に分解する例
View bits.exs
defmodule Bits do
require Integer
import Integer
import Bitwise
@doc """
A integer value to a bit list.
## example
@mattsan
mattsan / cli.ex
Last active May 25, 2019
[練習] wc (の機能の一部)を C++ で実装してみた
View cli.ex
defmodule ExCount.CLI do
@opts [
strict: [only_line: :boolean],
aliases: [l: :only_line]
]
def main(args) do
args
|> OptionParser.parse(@opts)
|> show_counts()
@mattsan
mattsan / README.md
Created May 19, 2019
Serverless を使った Ruby の AWS Lambda のプロジェクト例
View README.md

Serverless を使った Ruby の AWS Lambda のプロジェクト例

ディレクトリ構成

.
├── handler.rb
├── layers/
│   ├── Gemfile
│   └── Gemfile.lock