Skip to content

Instantly share code, notes, and snippets.

View codecitizen's full-sized avatar

amp codecitizen

  • Alexander Partsch
  • Vienna, Austria
View GitHub Profile
@codecitizen
codecitizen / issue387.clj
Created July 20, 2020 10:50
PF.tv Issue 387 Challenge
(ns issue387
(:require [clojure.string :as s]))
(defn asterisks [word]
(apply str (repeat (.length word) "*")))
(defn clean-word [sample word]
(s/replace sample (re-pattern (str "(?i)" word)) (asterisks word)))
(defn clean [sample index]
@codecitizen
codecitizen / ValidjacksonspringApplication.java
Created February 24, 2020 11:56
Example of using the `@Size` Annotation with Spring and Jackson.
package com.docutools.demo.validjacksonspring;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
// POST /trigger { path: "" }
module.exports.trigger = async (event, context) => {
const id = uuid();
await stepfunctions.startExecution({
stateMachineArn: process.env.STATE_MACHINE_ARN,
input: JSON.stringify(event.body),
name: id
});
@codecitizen
codecitizen / list-classes-from-jar.clj
Created November 25, 2018 12:48
How to list all classes from JAR file in Clojure.
(ns list-classes-from-jar
(:import (java.util.jar JarFile)))
(def jar-file (JarFile. "target/s3-file-upload-sls-1.0.0-SNAPSHOT-standalone.jar"))
(def entries (.entries jar-file))
(while (.hasMoreElements entries)
(let [entry (.nextElement entries)]
(println (.getName entry))))
@codecitizen
codecitizen / serverless.yml
Created November 23, 2018 14:52
AWS Step Functions with Serverless Example, including Re-Try policy, Parallel Execution and Error Handling.
service: aws-step-functions-showcase
provider:
name: aws
runtime: nodejs8.10
iamRoleStatements:
- Effect: "Allow"
Action:
- "states:StartExecution"
Resource:
@codecitizen
codecitizen / serverless.yml
Created November 22, 2018 20:42
A serverless.yml file configuring a AWS ElastiCache redis instance that is accessible by all AWS Lambda functions deployed by this serverless function.
service: my-service
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
environment:
REDIS_HOST:
"Fn::GetAtt": [ElasticCacheCluster, RedisEndpoint.Address]
functions:
@codecitizen
codecitizen / pprint-members.py
Created April 25, 2018 14:54
Pretty print a python objects members.
import pprint
import inspect
pp = pprint.PrettyPrinter(depth=6)
pp.pprint(inspect.getmembers(myObject))
var saml2 = require('saml2-js');
const fs = require('fs');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: true
}));
@codecitizen
codecitizen / AuthorizationServerConfig.java
Created January 10, 2017 13:59
Buggy OAuth2 Spring Security Authorization Server Configuration
package com.myapp.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
@codecitizen
codecitizen / exponential_backoff.clj
Created December 5, 2016 09:55
Exponential Backoff in Clojure
(def time-slot-ms 52)
(def truncate 10)
(defn ** [b e]
(reduce * (repeat e b)))
(defn with-exp-backoff [action!]
(loop [c 0]
(let [slot (* time-slot-ms (dec (** 2 c)))]
(println "Sleeping for " slot "ms.")