Skip to content

Instantly share code, notes, and snippets.

@codemartial
codemartial / flickr.html
Last active April 13, 2023 09:59
Awesomest Hugo shortcode for Flickr photos. Responsive images, EXIF data, custom titles 👍
{{/*
Flickr shortcode for Hugo
Usage: {{< flickr photo_url="https://www.flickr.com/photos/username/1234567890" title="Photo title" >}}
Parameters:
photo_url: URL of the photo on Flickr
title: Title of the photo
caption: Caption of the photo (disables EXIF info)
href: URL of the link (overrides photo_url)
Output:
<figure>
@codemartial
codemartial / exiftool-examples.md
Last active May 31, 2021 02:56
A collection of exiftool recipes from my usage

Exiftool Examples

Following is a collection of real exiftool commands that I've used, along with explanations of what each does. exiftool is a command-line utility that provides very powerful EXIF reading, writing and searching capabilities.

I'm writing this down because I often spend a lot of time reading through exiftool documentation to find out how to get something done, just to forget it within hours. All of these examples work on a Unix shell environment like ZSH on MacOS or the various Linux shells.

Extracting EXIF Information

What does EXIF data look like? Let's try the following on an image file, DSC09535.JPG:

@codemartial
codemartial / redis-worker.go
Created April 17, 2018 05:53
A worker pool for executing Redis commands using redigo
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
"sync"
"time"
)
var rconns *redis.Pool
@codemartial
codemartial / ccf.go
Last active April 24, 2018 12:02
Co-ordinated Cache Filling using Redis Distributed Locks
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
redsync "gopkg.in/redsync.v1"
"sync"
"sync/atomic"
"time"
)
@codemartial
codemartial / bebo.go
Created February 14, 2018 11:53
Binary Exponential Back-Off Scheduler in Go
// BEBOSchedule computes a Binary Exponential Back-Off schedule given the following:
// retries: maximum number of retry attempts
// waittime: maximum number of seconds from the first attempt after which the operation is permanently failed
//
// The schedule is returned as a list of seconds since first attempt at which a retry must be made
// The schedule will have as many entries as the maximum number of attempts given
func BEBOSchedule(retries, waittime int) ([]uint, error) {
if retries <= 0 || waittime <= 0 || waittime < 1<<uint(retries)-1 {
return []uint{}, fmt.Errorf("Invalid retries or waittime")
@codemartial
codemartial / wald.go
Last active November 25, 2017 02:57
Table of minimum percentages estimated using Adjusted Wald Method at 99% confidence
package main
import (
"fmt"
"math"
)
func max(l, r float64) float64 {
if l > r {
return l
@codemartial
codemartial / ErrorHandling.md
Last active September 22, 2017 08:54
3 Principles of Error Handling

Error Handling 1-2-3

As we build infrastructure components that support a large user base, it becomes critical to be able to provide quick support to end users. A large chunk of support issues simply arise due to end users encountering an error that they are clueless about. E.g. an HTTP 500 error with a generic "failed to do " message leads the user to a dead end and causes frustration.

Apart from clear messaging to the end user, it's also important to provide maximum visibility into error logs, so that someone who is looking at the logs should be able to determine – even without being familiar with the system – whether the cause of the error is internal or external. This is extremely critical in high utilisation network applications because usually the source of error is an external failure rather than a code bug.

As an example of very poor logging, the other day I logged into a service backend hoping to find some trace of user reported issues in the error logs. After filtering out all

@codemartial
codemartial / etcmutex.go
Created March 23, 2017 06:35
etcd Mutex experimentation
package main
import (
"context"
"fmt"
etcc "github.com/coreos/etcd/clientv3"
etcsync "github.com/coreos/etcd/clientv3/concurrency"
"time"
)
@codemartial
codemartial / etcdw.go
Last active February 27, 2017 08:52
A basic checkpointing watcher for etcd.
package main
import (
"context"
"fmt"
etcc "github.com/coreos/etcd/clientv3"
"strconv"
"time"
)
@codemartial
codemartial / dfs.go
Created November 15, 2016 10:37
A distributed filesystem prototype
package main
import (
"bytes"
"fmt"
"sync"
"strings"
)
// Stores the filesystem hierarchy, data node members and their capacity