Skip to content

Instantly share code, notes, and snippets.

Leon Radley leon

View GitHub Profile
@leon
leon / test.yml
Created Mar 1, 2020
Nrwl NX github actions
View test.yml
name: Test develop and feature branches
on:
push:
branches:
- develop
- "feature/*"
jobs:
test:
@leon
leon / auth.state.ts
Created Apr 1, 2018
NGXS auth state
View auth.state.ts
import { Router } from '@angular/router';
import { Action, Selector, State, StateContext, Store } from '@ngxs/store';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase';
import { take, tap } from 'rxjs/operators';
import {
CheckSession,
LoginWithFacebook,
View aframe-map-controls.js
/* global AFRAME THREE */
if (typeof AFRAME === 'undefined') {
throw new Error('Component attempted to register before AFRAME was available.');
}
var radToDeg = THREE.Math.radToDeg;
/**
* Example component for A-Frame.
@leon
leon / index.html
Last active May 11, 2017
Click bug in d3 v4 and zoom
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
transform = d3.zoomIdentity;;
@leon
leon / localstorage.service.ts
Created Feb 25, 2017
Angular LocalStorageService
View localstorage.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class LocalStorageService {
public localStorage: any;
constructor() {
if (!localStorage) {
throw new Error('Current browser does not support Local Storage');
@leon
leon / secure-http.service.ts
Created Dec 30, 2016
Angular Secure HTTP Service (JWT)
View secure-http.service.ts
import {
Http,
ConnectionBackend,
Headers,
Request,
RequestOptions,
RequestOptionsArgs,
Response,
RequestMethod,
} from '@angular/http';
@leon
leon / secure-http.ts
Created Nov 14, 2016
secure-http angular2
View secure-http.ts
import { isString } from 'lodash';
import {
Http,
ConnectionBackend,
Headers,
Request,
RequestOptions,
RequestOptionsArgs,
Response,
RequestMethod,
@leon
leon / README.md
Last active Nov 11, 2016
Angular 2 SecureHttp
View README.md

When communicating with a backend we often need to add an authentication token and csrf-tokens.

Angular doesn't provide http interceptors as it did before, you instead need to create a subclass of http to get what you are looking for.

By using the SecureHttp service instead of the basic http service we can automatically add this to all outgoing requests.

As the backend often speaks json, this service also automatically converts post request body into json and converts response body's into json as well.

@leon
leon / .bash_aliases
Created Aug 30, 2016
Bash alias "npmd" installs both dependency and TypeScript defintion files in one go
View .bash_aliases
#
# Install Both Library and TypeScript defintion files in one go
#
npmd() {
#do things with parameters like $1 such as
npm install --save $1
npm install --save-dev @types/$1
}
alias npmd=npmd
View OAuthSsoTryAuthenticationFilter.java
package se.radley.security;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.cloud.security.oauth2.sso.OAuth2SsoProperties;
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
You can’t perform that action at this time.