Skip to content

Instantly share code, notes, and snippets.

View mattbajorek's full-sized avatar

Matt Bajorek mattbajorek

View GitHub Profile
@mattbajorek
mattbajorek / 0_reuse_code.js
Created June 7, 2016 22:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mattbajorek
mattbajorek / appsettings.json
Created November 22, 2019 03:06
Adding AWS config settings
{
"AWSCognito": {
"Region": "{Region}",
"PoolId": "{PoolId}",
"AppClientId": "{AppClientId}"
}
}
@mattbajorek
mattbajorek / Startup.cs
Last active November 23, 2019 15:23
Authentication
...
public void ConfigureServices(IServiceCollection services)
{
var Region = Configuration["AWSCognito:Region"];
var PoolId = Configuration["AWSCognito:PoolId"];
var AppClientId = Configuration["AWSCognito:AppClientId"];
services
.AddAuthentication(options =>
{
@mattbajorek
mattbajorek / ClapsController.cs
Last active November 25, 2019 14:23
Authorization Decorator
...
using Microsoft.AspNetCore.Authorization;
...
// This authorize attribute will be applied to all routes in this controller
[Authorize]
[Route("api/[controller]")]
[ApiController]
@mattbajorek
mattbajorek / Startup.cs
Last active May 10, 2020 02:09
Add Policy Based Authorization
...
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddAuthorization(options =>
{
options.AddPolicy("Admin", policy => policy.RequireClaim("custom:groupId", new List<string> { "0" } ));
@mattbajorek
mattbajorek / ClapsController.cs
Last active May 10, 2020 02:08
Policy Based Authorization
...
using Microsoft.AspNetCore.Authorization;
...
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ClapsController : ControllerBase
@mattbajorek
mattbajorek / index.js
Last active March 26, 2020 02:44
todos-redux-to-react-sweet-state entry point
import React from 'react'
import { render } from 'react-dom'
import App from './components/App'
import { defaults } from 'react-sweet-state'
import { produce } from 'immer'
defaults.mutator = (currentState, producer) => produce(currentState, producer)
render(
@mattbajorek
mattbajorek / todos.store.js
Created March 26, 2020 02:43
todos-redux-to-react-sweet-state todos store
import { createStore } from 'react-sweet-state'
import actions from './todos.actions'
const initialState = []
const todosStore = createStore({ initialState, actions })
export default todosStore
@mattbajorek
mattbajorek / todos.actions.js
Created March 26, 2020 02:46
todos-redux-to-react-sweet-state todos actions
let nextTodoId = 0
const todosActions = {
addTodo: text => ({ setState }) => {
setState(todos => {
todos.push({
id: nextTodoId++,
text,
completed: false
})
@mattbajorek
mattbajorek / todos.selector.js
Created March 26, 2020 02:52
todos-redux-to-react-sweet-state todos selector
import makeSelectorsIntoHooks from '../utils'
import todosStore from './todos.store'
import { VisibilityFilters } from '../visibilityFilter/visibilityFilter.store'
const todoSelectors = {
useTodosActions: null,
useVisibleTodos: (todos, visibilityFilter) => {
switch (visibilityFilter) {
case VisibilityFilters.SHOW_ALL: