Skip to content

Instantly share code, notes, and snippets.

@halkyon
halkyon / index.php
Last active Jun 8, 2022
Test AWS SDK PHP v3 Storj
View index.php
<?php
//
// Test script to see if AWS SDK PHP works as expected with Storj gateway.
//
// Assuming a working PHP and Composer setup:
//
// 1. Copy this file to an empty dir.
// 2. Run `composer require aws/aws-sdk-php`.
// 3. Configure credentials: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html
@halkyon
halkyon / main.go
Last active Jun 14, 2022
share file programatically using storj linksharing service
View main.go
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/pkg/errors"
"storj.io/uplink"
View s3_put_object_storj.js
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
// generate credentials with:
// uplink share --readonly=false --not-after +1h --register sj://mybucket/7702ec60-62ac-11ec-be04-7d227eabec45/ --auth-service=https://auth.us1.storjshare.io --access MYACCESS
const accessKeyId = ""
const secretAccessKey = ""
const endpoint = "https://gateway.us1.storjshare.io"
const s3Client = new S3Client({
credentials: {
@halkyon
halkyon / main.go
Created Nov 11, 2021
multipart upload programatically in Go
View main.go
package main
import (
"bytes"
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
@halkyon
halkyon / install.md
Last active Jun 3, 2021
BeDrive docker installation
View install.md
  1. Unzip the website.zip file provided by BeDrive somewhere
  2. Replace docker-compose.yml with the following:
version: "3"
services:
  web:
    build: . 
    depends_on:
      - mariadb
@halkyon
halkyon / digitalocean_saltcloud_vpc.patch
Last active Sep 7, 2020
Patch for salt-cloud digitalocean integration to support setting VPC for private networking
View digitalocean_saltcloud_vpc.patch
--- /usr/lib/python3/dist-packages/salt/cloud/clouds/digitalocean.py 2020-09-07 11:02:31.000000000 +1200
+++ /usr/lib/python3/dist-packages/salt/cloud/clouds/digitalocean_new.py 2020-09-07 11:04:47.000000000 +1200
@@ -357,6 +357,11 @@
if not isinstance(private_networking, bool):
raise SaltCloudConfigError("'private_networking' should be a boolean value.")
kwargs['private_networking'] = private_networking
+ vpc_uuid = config.get_cloud_config_value(
+ "vpc_uuid", vm_, __opts__, search_global=False, default=None,
+ )
+ if vpc_uuid is not None:
@halkyon
halkyon / flac-to-mp3.php
Created Aug 27, 2020
FLAC to MP3 converter command line tool in PHP
View flac-to-mp3.php
#!/usr/bin/php
<?php
##
## Extract a zip containing FLAC files, or a directory of FLAC files,
## and encode them into MP3 using LAME.
##
## Requirements (make sure these are in your path):
## - php (5.3+, required to run this script)
## - flac (for decoding FLAC to WAV)
@halkyon
halkyon / ghost-blog-kubernetes.yaml
Last active Jul 15, 2020
Kubernetes YAML (namespace, service, ingress, deployment) for running a very simple setup of Ghost (https://github.com/TryGhost/Ghost)
View ghost-blog-kubernetes.yaml
# Simple setup of Ghost in Kubernetes.
#
# Some points to consider:
# - Content is stored in a single persistent disk, and database is SQLite. Using a dedicated database would be ideal
# for bigger deployments, and using distributed storage would allow pods to horizontally scale, e.g. GlusterFS, EFS.
#
# - A load balancer is provisioned for external traffic to access the blog service. For a multi-tenanted approach,
# nginx ingress controller (https://kubernetes.github.io/ingress-nginx/deploy/) could be used.
#
# - No TLS for the service. This could be accomplished using GCP, or AWS managed certs on the load balancer.
@halkyon
halkyon / interface.go
Last active Mar 15, 2020
Simple example of an interface in Go using a "loader" interface with memory and disk as implementations
View interface.go
package main
import (
"fmt"
"io/ioutil"
"os"
)
type loader interface {
Read() ([]byte, error)
@halkyon
halkyon / linked-list.go
Last active Mar 15, 2020
Simple example of a circular doubly linked list in Go
View linked-list.go
package main
import (
"fmt"
)
type list struct {
head *item
tail *item
}