Skip to content

Instantly share code, notes, and snippets.

View leon's full-sized avatar

Leon Radley leon

View GitHub Profile
@leon
leon / MyApplication.java
Last active August 29, 2015 14:18
Gradle config for spring data fowler and java 8 dates
package test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
@SpringBootApplication
// Enable java 8 dates in hibernate
@EntityScan(basePackageClasses = { MyApplication.class, Jsr310JpaConverters.class })
@leon
leon / IdNumberValidator.java
Last active March 30, 2020 10:42
Swedish Organisation number / SSN validator
package util;
import org.apache.commons.lang3.StringUtils;
public class IdNumberValidator {
// Invalid Result is used as a return value when the test fails
private static final IdNumberValidatorResult invalid = new IdNumberValidatorResult();
public static IdNumberValidatorResult validate(String value) {
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;
@leon
leon / .bash_aliases
Created August 30, 2016 07:42
Bash alias "npmd" installs both dependency and TypeScript defintion files in one go
#
# 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
@leon
leon / README.md
Last active November 30, 2021 07:58
Angular 2 SecureHttp

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 / secure-http.ts
Created November 14, 2016 14:39
secure-http angular2
import { isString } from 'lodash';
import {
Http,
ConnectionBackend,
Headers,
Request,
RequestOptions,
RequestOptionsArgs,
Response,
RequestMethod,
@leon
leon / secure-http.service.ts
Created December 30, 2016 18:47
Angular Secure HTTP Service (JWT)
import {
Http,
ConnectionBackend,
Headers,
Request,
RequestOptions,
RequestOptionsArgs,
Response,
RequestMethod,
} from '@angular/http';
@leon
leon / localstorage.service.ts
Created February 25, 2017 16:22
Angular LocalStorageService
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 / index.html
Last active May 11, 2017 11:55
Click bug in d3 v4 and zoom
<!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 / aframe-map-controls.js
Created October 7, 2017 15:18
Aframe Map Controls
/* 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.