Skip to content

Instantly share code, notes, and snippets.

View masahitojp's full-sized avatar
🎯
Focusing

Masato Nakamura masahitojp

🎯
Focusing
View GitHub Profile
@taichi
taichi / .golangci.yml
Last active May 7, 2024 07:29
ロギングライブラリのあり方については別途要検討。zapやzerologを使うならファクトリ関数だけを置くようにした方がいいかも。
linters-settings: # 設定のデフォルト値は、https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml で確認できる
depguard: # packagesに宣言されているモジュールの取り扱いに関するルール。ブラックリスト形式で使っているので、列挙したものを使うとエラーになる。
list-type: blacklist
packages:
- golang.org/x/xerrors # go 1.13で必要な機能はすべてerrorsに取り込まれたので使わない
- github.com/rs/zerolog # ログ出力用のライブラリはプロジェクト内部に作ったファクトリ関数経由で使うため
packages-with-error-message:
- golang.org/x/xerrors: "エラー処理は標準のerrorsを使って下さい。スタックトレースが必要な場合のみpkg/errorsを使って下さい"
- github.com/rs/zerolog: "ログ出力は example.com/myproject/logger#Newから利用して下さい"
dupl: # コードのコピペを検出するルール。 閾値のトークン数を越えるものをエラーにする
@paulsmith
paulsmith / echo.go
Created January 12, 2011 06:09
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
@sevastos
sevastos / aws-multipartUpload.js
Last active October 8, 2023 10:43
Example AWS S3 Multipart Upload with aws-sdk for Node.js - Retries to upload failing parts
// Based on Glacier's example: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/examples.html#Amazon_Glacier__Multi-part_Upload
var fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./aws-config.json');
var s3 = new AWS.S3();
// File
var fileName = '5.pdf';
var filePath = './' + fileName;
var fileKey = fileName;
@slfritchie
slfritchie / presentation.md
Created March 18, 2014 09:22
Erlang tracing, for the Riak source code reading series, 2014-03-18, Tokyo, Japan

Erlang Tracing: more than you wanted to know

Rough Outline

  • What can be traced?
  • How can trace events be specified?
  • "match specifications": twisty passages, all alike
  • WTF, can I just use DTrace and drink my coffee/beer/whisky in peace?
  • Trace delivery mechanisms: pick one of two
@essen
essen / my_module.erl
Created October 14, 2013 03:25
Thinking in Erlang: The Code
-module(my_module).
-export([my_function/1, my_function/2]).
-export([infinite_loop/0, f/1, r/2, sort/1]).
-export([only_primes/1, is_prime/1]).
my_function(A) when is_integer(A) ->
my_function(A, 0);
my_function(A) when is_list(A) ->
my_function(list_to_integer(A), 0).
@gakuzzzz
gakuzzzz / 1_.md
Last active August 2, 2023 01:59
Scala の省略ルール早覚え

Scala の省略ルール早覚え

このルールさえ押さえておけば、読んでいるコードが省略記法を使っていてもほぼ読めるようになります。

メソッド定義

def concatAsString(a: Int, b: Int): String = {
  val a_ = a.toString();
  val b_ = b.toString();
@gakuzzzz
gakuzzzz / 1_.md
Last active June 19, 2023 12:53
trait と abstract class の使い分け

trait と abstract class の使い分け

  • 基本は迷ったら trait にしておけば良いと思います
    • trait は一つの class に複数 mixin できますが、class は一つしか継承できません
    • つまり、trait であれば mixin される class を気にしなくてよいですが、 abstract class にした場合は、extends される class が他に継承したい物が無いか気にする必要があります
  • trait はコンストラクタを持つ事ができませんが、abstract class はコンストラクタを持つ事ができます
    • 従って、型引数に制約をつけたい時や、共通のフィールドの初期化などがある場合は、abstract class にすると楽な場合があります。
  • 以下に具体例を示します。良くある Java の enum を Scala で定義する場合の例です。
@bellbind
bellbind / ecc.py
Created December 1, 2011 08:08
[python]basics of elliptic curve cryptography
# Basics of Elliptic Curve Cryptography implementation on Python
import collections
def inv(n, q):
"""div on PN modulo a/b mod q as a * inv(b, q) mod q
>>> assert n * inv(n, q) % q == 1
"""
for i in range(q):
if (n * i) % q == 1:
@alexcasalboni
alexcasalboni / aws-lambda-static-type-checker.md
Last active May 22, 2023 07:31
AWS Lambda Static Type Checker Example (Python3)

How to use Python3 Type Hints in AWS Lambda

TL;DR

Static Type Checkers help you find simple (but subtle) bugs in your Python code. Check out lambda_types.py and incrementally improve your code base and development/debugging experience with type hints.

Your Lambda Function code will go from this: