Skip to content

Instantly share code, notes, and snippets.

View tomfa's full-sized avatar

Tomas Fagerbekk tomfa

View GitHub Profile
@tomfa
tomfa / index.html
Last active July 20, 2016 12:29
Download svg as png (or svg) with Java backend support - http://notes.webutvikling.org/converting-svg-to-png-with-javascript/
<form method="POST" action="http://localhost:2222/rest/download/png" onSubmit="getSvg(this)">
<input type="hidden" value="" name="data" type="text" />
<button type="submit">GO</button>
</form>
<div class="svg-wrapper">
<svg height="140" width="500">
<ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>
</div>
@tomfa
tomfa / actions.js
Created August 3, 2016 17:06
Redux API middleware: Presuming one is already logged in
import { CALL_API } from 'api';
import * as type from './types';
const USERS_URL = '/users';
export const getUsers = () => {
return {
[CALL_API]: {
url: USERS_URL,
authenticated: true,
@tomfa
tomfa / snsToSlack.js
Last active May 12, 2022 10:14 — forked from terranware/snsToSlack.js
AWS Lambda function SNS -> Slack Channel
var https = require('https');
var util = require('util');
var CHANNEL = "#aws-sns";
var PATH = "/services/your-slack-webhook-url-info-goes-here";
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
@tomfa
tomfa / policy
Created September 3, 2016 14:24
AWS Policy for Lambda to Slack logging
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@tomfa
tomfa / cwlogsSlack.js
Last active July 31, 2022 14:30
AWS Lambda function CloudWatch Logs -> Slack
var aws = require('aws-sdk'),
https = require('https'),
zlib = require('zlib'),
util = require('util');
// If you've used KMS to encrypt your slack, insert your CiphertextBlob here
var ENCRYPTED_URL = 'AQEC1423...';
// IF NOT, you can take the risk to insert your Slack URL here
// e.g. '/services/QWERTY/ASDFGHJ/zxYTinNLK';
@tomfa
tomfa / prerequisites.sh
Created September 14, 2016 11:05
Autorelad webpage every 5 min (Debian)
sudo apt-get install xdotool
sudo apt-get install iceweasel
@tomfa
tomfa / googleAnalyticsUtils.js
Last active September 25, 2016 13:02
Using Google Analytics in React Redux
/*
Getting Google Analytics ID from environment variable GA_ID
This should be set on the form UA-8401XXXX-X and can be set by:
1) in package.json under "scripts": {
"start": "GA_ID=UA-8401XXXX-X node server.js"
}
2) In webpack, under plugins:
new webpack.EnvironmentPlugin([ 'API_URL', 'GA_ID' ])
@tomfa
tomfa / AWSElasticBeanstalkMulticontainerDocker
Last active February 13, 2020 14:30
Beanstalk EC2 instance profile policies
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ECSAccess",
"Effect": "Allow",
"Action": [
"ecs:Poll",
"ecs:StartTask",
"ecs:StopTask",
@tomfa
tomfa / AWSElasticBeanstalkEnhancedHealth
Created October 16, 2016 14:03
Beanstalk service role policies
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"elasticloadbalancing:DescribeInstanceHealth",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetHealth",
"ec2:DescribeInstances",
@tomfa
tomfa / BeanstalkViaTerraform
Last active March 15, 2022 07:51
Adding Beanstalk roles with Terraform
resource "aws_iam_instance_profile" "beanstalk_service" {
name = "beanstalk-service-user"
roles = ["${aws_iam_role.beanstalk_service.name}"]
}
resource "aws_iam_instance_profile" "beanstalk_ec2" {
name = "beanstalk-ec2-user"
roles = ["${aws_iam_role.beanstalk_ec2.name}"]
}