Skip to content

Instantly share code, notes, and snippets.

View onnimonni's full-sized avatar

Onni Hakala onnimonni

View GitHub Profile
onnimonni / s3_secure_file.rb
Created December 29, 2017 17:27
Ruby script to upload versioned private files to s3 bucket and to retrieve their presigned_url. This can be used to achieve append only file uploads which can't be deleted easily.
require 'aws-sdk-s3'
# When there's something wrong with the s3
class S3StorageError < StandardError
def initialize(data)
@data = data
class S3File
* Add REST API support to an already registered post type.
add_action( 'init', 'rata_post_type_rest_support', 25 );
function rata_post_type_rest_support() {
global $wp_post_types;
// Be sure to set this to the name of your post type!
$post_type_name = 'rata';
onnimonni /
Created November 17, 2017 10:46
Poor mans append-only bucket with terraform - versioned s3 bucket without delete access
# Asks the bucket name
variable "aws_bucket_name" {}
provider "aws" {
alias = "west"
region = "eu-west-1"
onnimonni / curl.txt
Created October 26, 2017 13:00
Metabase redirect problem
$ curl -i
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 426
Connection: keep-alive
Date: Thu, 26 Oct 2017 10:20:14 GMT
Last-Modified: Wed, 04 Oct 2017 01:39:52 GMT
ETag: "e377a2b0a454fded1058c86690d70473"
Server: AmazonS3
Age: 9573
onnimonni / iban_generator.rb
Last active October 21, 2017 10:50
Ruby class for generating valid fake IBAN numbers for testing
# Module for generating random Iban account numbers
module IBAN
# Calculates the mandatory checksum of 3..4 characters in iban
def iban_checksum(account, cc)
# Converts letters to numbers according the iban rules, A=10..Z=35
iban_to_num = "#{account}#{cc}00" { |d|
d.match(/[A-Z]/) ? (d.ord - 55).to_s : d
# Calculate checksum with reverse modulo
onnimonni / finnish_bank_reference.rb
Last active January 5, 2018 14:14
Finnish bank reference calculator in ruby
# Array#sum is needed for nice code outside rails projects
require 'active_support'
require 'active_support/core_ext'
# Module for creating valid Finnish bank references
module FinnishBankRefence
# Generates reference from a input or a random number
def self.generate( base = rand(10**3..(10**19-1)) )
if base < 10**3 or base >= 10**19
$ curl -sSL | bash -s stable --ruby
gpg: Signature made Thu Jun 22 19:18:38 2017 EEST using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <>" [unknown]
gpg: aka "Michal Papis <>" [unknown]
gpg: aka "[jpeg image of size 5015]" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3
onnimonni /
Created June 28, 2017 14:41
Example terraform config for creating a digitalocean droplet with volume.
variable "digitalocean_token" {
description = "This is the Digitalocean API-token which is used to setup the machines."
variable "digitalocean_region" {
description = "For example: nyc1, nyc2, ams2, ams3, fra2"
default = "fra1"
variable "digitalocean_dokku_size" {
description = "Instance size: 512mb, 1gb, 2gb, 4gb ..."
default = "2gb"
onnimonni / 0_reuse_code.js
Created June 9, 2017 08:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
onnimonni / sendmail
Last active May 29, 2017 19:33
msmtp wrapper which acts like sendmail and reads configs from envs. Useful in php docker containers to ensure that all mail() calls are working.
# This is custom wrapper for msmtp which acts like good old sendmail
# - It is used for php and cron
# - This is easier to configure for external mail server than sendmail
# - sendmail is just the default binary which other services will use
# This script gives itself as a parameter for msmtp