• Stars
    star
    3,866
  • Rank 11,343 (Top 0.3 %)
  • Language
    Go
  • License
    Other
  • Created almost 13 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go Humans! (formatters for units to human friendly sizes)

Humane Units Build Status GoDoc

Just a few functions for helping humanize times and sizes.

go get it as github.com/dustin/go-humanize, import it as "github.com/dustin/go-humanize", use it as humanize.

See godoc for complete documentation.

Sizes

This lets you take numbers like 82854982 and convert them to useful strings like, 83 MB or 79 MiB (whichever you prefer).

Example:

fmt.Printf("That file is %s.", humanize.Bytes(82854982)) // That file is 83 MB.

Times

This lets you take a time.Time and spit it out in relative terms. For example, 12 seconds ago or 3 days from now.

Example:

fmt.Printf("This was touched %s.", humanize.Time(someTimeInstance)) // This was touched 7 hours ago.

Thanks to Kyle Lemons for the time implementation from an IRC conversation one day. It's pretty neat.

Ordinals

From a mailing list discussion where a user wanted to be able to label ordinals.

0 -> 0th
1 -> 1st
2 -> 2nd
3 -> 3rd
4 -> 4th
[...]

Example:

fmt.Printf("You're my %s best friend.", humanize.Ordinal(193)) // You are my 193rd best friend.

Commas

Want to shove commas into numbers? Be my guest.

0 -> 0
100 -> 100
1000 -> 1,000
1000000000 -> 1,000,000,000
-100000 -> -100,000

Example:

fmt.Printf("You owe $%s.\n", humanize.Comma(6582491)) // You owe $6,582,491.

Ftoa

Nicer float64 formatter that removes trailing zeros.

fmt.Printf("%f", 2.24)                // 2.240000
fmt.Printf("%s", humanize.Ftoa(2.24)) // 2.24
fmt.Printf("%f", 2.0)                 // 2.000000
fmt.Printf("%s", humanize.Ftoa(2.0))  // 2

SI notation

Format numbers with SI notation.

Example:

humanize.SI(0.00000000223, "M") // 2.23 nM

English-specific functions

The following functions are in the humanize/english subpackage.

Plurals

Simple English pluralization

english.PluralWord(1, "object", "") // object
english.PluralWord(42, "object", "") // objects
english.PluralWord(2, "bus", "") // buses
english.PluralWord(99, "locus", "loci") // loci

english.Plural(1, "object", "") // 1 object
english.Plural(42, "object", "") // 42 objects
english.Plural(2, "bus", "") // 2 buses
english.Plural(99, "locus", "loci") // 99 loci

Word series

Format comma-separated words lists with conjuctions:

english.WordSeries([]string{"foo"}, "and") // foo
english.WordSeries([]string{"foo", "bar"}, "and") // foo and bar
english.WordSeries([]string{"foo", "bar", "baz"}, "and") // foo, bar and baz

english.OxfordWordSeries([]string{"foo", "bar", "baz"}, "and") // foo, bar, and baz

More Repositories

1

java-memcached-client

A simple, asynchronous, single-threaded memcached client written in java.
Java
496
star
2

seriesly

A time series database.
Go
461
star
3

go-coap

Implementation of CoAP in go.
Go
341
star
4

gomemcached

A memcached binary protocol toolkit for go.
Go
316
star
5

go-probably

Probabilistic Data Structures for Go
Go
255
star
6

go-broadcast

A trivial channel pubsub I use in lots of projects.
Go
242
star
7

gitmirror

A web server to receive webhooks and mirror git repos.
Go
168
star
8

beanstalk-tools

Various tools for watching beanstalkd.
Ruby
164
star
9

py-github

Python interface for talking to the github API
Python
160
star
10

bindir

My ~/bin
Python
136
star
11

mac-zfs

Continuing where Apple left off with ZFS.
C
124
star
12

go-heatmap

Heatmap creation stuff for go.
Go
111
star
13

twitty-twister

A twisted client for twitter-like APIs.
Python
108
star
14

labrea

Scripting other people's programs.
C
104
star
15

go-wikiparse

mediawiki dump parser for loading up wikipedia data
Go
100
star
16

gopro

Tools for making the most out of GoPro Plus.
Haskell
92
star
17

twitterspy

A twitter <-> XMPP gateway with search and track and other good stuff.
Python
79
star
18

randbo

In a world of decreasing entropy, it's time to introduce some chaos.
Go
70
star
19

elock

A simple, fault-tolerant distributed lock server in erlang.
Erlang
67
star
20

go-nntp

NNTP client and server for the go language.
Go
54
star
21

ememcached

A framework for building erlang memcached servers.
Erlang
50
star
22

slosh

Lazy realtime web.
Python
44
star
23

whatsup

My web monitoring jabber bot.
Python
44
star
24

mqtt-hs

Haskell MQTT client.
Haskell
40
star
25

snippets

My junk drawer. Various things I've played with in various states.
C
38
star
26

go-jsonpointer

jsonpointer implementation for go
Go
36
star
27

beanstalk-client-ruby

Keith Rarick's ruby client for beanstalk
Ruby
35
star
28

go-rs232

RS232 / Serial interface for go
Go
34
star
29

go-aprs

APRS libs and tools for go.
Go
32
star
30

erl-conc

Concurrent Lists in Erlang
Erlang
29
star
31

logic-pwm

PWM Analyzer for Saleae Logic
C++
29
star
32

waitforsocket

A simple program to help you react more quickly to servers and services coming back online.
Nix
28
star
33

go-saturate

Double-fanout pipeline for saturating all the things.
Go
23
star
34

go-follow

Follow (tail -f) an io.Reader, blocking on EOF until more data arrive.
Go
22
star
35

logic-ws2812

Logic Analyzer plugin for WS2812 addressable LEDs.
C++
22
star
36

twisted-gears

A twisted interface to gearman.
Python
21
star
37

ruby-trie

Hacks on a ruby trie implementation from Dan Erat
Ruby
21
star
38

go-elasticsearch

Elasticsearch interface for go
Go
21
star
39

memcached-test

Python memcached binary protocol client and server (used primarily for testing and protocol experimentation).
Python
21
star
40

gopro-plus

GoPro Plus cloud service interface in Haskell.
Haskell
20
star
41

frames

A simple channeling protocol.
Go
19
star
42

ruby-freebase

A ruby client for freebase
Ruby
18
star
43

go-nma

A go interface to NotifyMyAndroid
Go
17
star
44

logexec

A log redirection thing.
Go
16
star
45

mqttd

a complete mqtt v5 broker
Haskell
16
star
46

go-hashset

A set of hashes.
Go
16
star
47

replaykit

A toolkit for replaying time series data.
Go
16
star
48

yellow

Raise awareness of slow functions
Go
15
star
49

tesla

Tesla API for Haskell
Haskell
15
star
50

twisted-memcached

memcached protocol in twisted
Python
15
star
51

papertrails

My papertrail S3 log aggregator tool
Nix
14
star
52

beanstalk-xmpp

A stupidly simple beanstalk -> xmpp gateway to connect various services to IM.
Python
14
star
53

photo-couch

couchapp photo album
JavaScript
14
star
54

buildwatch

A buildbot GUI for OS X
Objective-C
12
star
55

BreakDancer

It thinks of everything.
Python
12
star
56

logic-cppm

CPPM Analyzer for Saleae Logic
C++
12
star
57

gojson

Fork of go's encoding/json with the scanner API made public.
Go
12
star
58

etest

A tool to help coordinate distributed tests.
Erlang
11
star
59

go-couchstore

Go interface to libcouchstore.
Go
11
star
60

beanstalk-client-twisted

A beanstalk client for the twisted network framework.
Python
11
star
61

graphex

Dependency graph viewer CLI tool
Haskell
10
star
62

dotfiles

Finally pushing up my dotfiles from hg.
Emacs Lisp
10
star
63

httputil

HTTP client and server utilities for go
Go
10
star
64

dustin.sallings.org

My github page.
HTML
10
star
65

ibutton

My 1wire protocol stack and related tools
C
10
star
66

app-hider

OS X app that helps you focus by hiding applications you aren't paying attention to.
Objective-C
10
star
67

mc-hammer

A simple load testing tool.
C++
9
star
68

urlwatch

Watch broken URLs from the commandline. Be told when stuff starts working again.
Go
9
star
69

pfetch

A web service consumer.
Go
9
star
70

logmerge

Combines several compressed web logfiles (including S3) into a single common log file very quickly.
C++
9
star
71

mccouch

Memcached Interface for CouchDB
Erlang
9
star
72

kvtest

A framework for testing low-level key/value stores.
C++
9
star
73

environ

My environmental monitoring stuff for the house.
Erlang
8
star
74

influxer

MQTT -> InfluxDB ingestion thing.
Haskell
8
star
75

photoupload

A Mac OS X photo uploader program for my photo album.
Objective-C
8
star
76

wwcp

WWCP
Go
8
star
77

noelani

Noelani's web site
Ruby
7
star
78

go-couch

CouchDB API
Go
7
star
79

spyjar

My generally useful java library I take wherever I go.
Java
7
star
80

diff

Different strokes.
Go
7
star
81

testingbee

Port of Go's testing.B to C
C
7
star
82

go-yammer

A yammer interface for go
Go
7
star
83

photo

My photo album project.
Common Lisp
7
star
84

githubhooks

A thing to watch all github repos and fire hooks from them.
Go
7
star
85

py-backpack

Python interface to backpack.
Python
7
star
86

memcached_mon

A processing hack for visualizing memcached data in real(ish) time.
Processing
6
star
87

websaver

Use a URL as a screen saver.
Objective-C
6
star
88

washer

Code for my washer project.
Arduino
6
star
89

arduino-2406

A 1Wire DS2406 Control Library for Arduino.
Processing
6
star
90

twitter-pub

Simple service to publish a twitter stream to an XMPP pubsub node.
Python
6
star
91

go-nmea

Parsing messages from an NMEA stream
Go
6
star
92

location

Location, location, location.
JavaScript
6
star
93

tesladb

Thing to grab data from the Tesla API and store it in sqlite and mqtt.
Haskell
6
star
94

twisted-friends

A friendfeed client for twisted.
Python
6
star
95

gearman-ocaml

OCaml library for gearman
OCaml
6
star
96

ruby-summize

A ruby client for the summize conversational search engine.
Ruby
6
star
97

money

My money tracking app. There are many like it, but this one is mine.
Ruby
6
star
98

gerrit-couch

couchapp for showing gerrit activity
JavaScript
6
star
99

rpics

My reddit pictures capture thing.
JavaScript
5
star
100

dvdbackup

Bug fixes of Olaf Beck's dvdbackup pulled somewhere off the web.
C
5
star