Skip to content

Instantly share code, notes, and snippets.

View codecitizen's full-sized avatar

amp codecitizen

  • Alexander Partsch
  • Vienna, Austria
View GitHub Profile
<add path="report.pdf" verb="GET" type="Subcontractor_Module.Handlers.GetPdfReport" name="pdf_report_handler"
resourceType="Unspecified" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness32" />
<add path="report.pdf" verb="GET" type="Subcontractor_Module.Handlers.GetPdfReport" name="pdf_report_handler64"
resourceType="Unspecified" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness64" />
@codecitizen
codecitizen / LocalDateTimePersistenceConverter.java
Created November 15, 2016 15:28
JPA Attribute Converter for java.time.LocalDateTime to java.sql.Instant
package com.github.gist.codecitizen.jpa.converters;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
* Maps {@link java.time.LocalDateTime} entity attributes to {@link java.sql.Timestamp} values
* so a temporal value instead of {@code bytea} is written to the database.
@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.")
@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;
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 / 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))
@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 / 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 / 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))))
// 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
});