Skip to content

Instantly share code, notes, and snippets.

@aSemy
aSemy / WebSecurityConfig.java
Last active May 30, 2018 14:29
EnableGlobalMethodSecurity
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// ...
}
@aSemy
aSemy / PreAuthorize.java
Created May 30, 2018 14:29
getMeterReadings PreAuthorize
@GraphQLQuery(name = "getMeterReadings")
@PreAuthorize("isAuthenticated()")
public TreeSet<MeterReadingDTO> getMeterReadings(
// ...
}
@aSemy
aSemy / CookieCsrfTokenRepository.java
Last active May 30, 2018 14:38
CookieCsrfTokenRepository
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
final CsrfTokenRepository csrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
http
@aSemy
aSemy / Rules.java
Last active June 1, 2018 14:28
A couple of utils for GraphQL validation rules
// Rule.java
public abstract class Rule
implements BiFunction<FieldAndArguments, FieldValidationEnvironment, Optional<Collection<GraphQLError>>> {
}
// RuleSingle.java
public abstract class RuleSingle extends Rule {
@Override
public final Optional<Collection<GraphQLError>> apply(FieldAndArguments fieldAndArguments,
@Service
public class GraphQLRuleService {
// fetches messages from appropriate .prop file
@Autowired
private final MessagesService messagesService;
public RuleSingle stringNonBlank(final String argumentName, final String fieldName) {
return new RuleSingle() {
@Override
public Optional<GraphQLError> applySingle(FieldAndArguments fieldAndArguments, FieldValidationEnvironment environment) {
@Autowired
public GraphQlSampleController(final GraphQLRuleService ruleService) {
// Schema generated from query classes
GraphQLSchema schemaFromAnnotated = new GraphQLSchemaGenerator()//
// setup the schema
// ...
.generate();
// set up field validation
@Component
public class UserRegisterMutator {
public static final String REGISTER_ARGUMENT_NAME = "userRegisterRequest";
/**
* @param userRegisterRequest Contains info about the user's registration, e.g. their name
*
* @return Always returns true, so potential attackers get no info. Valid attempts will get an email.
*/
public static Set<Rule> getRules(final GraphQLRuleService ruleService) {
final Set<Rule> rules = new HashSet<>();
// validate name not blank
rules.add(ruleService.stringNonBlank(UserRegisterMutator.REGISTER_ARGUMENT_NAME, "name"));
return rules;
}
@aSemy
aSemy / !Hide Dropbox icon in Windows 10 taskbar notification area README.md
Last active October 20, 2021 11:01
Hide Dropbox icon in Windows 10 taskbar notification area

Hide Dropbox icon in Windows 10 taskbar notification area

Stop the Dropbox icon from re-appearing in the Windows 10 taskbar notification area.

Dropbox icon in the Windows 10 taskbar tray icons

Every time Dropbox updates it overrides my preference and moves its icon from the 'hidden' icons to the always-visible icons.

I've written hide_dropbox_icon.ps1, a Powershell script that will undo this forced option, and make the Dropbox icon hidden.

@aSemy
aSemy / kjs_type_union_properties.md
Last active May 7, 2024 13:59
Kotlin/JS TypeUnion properties

Hot new strat for defining type-union properties in Kotlin/JS

Demo

// SomeConfig is an external TypeScript interface
// it has a property with a type-union type, but don't implement it as a member...
external interface SomeConfig {
  // multiProp: number | string | Extension | ((string) => Extension | null)
}