Skip to content

Instantly share code, notes, and snippets.

View onnimonni's full-sized avatar

Onni Hakala onnimonni

View GitHub Profile
@onnimonni
onnimonni / replace-action-tags-with-revs.sh
Last active March 16, 2025 21:39
Replace git tags in GitHub Actions with commit hashes
#!/bin/sh
# Replace version tags with commit hashes in github actions workflows
# Example: "uses: actions/checkout@v4"
# -> "uses: actions/[email protected] #v4"
for workflow in .github/workflows/*.yml; do
grep -E "uses:[[:space:]]+[A-Za-z0-9._-]+/[A-Za-z0-9._-]+@v[0-9]+" "$workflow" | while read -r line; do
repo=$(echo "$line" | sed -E 's/.*uses:[[:space:]]+([A-Za-z0-9._-]+\/[A-Za-z0-9._-]+)@v[0-9]+.*/\1/')
tag=$(echo "$line" | sed -E 's/.*@((v[0-9]+)).*/\1/')
commit_hash=$(git ls-remote "https://github.com/$repo.git" "refs/tags/$tag" | cut -f1)
@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) <[email protected]>" [unknown]
gpg: aka "Michal Papis <[email protected]>" [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