Skip to content

Instantly share code, notes, and snippets.

View leon's full-sized avatar

Leon Radley leon

View GitHub Profile
@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 / 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 / .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
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 / 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) {
@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 / Dockerfile
Created November 16, 2014 15:07
docker java 8
#
# - install jdk8 from oracle
#
RUN apt-get install -y python-software-properties software-properties-common
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer
@leon
leon / README.md
Created September 25, 2014 09:35
Convert all files to utf-8

Use with causion

Sometimes the script fails to convert and spits out an empty file instead.

@leon
leon / README.md
Created February 4, 2014 09:49
angularjs $q decorator for spread

Use it like this

$q.all([ promise1, promise2 ]).then($q.spread(function (promise1Result, promise2Result) {

});

package actions
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
import javax.persistence._
import play.db.jpa.JPAPlugin
import play.api.Play
import play.api.mvc.SimpleResult
class EntityManagerRequest[A](val em: EntityManager, request: Request[A]) extends WrappedRequest[A](request)