Skip to content

Instantly share code, notes, and snippets.

View elnygren's full-sized avatar

el3ng elnygren

  • Helsinki, Finland
View GitHub Profile
@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 / 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
const Koa = require('koa')
const app = new Koa()
const _ = require('koa-route')
const bodyParser = require('koa-bodyparser')
const R = require('ramda')
const uuidv4 = require('uuid/v4')
const moment = require('moment')
const cors = require('koa-cors')
const {sendVerificationEmail} = require('./src/email.js')
/*
We're using Redis so here's the basic boilerplate + couple queries.
*/
const config = require('./config')
const redis = require('redis')
const bluebird = require('bluebird')
// don't leave home with out bluerbird's promisify ! (Made in Finland <3)
bluebird.promisifyAll(redis.RedisClient.prototype)
bluebird.promisifyAll(redis.Multi.prototype)
const config = require('./config')
const mailgun = require('mailgun-js')({apiKey: config.MAILGUN_API_KEY, domain: config.MAILGUN_DOMAIN})
// poor man's email templating
const VERIFICATION_EMAIL = (forwarder, secret) => `Hi,
To verify your Tactforms.com form, click this link:
https://tactforms.com/api/secret/${forwarder}/${secret}
Your form's secret url is:
@elnygren
elnygren / Dockerfile
Created August 28, 2017 20:21
Node.js Dockerfile
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 / site.conf
Created August 28, 2017 20:26
Nginx example
server {
listen 443 ssl http2;
server_name example.com;
root /srv/example.com;
index index.html index.htm;
# for Staging, create .htpasswd with:
# https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-nginx-on-ubuntu-14-04
# auth_basic "Restricted Content";
@elnygren
elnygren / Dockerfile
Last active November 28, 2019 09:28
Homework: Django-React-Docker
FROM python:3.6
WORKDIR /app/
# move requirements.txt
# install deps
# copy rest of code
@elnygren
elnygren / reactjr.js
Created September 14, 2017 07:40
React junior interview
// tehtävä
// make the following code "better"
// with map, filter, reduce, ES6
var arr = [1,2,3,4,5,6]
var sum = 0
var newArr = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) {
@elnygren
elnygren / README.md
Last active September 27, 2017 07:14
IntelliJ bindings that make sense (benchmarked from Sublime Text and Atom)

Better IntelliJ editing/coding experience

Let's face it. Sublime Text is the de facto industry leader when it comes to editing and coding. However, many people like to have an IDE for additional features.

This is a guide to setting up IntelliJ/PyCharm the way it should be.

Note: There are some premade Atom/ST bindings, but this is doing it the hard way - so you know what's going on.

Keybinds