Skip to content

Instantly share code, notes, and snippets.

View elnygren's full-sized avatar

el3ng elnygren

  • Helsinki, Finland
View GitHub Profile
@elnygren
elnygren / Dockerfile
Created August 28, 2017 18:42
Tactforms.com API (just some interesting bits & pieces, lots of boring parts redacted)
FROM node:8.4.0
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package.json .
COPY package-lock.json .
RUN npm install
@elnygren
elnygren / crypto.py
Last active September 27, 2017 07:12
Python goodies (functional helpers, sane logging, etc)
#!/usr/bin/python
from subprocess import Popen, PIPE
def crypt(enc, data, secret_key):
"""Encrypt/decrypt with OpenSSL"""
mode = "-e" if enc else "-d"
data = data if enc else data+'\n'
command = ["openssl", "enc", mode, "-base64", "-aes-256-cbc", "-salt", "-k", secret_key]
p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
@elnygren
elnygren / authentication.py
Created June 2, 2017 13:32
Django Rest Framework custom authorization header
"""
[API] uses the DRF TokenAuthentication with one customisation:
Token is read from 'X-Mirror-Authorization' instead of the 'Authorization' header.
Unfortunately, this is not a simple setting in DRF so we need to override the
contents of get_authorization_header and TokenAuthentication.authenticate.
You may refer to:
https://github.com/encode/django-rest-framework/blob/master/rest_framework/authentication.py
@elnygren
elnygren / minimum_viable_module.py
Last active April 26, 2017 19:02
Minimum Viable Ansible Module
from ansible.module_utils.basic import *
module = AnsibleModule(
argument_spec=dict(
state=dict(choices=['present', 'absent'], default='present'),
)
)
# do something fancy here
module.exit_json(changed=True, msg='it was a great success')
@elnygren
elnygren / react-intro-pre.md
Last active April 21, 2017 12:17
React intro by Fastdevco & Emblica pre-material

React-intro is an intro level course to React programming. Before you arrive to the event we'd like you to take care of some basic things:

  • install Node.js (preferably the most recent LTS version)
  • install npm
  • install webpack (we are using webpack 2)
  • any easy static web server (python2 or python3 has a good one for this course)

!! this is NOT a comprehensive guide, please refer to search engines and online tutorials if you encounter problems !!

@elnygren
elnygren / ansible_module.py
Created April 15, 2017 13:10
Ansible module boilerplate
DOCUMENTATION = '''
---
module: boilerplate
short_description: This is an example boilerplate module.
description:
- Boilerplate ansible module
- Use as a base for building your own modules and learning about how ansible modules work.
author: "Elias Nygren (@elnygren)"
options:
state:
@elnygren
elnygren / nginx.conf
Last active June 30, 2018 08:52
Nginx SSL, security and SEO configuration reference
# Configure to suit your needs,
# this won't work copypasted and requires a pretty new nginx version.
# don't leak software versions
server_tokens off;
proxy_hide_header X-Powered-By;
# Security Headers
# https://securityheaders.io
@elnygren
elnygren / infra_destroy.py
Created March 20, 2017 22:09
Destroy all VMs on UpCloud in parallel
"""
I use this for DevOps.
...ya know, when you test stuff, and need to bring everything down after.
"""
import os
import upcloud_api
import multiprocessing
manager = upcloud_api.CloudManager(os.environ.get('UPCLOUD_API_USER'), os.environ.get('UPCLOUD_API_PASSWD'))
@elnygren
elnygren / s3_cors
Created March 20, 2017 17:31
S3 Cors settings
echo "
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>http://www.example1.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
@elnygren
elnygren / open_ssl.sh
Last active January 24, 2017 11:39
Open SSL tips
# verify SSL of a running system on Heroku, AWS etc. before pointing DNS there
openssl s_client -connect domain.com.somedns.com:443 -servername www.example.com
# verify a chain before uploading
certs openssl verify chain.cer
> chain.cer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Global Root CA
> error 18 at 0 depth lookup:self signed certificate # this is expected
> OK # we're ok!