Skip to content

Instantly share code, notes, and snippets.

View onnimonni's full-sized avatar

Onni Hakala onnimonni

View GitHub Profile
@onnimonni
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
end
end
class S3File
<?php
/**
* 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
onnimonni / append-only-s3.tf
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
onnimonni / curl.txt
Created October 26, 2017 13:00
Metabase redirect problem
$ curl -i https://www.metabase.com/docs/
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
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".upcase.chars.map { |d|
d.match(/[A-Z]/) ? (d.ord - 55).to_s : d
}.join.to_i
# Calculate checksum with reverse modulo
@onnimonni
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 https://get.rvm.io | bash -s stable --ruby
Downloading https://github.com/rvm/rvm/archive/1.29.2.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.2/1.29.2.tar.gz.asc
gpg: Signature made Thu Jun 22 19:18:38 2017 EEST using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
gpg: aka "Michal Papis <michal.papis@toptal.com>" [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
onnimonni / terraform_digitalocean_dokku.tf
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
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
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.
#!/bin/bash
##
# 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
# - It needs following env: SMTP_HOST, SMTP_PASSWORD, SMTP_PORT, SMTP_AUTH, SMTP_USER
##
# This script gives itself as a parameter for msmtp