Skip to content

Instantly share code, notes, and snippets.

View serban-petrescu's full-sized avatar

Serban Petrescu serban-petrescu

View GitHub Profile
@serban-petrescu
serban-petrescu / simpleTA.xsjs
Last active October 1, 2018 10:11
HANA XSC Simple TA Service
function sentiment(sentiment) {
if (sentiment && sentiment.label) {
switch(sentiment.label) {
case "StrongNegativeSentiment":
case "StrongNegativeEmoticon":
return {
startIndex: sentiment.offset,
endIndex: sentiment.offset + sentiment.text.length,
text: sentiment.text,
type: "NEGATIVE",
@serban-petrescu
serban-petrescu / exportDependencies.sh
Created March 19, 2018 20:06
Bash shell which builds a .csv file with all maven dependencies from a folder structure
for D in ` find . -maxdepth 2 -type f -name 'pom.xml' | sed -r 's|/[^/]+$||' | sort -u`
do
(cd $D && mvn -o dependency:tree |
grep -E ":.*:.*:(compile|test)" |
sed "s,\[INFO\] \(.\)[ |\\+-]*\([^:]*\):\([^:]*\):[^:]*:[^:]*:\([^:]*\),\1;\2;\3;\4,g" |
sed "s,[ |];,transitive;,g" |
sed "s,[+\\];,direct;,g")
done | sort -u | (echo "type;group;artefact;scope" && cat)
@serban-petrescu
serban-petrescu / DemoApplication.java
Last active May 21, 2018 13:06
SAP CF Logging Async Servlet bug
package com.example.demo;
import com.sap.hcp.cf.logging.servlet.filter.RequestLoggingFilter;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.tomcat.util.descriptor.web.FilterDef;
import org.apache.tomcat.util.descriptor.web.FilterMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@serban-petrescu
serban-petrescu / settings.xml
Last active June 11, 2018 04:23
.msg Maven proxy settings (just copy this file in your %USER_HOME%/.m2 folder)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<proxies>
<proxy>
<id>http</id>
const database = new rds.DatabaseInstance(this, 'example', {
engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_11 }),
vpc: ec2.Vpc.fromLookup(this, 'vpc', { isDefault: true }),
credentials: rds.Credentials.fromGeneratedSecret('admin'),
// other RDS instance properties
});
database.addRotationSingleUser({
automaticallyAfter: cdk.Duration.days(8 * 7),
excludeCharacters: '!@#$%^&*'
@serban-petrescu
serban-petrescu / Policy.json
Last active May 29, 2021 10:51
AWS MFA Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyAllExceptListedIfNoMFA",
"Effect": "Deny",
"NotAction": [
"iam:ChangePassword",
"iam:GetAccountPasswordPolicy",
"iam:CreateVirtualMFADevice",
@serban-petrescu
serban-petrescu / bw-aws.ps1
Last active May 29, 2021 16:21
BW-AWS: Unlock
function Unlock-Bw() {
$status = bw status | ConvertFrom-Json
if ($status.status -eq "locked") {
$password = (Get-Credential "Bitwarden").GetNetworkCredential().Password
$session = bw unlock $password --raw
$env:BW_SESSION = $session
}
}
# and later on, to wipe the session
@serban-petrescu
serban-petrescu / bw-aws.ps1
Last active May 29, 2021 15:46
BW-AWS: Get creds
function Find-BWField() {
param ($item, $name)
[Array]::Find($item.fields, [Predicate[Object]] { $args[0].name -eq $name }).value
}
$item = bw get item $id | ConvertFrom-Json
$account = Find-BWField -item $item -name "ACCOUNT"
$keyId = Find-BWField -item $item -name "ACCESS_KEY_ID"
$secretKey = Find-BWField -item $item -name "SECRET_ACCESS_KEY"
@serban-petrescu
serban-petrescu / bw-aws.ps1
Last active May 29, 2021 16:03
BW-AWS: Cache
$path = ".\$($id).xml" #id = BW item name
function Write-Cache() {
param ($value)
$secure = ConvertTo-SecureString -AsPlainText -Force -String $value
$obj = New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList "myusername", $secure
return $obj | Export-Clixml $path
}
@serban-petrescu
serban-petrescu / bw-aws.ps1
Last active May 29, 2021 16:24
BW-AWS: MFA
if ((Find-BWField -item $item -name "IS_ROOT") -eq "true") {
$mfaArn = "arn:aws:iam::$($account):mfa/root-account-mfa-device"
} else {
$mfaArn = "arn:aws:iam::$($account):mfa/$($item.login.username)"
}
if ($item.login.totp) {
$token = bw get totp $id
$result = aws sts get-session-token --serial-number $mfaArn --token-code $token `
--duration-seconds $sessionLifetime | ConvertFrom-Json