Skip to content

Instantly share code, notes, and snippets.

@tnishimura
tnishimura / example-tokens.bash
Last active January 17, 2022 13:22
Example tokens to be used with the samples in "JWT Authentication and Authorization for your Giraffe API" at https://carpenoctem.dev/blog/jwt-authentication-authorization-giraffe-api-server-fsharp/
# Below are two tokens to be used with the article "JWT Authentication and Authorization for your
# Giraffe API" at https://carpenoctem.dev/blog/fsharp-giraffe-jwt-auth/
# {"alg":"HS256","typ":"JWT"}
# {
# "CustomClaim": "value",
# "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "Jane Adminton",
# "http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Admin",
# "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth": "2003/10/31",
# "exp": 1705468508,
@tnishimura
tnishimura / generate-jwt-with-fsharp.fsx
Last active September 5, 2023 10:00
This is an F# interactive script to generate a JWT. You can use it as a reference for when you are generating JWT on your server for a client, for example. It is hard coded for symmetric signing (HS256), but can be modified for asymmetric signing RS256, see notes in code.
(*
This is an F# interactive script to generate a JWT. You can use it as a reference for when you are generating JWT on
your server for a client, for example. It is hard coded for symmetric signing (HS256), but can be modified for
asymmetric signing RS256, see notes.
*)
#r "nuget: System.IdentityModel.Tokens.Jwt"
open System
open System.Text // for Encoding
open System.IdentityModel.Tokens.Jwt // For JwtSecurityToken (Install it from Nuget)
open System.Security.Claims // For Claim, ClaimTypes
@tnishimura
tnishimura / index.html
Last active February 7, 2020 02:02
--box-shadow on ion-searchbar does nothing. This gist was created by taking the example at https://github.com/ionic-team/ionic-docs/blob/master/src/demos/api/searchbar/index.html, changing the cdn links to 4.11.10, and applying the --box-shadow style to the ion-searchbar (via the red-box class).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Searchbar</title>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@4.11.10/dist/ionic/ionic.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core@4.11.10/dist/ionic/ionic.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@4.11.10/css/ionic.bundle.css"/>
</head>
@tnishimura
tnishimura / redux-typescript-todo-list-example.ts
Last active December 22, 2019 12:06
This is a type-safe version of the To-Do list example in Redux's documentation. Everything is typed and should pass in 'strict' mode'. It uses some advanced typescript features such as "keyof".
import { createStore, combineReducers, Reducer } from "redux";
///////////////////////////////////////////////////////////////////////
// action types
// first, define all the action types
const ADD_TODO = "ADD_TODO";
const COMPLETE_TODO = "COMPLETE_TODO";
const REMOVE_TODO = "REMOVE_TODO";
const SET_VISIBILITY_FILTER = "SET_VISIBILITY_FILTER";
import sys
import math
import fractions
def pi_fraction(gap):
"""Print the fraction within gap of pi that has the smallest denominator.
>>> pi_fraction(0.01)
22 / 7 = 3.142857142857143