This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # -*- coding: utf-8 -*- | |
| # prints a sparkline in the terminal using the supplied list of numbers | |
| # examples: | |
| # spark.rb 10 20 30 100 90 80 | |
| # spark.rb 1 2 0.4 0.1 1.3 0.7 | |
| @ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇] | |
| values = ARGV.map { |x| x.to_f } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Simple bijective function | |
| # Basically encodes any integer into a base(n) string, | |
| # where n is ALPHABET.length. | |
| # Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047 | |
| ALPHABET = | |
| "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//) | |
| # make your own alphabet using: | |
| # (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Compress and add javascript: prefix, then save as a bookmarklet | |
| function process(image){ | |
| h = image.height; w = image.width; | |
| var buffer = document.createElement("canvas"); // Anonymous canvas | |
| buffer.width = w;buffer.height=h; | |
| var ct = buffer.getContext('2d'); | |
| ct.drawImage(image,0,0); | |
| var data = ct.getImageData(0,0,w,h).data; // This may raise an exception for external images. | |
| var pxs=2; // Height-Width of the pixel block |
NewerOlder