Skip to content

Instantly share code, notes, and snippets.

View ppanyukov's full-sized avatar

Philip Panyukov ppanyukov

  • UK
View GitHub Profile
@ppanyukov
ppanyukov / string_hacks.go
Created November 7, 2019 13:25
Go Hacks for Performance and Fun
package main
import (
"fmt"
"unsafe"
)
// A demo of things you can do with strings and []byte slices
// in a dangerous and exciting ways. I got here by having to verify
// if two given strings point to the same storage in memory.
@ppanyukov
ppanyukov / p4changes.sh
Created June 20, 2011 10:36
Print Perforce commit stats by user between two specified dates
#!/bin/bash
#
# A kind of an alias support for the Perforce p4.
#
# This one aliases "interchanges" and "changes" commands to be printed out nicely in format:
#
# Change <change_no> on <date> by <user>@<workspace> [<status>]
# <first line of change description>
# --
# Change <change_no> on <date> by <user>@<workspace> [<status>]
@ppanyukov
ppanyukov / LogAgent.fs
Created March 13, 2012 03:07
Asynchronous log writer implemented using F# agent
module LogAgent =
// Log writer implementation using F# asynchronous agents
// Written as an excersise
open System
open System.IO
type private Message =
@ppanyukov
ppanyukov / dump_headers.go
Last active February 8, 2023 15:26
Simple web server in golang to dump to echo requests
package main
import (
"fmt"
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
var formatted, err = httputil.DumpRequest(r, true)
@ppanyukov
ppanyukov / gist:1051835
Created June 28, 2011 18:38
F# function to join sequence of strings using a delimiter without conversion to array
open System
open System.Text
/// Join a sequence of strings using a delimiter.
/// Equivalent to String.Join() but without arrays.
let join (items : seq<string>) (delim : string) =
// Collect the result in the string builder buffer
// The end-sequence will be "item1,delim,...itemN,delim"
let buff =
Seq.fold
# Shows how to get auth token for VSTS (Azure Devops) from Azure CLI.
#
# Extracted from various github projects: Azure CLI and Azure SDK for Go
# See: https://github.com/Azure/azure-sdk-for-go/blob/ca5ebc8601ba1af17b289bb42161b7afb496423f/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1#L17
# VSTS / Azure Devops resource identifier is: "499b84ac-1321-427f-aa17-267ca6975798"
organisation="your_org"
project="your_project"
@ppanyukov
ppanyukov / deployment.yaml
Created June 18, 2022 14:04
Using Docker in Kubernetes
---
# This creates a deployment where each pod has two containers:
# - Docker Server: the actual docker engine.
# - Docker Client: simple Ubuntu instance with docker cli so we can
# test the docker things. In practice this would be some CI agent
# like Azure Devops agent or Jenkins or anything at all.
#
# After this deployment is created, wait for a bit for docker CLI to be installed
# in the client container. Then shell into it and use docker commands like docker build etc
# to test that things actually work.
@ppanyukov
ppanyukov / combinePdfFiles.tex
Created June 20, 2011 12:30
Combine several PDF files into one using LaTeX
% Many a time we have HTML articles published across multiple pages.
% And sometimes we want to print all those pages as one PDF.
% Here is how to do it:
% - Print into PDF from the browser into files like p01.pdf, p02.pdf etc
% - Use LaTeX to assemble these into one PDF.
%
% Here is the example. The \includepdf command supports scaling too,
% and I'm sure some other interesting commands as well.
%
% [copylifted from: http://yusung.blogspot.com/2007/02/combine-several-pdf-files-using-latex.html]
# This is a hack to obtain azurerm_user_assigned_identity data item from
# the cluster.identity object.
#
# The reason we need this is depending on the kind of identity (SystemAssigned,
# UserAssigned) we have different fields in that object. In particular if we
# have UserAssigned identity, the value of principal_id will be empty, and
# we need to assign roles to it like Network Contributor.
#
# To use:
# # Grab the cluster data item
@ppanyukov
ppanyukov / encrypt.sh
Last active September 14, 2021 06:13
Noddy script to encrypt/decrypt files using openssl private (ssh) key.
#!/usr/bin/env bash
set -eu
# Noddy script to encrypt/decrypt files using openssl private (ssh) key.
# Works with files and stdin.
# Results are stdout.
#
# Requirements:
# - openssl
# - ssh private key: ~/.ssh/id_rsa