Skip to content

Instantly share code, notes, and snippets.

View iwatakeshi's full-sized avatar
📚
Always learning

Takeshi iwatakeshi

📚
Always learning
View GitHub Profile
@iwatakeshi
iwatakeshi / service-workers.md
Created April 20, 2020 17:12 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@iwatakeshi
iwatakeshi / iso-3166-1_codes.ex
Created March 21, 2020 20:15 — forked from delameko/iso-3166-1_codes.ex
ISO 3166-1 (alpha 2) country codes, in an Elixir list
country_codes = [
%{ iso_3166_1: "AF", name: "Afghanistan" },
%{ iso_3166_1: "AX", name: "Aland Islands" },
%{ iso_3166_1: "AL", name: "Albania" },
%{ iso_3166_1: "DZ", name: "Algeria" },
%{ iso_3166_1: "AS", name: "American Samoa" },
%{ iso_3166_1: "AD", name: "Andorra" },
%{ iso_3166_1: "AO", name: "Angola" },
%{ iso_3166_1: "AI", name: "Anguilla" },
%{ iso_3166_1: "AQ", name: "Antarctica" },
@iwatakeshi
iwatakeshi / Guardian JWT.md
Created March 8, 2020 18:49 — forked from nikneroz/Guardian JWT.md
Elixir + Phoenix Framework + Guardian + JWT. This is tutorial and step by step installation guide.

Elixir + Phoenix Framework + Guardian + JWT + Comeonin

Preparing environment

We need to generate secret key for development environment.

mix phoenix.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hf

Let's generate User model and controller.

@iwatakeshi
iwatakeshi / Elixir Email Validation
Created March 6, 2020 18:44 — forked from mgamini/Elixir Email Validation
Elixir Email Validation
defmodule EmailValidator do
# ensure that the email looks valid
def validate_email(email) when is_binary(email) do
case Regex.run(~r/^[\w.!#$%&’*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i, email) do
nil ->
{:error, "Invalid email"}
[email] ->
try do
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email
@iwatakeshi
iwatakeshi / Readme.md
Created January 22, 2020 00:52 — forked from j0lvera/Readme.md
FaunaDB User Token Expiration (for ABAC)

Auth0 + FaunaDB ABAC integration: How to expire Fauna user secrets.

Fauna doesn't yet provide expiration/TTL for ABAC tokens, so we need to implement it ourselves.

What's in the box?

3 javascript functions, each of which can be imported into your project or run from the command-line using node path/to/script.js arg1 arg2 ... argN:

  1. deploy-schema.js: a javascript function for creating supporting collections and indexes in your Fauna database.
@iwatakeshi
iwatakeshi / useScrollDirection.js
Last active January 9, 2020 19:19 — forked from reecelucas/useScrollDirection.js
React hook to detect scroll direction, based on the API of https://github.com/dollarshaveclub/scrolldir
const SCROLL_UP = 1;
const SCROLL_DOWN = -1;
const useScrollDirection = ({
initialDirection,
thresholdPixels,
off
} = {}) => {
const [scrollDir, setScrollDir] = useState(initialDirection);
@iwatakeshi
iwatakeshi / nginx.conf
Created September 20, 2019 05:33 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@iwatakeshi
iwatakeshi / nginx.conf
Created September 12, 2019 05:59 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@iwatakeshi
iwatakeshi / responsive-badge.html
Created August 25, 2019 21:37 — forked from ericclemmons/responsive-badge.html
Responsive indicators for TailwindCSS
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/tailwind.min.css">
<!-- Responsive indicators! -->
<div class="fixed top-0 right-0 z-50 bg-pink-500 text-white shadow-md px-2 rounded-bl font-mono">
<span class="sm:hidden">default</span>
<span class="hidden sm:inline md:hidden">sm</span>
<span class="hidden md:inline lg:hidden">md</span>
<span class="hidden lg:inline xl:hidden">lg</span>
<span class="hidden xl:inline">xl</span>
</div>
@iwatakeshi
iwatakeshi / nuxt.config.js
Created August 19, 2019 15:37 — forked from mkmms/nuxt.config.js
@nuxt/apollo Cors Issue Apollo config
apollo: {
clientConfigs: {
default: {
httpEndpoint: `${process.env.API_URL}/graphql`,
httpLinkOptions: {
fetchOptions: {
mode: 'cors' //Cors Needed for external Cross origins, need to allow headers from server
},
credentials: "omit" //must be omit to support application/json content type
}