Skip to content

Commit

Permalink
cmd/num: Add num tool which displays the binary, octal, decimal and h…
Browse files Browse the repository at this point in the history
…exadecimal representation of numbers.
  • Loading branch information
mewmew committed Jul 8, 2015
1 parent 9b6004b commit 1344907
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 208 deletions.
17 changes: 6 additions & 11 deletions cmd/ascii/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
ascii
=====
# ascii

This tool examines files and reports non-ascii characters.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/ascii

Usage
-----
## Usage

ascii [OPTION]... PATH...

Expand All @@ -18,17 +15,15 @@ Flags:
-v (default=false)
Verbose.

Examples
--------
## Examples

echo "Hello, 世界" > foo.txt
ascii foo.txt
// Output:
// foo.txt (1:7) - non-ascii character '世'

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
14 changes: 5 additions & 9 deletions cmd/flac2wav/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
flac2wav
========
# flac2wav

The flac2wav tool converts FLAC files to WAV files.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/flac2wav

Usage
-----
## Usage

flac2wav [OPTION]... FILE...

Expand All @@ -18,9 +15,8 @@ Flags:
-f (default=false)
Force overwrite.

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
8 changes: 3 additions & 5 deletions cmd/gitstat/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
gitstat
=======
# gitstat

The aim of this project is to provide a convenient tool for checking the status
of multiple git repositories.
Expand All @@ -11,9 +10,8 @@ The status of each repository can be one or more of the following:
- Staged changes
- Ahead

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
17 changes: 6 additions & 11 deletions cmd/gitsync/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
gitsync
=======
# gitsync

This tool keeps forked git repositories in sync with their parents. It does so
by locating the repositories of provided usernames and organizations. Then it
creates a shell script which will clone all repository forks, pull changes from
their parens and push those changes to the forked repository.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/gitsync

Usage
-----
## Usage

gitsync USER...

Examples
--------
## Examples

gitsync mewbak > sync.sh
chmod +x sync.sh
./sync.sh

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
17 changes: 6 additions & 11 deletions cmd/links/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
links
=====
# links

This tool examines HTML files and reports invalid links.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/links

Usage
-----
## Usage

links PATH...

Examples
--------
## Examples

1. Report any invalid links in the set of files [a.html][] and [b.html][].

Expand All @@ -27,9 +23,8 @@ Examples
[a.html]: https://raw.githubusercontent.com/mewmew/playground/master/cmd/links/testdata/a.html
[b.html]: https://raw.githubusercontent.com/mewmew/playground/master/cmd/links/testdata/b.html

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
17 changes: 6 additions & 11 deletions cmd/metagps/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
metagps
=======
# metagps

This tool outputs the GPS coordinates of provided images.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/metagps

Usage
-----
## Usage

metagps PATH...

Examples
--------
## Examples

metagps "2013-02-17 - 09.09.37.jpg"
// Output:
// path: 2013-02-17 - 09.09.37.jpg
// coord: N 13.410758 E 103.85964

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
17 changes: 6 additions & 11 deletions cmd/mimicry/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
mimicry
=======
# mimicry

This tool creates a git repository which mimics an image using a contribution
history of carefully crafted commit dates. It expects a 51x7 image with a
transparent background.

Installation
------------
## Installation

go get github.com/mewmew/playground/cmd/mimicry

Usage
-----
## Usage

mimicry IMAGE

Examples
--------
## Examples

The mimicry command was used to create the [hello][] repository. Below is a screenshot of its contribution history as of 2014-07-11.

Expand All @@ -26,9 +22,8 @@ The mimicry command was used to create the [hello][] repository. Below is a scre

[hello]: https://github.com/yumpie/hello

public domain
-------------
## Public domain

This code is hereby released into the *[public domain][]*.
The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
51 changes: 51 additions & 0 deletions cmd/num/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# num

The `num` tool displays the binary, octal, decimal and hexadecimal representation of numbers.

## Installation

go get github.com/mewmew/playground/cmd/num

## Usage

num BIN|OCT|DEC|HEX

## Examples

```bash
$ num 0b111101101
bin: 0b111101101
oct: 0o755
dec: 493
hex: 0x1ED
```

```bash
[~]$ num 0o755
bin: 0b111101101
oct: 0o755
dec: 493
hex: 0x1ED
```

```bash
$ num 493
bin: 0b111101101
oct: 0o755
dec: 493
hex: 0x1ED
```

```bash
$ num 0x1ED
bin: 0b111101101
oct: 0o755
dec: 493
hex: 0x1ED
```

## Public domain

The source code and any original content of this repository is hereby released into the [public domain].

[public domain]: https://creativecommons.org/publicdomain/zero/1.0/
75 changes: 75 additions & 0 deletions cmd/num/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//go:generate usagen num

// num is a tool which displays the binary, octal, decimal and hexadecimal
// representation of numbers.
package main

import (
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
)

func usage() {
const use = `
Usage: num BIN|OCT|DEC|HEX
Examples:
num 0b111101101
num 0o755
num 493
num 0x1ED
`
fmt.Fprint(os.Stderr, use[1:])
}

func main() {
// Parse command line arguments.
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
s := flag.Arg(0)

n, err := parseNum(s)
if err != nil {
log.Fatal(err)
}
const format = `
bin: 0b%b
oct: 0o%o
dec: %d
hex: 0x%X
`
fmt.Printf(format[1:], n, n, n, n)
}

// parseNum parses the given string as a binary, octal, decimal or hexadecimal
// number based on its prefix; with "0b", "0o", no prefix, and "0x"
// respectively.
func parseNum(s string) (n uint64, err error) {
var base int
switch {
case strings.HasPrefix(s, "0b"):
// Binary
base = 2
s = s[len("0b"):]
case strings.HasPrefix(s, "0o"):
// Octal
base = 8
s = s[len("0o"):]
case strings.HasPrefix(s, "0x"):
// Hexadecimal
base = 16
s = s[len("0x"):]
default:
// Decimal
base = 10
}
return strconv.ParseUint(s, base, 64)
}
10 changes: 10 additions & 0 deletions cmd/num/z_usage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// generated by `usagen num`; DO NOT EDIT

// Usage: num BIN|OCT|DEC|HEX
//
// Examples:
// num 0b111101101
// num 0o755
// num 493
// num 0x1ED
package main
Loading

0 comments on commit 1344907

Please sign in to comment.