Skip to content

Instantly share code, notes, and snippets.

@masatomix
masatomix / HS256Main.java
Last active May 13, 2021 09:12
HS256 / RSA256 を用いたサンプル。共通鍵、公開鍵でハッシュした署名をつけるJWSのサンプルと、公開鍵で署名したJWTを検証するサンプルコード。
package nu.mine.kino;
import java.text.ParseException;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.JWSVerifier;
import com.nimbusds.jose.KeyLengthException;
@masatomix
masatomix / AccessTokenRequestParam.java
Last active August 8, 2017 07:38
JerseyでJSONオブジェクトをPOSTする件
@Data
@AllArgsConstructor
public class AccessTokenRequestParam {
private String redirect_url;
private String client_id;
private String client_secret;
@masatomix
masatomix / HmacSha256Main.java
Created August 18, 2017 00:44
HmacSHA256 によるハッシュのサンプル
package nu.mine.kino;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
@masatomix
masatomix / file0.txt
Last active December 15, 2018 12:20
Qiitaで数式がつかえるみたいなので三角関数とか内積とか相関係数について書いて、Pythonで計算してみた ref: https://qiita.com/masatomix/items/278a233c39b4e82d0bad
\left(
\begin{array}{c}
\cos\theta\\
\sin\theta
\end{array}
\right)
package nu.mine.kino.springboot;
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
import * as functions from 'firebase-functions'
import * as cookie from 'cookie'
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const addCookie = functions.https.onRequest((request, response) => {
response.setHeader('Cache-Control', 'private') // Hosting経由だと、これがないとset cookieが削除される
_addCookie(response, 'key', 'value')
response.send('Hello from Firebase!')
#!/bin/bash
clientId=xxx
clientSecret=xxx
login_hint=1001
user_code=675325
backchannelReq=`cat << EOS
curl http://localhost:8080/api/backchannel/authentication -X POST \
@masatomix
masatomix / cloudformation_orch.json
Last active July 9, 2019 02:34
AWS CloudFormationを使って、セキュリティグループとEC2インスタンスを作成する Infra as code.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Description": "VpcId of your existing Virtual Private Cloud (VPC)"
},
"SubnetId": {
"Type": "AWS::EC2::Subnet::Id",
"Description": "SubnetId of your existing Subnet"
const request = require('request')
const url = 'https://rss.techplay.jp/event/w3c-rss-format/rss.xml'
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
const regex = /[\b]/
body = body.replace(regex)
const json = xml2json(body)
// for (var i in json.rss.channel.item) {
@masatomix
masatomix / gist:d0d00bceff0d46da38fc75a1872d20ed
Last active March 2, 2020 15:03
日付考慮コード。
const moment = require('moment-timezone')
// シンプルに
console.log(moment().format()) // 2020-02-13T10:47:10+09:00 (いま日本で10:47です)
console.log(new Date().toLocaleString()) // 2020-2-13 10:50:22 AM
// ってやると本番に行くと値が9時間ずれるよね、みたいな件。。
// 日付をあつかうには
// どのタイムゾーンの日付か(Timezone)
// どの言語で表示するか(Locale)