Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Recently, I used my favorite image editor to make a 1x1 black pixel (which can come in handy when you want to draw solid boxes in HTML cheaply). Even though I made it a monochrome PNG, it came out to be 120 bytes! I mean, that's kind of steep. 120 bytes. For one pixel. I then converted it to a GIF, which dropped the size down to 43 bytes. Much better, but still...
Challenge
The shortest image file or program that is or generates a 1x1 black pixel. A submission may be:
An image file that represents a 1x1 black pixel. The format chosen must be able to represent larger images than 1x1, and cannot be ad-hoc (that is, it can't be an image format you just made up for code golf). Image files will be ranked by byte count.
A program that generates such an image file. Programs will be ranked by character count, as usual in code golf.
As long as an answer falls into one of these two categories, anything is fair game.
Also, for image files, please specify them in hexadecimal or escapes rather than using an external image host :-)
Data URI, 83 characters
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==
Image file: 10 bytes, in PGM format:
P5 1 1 1\n\0
To create it, in Python: 40 characters
open('b.pgm', 'w').write('P5 1 1 1\n\0')
Unicode art format:
·
WBMP, 5 bytes:
00 00 01 01 00
Can't imagine anything smaller
The PBM format is a black and white graphics format.
A binary representation of a single black pixel would take 8 bytes, and writing it to a file with C# would look like:
File.WriteAllText("p.pbm", "P4 1 1 ÿ");
Logo / Turtle basic, 12 bytes
PENDOWN FD 1
I can't remember if pendown can be shortened to pd or not, if so, that drops it to 7 bytes.
bash: 31 chars
The script to download a single pixel gif from the interwebs is fewer bytes than the single pixel itself...
wget http://tinyurl.com/2w97dyo
Python+PIL 68 chars
from PIL import Image
Image.fromstring("P",(1,1),"\0").save("B.gif")
Postscript, 29 bytes. not really a "single pixel", but it was a single pixel on my preview screen.
0 0 moveto .5 0 lineto stroke
Python (w/ PIL) (85 chars):
from PIL import Image
i=Image.new("P",(1,1))
i.putpixel((0,0),(0))
i.save("i.gif","GIF")
An old image format I used to use: 4 bytes
01 00 00 0C
The format consists of an array of 16 bit integers (little endian):
Bit mapping:
0-10: number of pixels to shade
10-11: control bits
12-15: VGA16 pidel color
Control bits values:
0: normal
1: end of line
3: end of file
SVG, 59 characters:
<svg><rect width="1" height="1" style="fill:#000;"/></svg>
Unfortuntally, including Doctype it grows to 157...:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg><rect width="1" height="1" style="fill:#000;"/></svg>
DrRacket: 23 chars
#lang slideshow
(disk 1)
I'm pretty late to this party, but http://www.perlmonks.org/?node_id=7974 has a more general answer than anyone's posted so far:
## tinygif
## World's Smallest Gif
## 35 bytes, 43 if transparent
use strict;
my($RED,$GREEN,$BLUE,$GHOST,$CGI);
## Adjust the colors here, from 0-255
$RED = 255;
$GREEN = 0;
$BLUE = 0;
## Set $GHOST to 1 for a transparent gif, 0 for normal
$GHOST = 0;
## Set $CGI to 1 if writing to a web browser, 0 if not
$CGI = 0;
$CGI && printf "Content-Length: %d\nContent-Type: image/gif\n\n",
$GHOST?43:35;
printf "GIF89a\1\0\1\0%c\0\0%c%c%c\0\0\0%s,\0\0\0\0\1\0\1\0\0%c%c%c\1\0;",
144,$RED,$GREEN,$BLUE,$GHOST?pack("c8",33,249,4,5,16,0,0,0):"",2,2,4;
XPM, 57 bytes:
/* XPM */
static char *_x_[] = {"1 1 1 1",".c #000","."}
When looking for the wikipedia article to link it I found XPM2, 26 bytes, but I could not open that with any program here.
! XPM2
1 1 1 1
. c #000
.
Rebmu: 16 chars
en'PNGmkIM![1x1]
If you want it to save to a file based on an argument you pass in, that adds three more chars to the program:
rebmu/args [wrAen'PNGmkIM![1x1]] %my-black-pixel.png
The program is shorthand for the following Rebol, parentheses added for clarity:
write a (encode 'png (make image! [1x1]))
<div style="height: 0; width: 1px; border-top: 1px solid #000">
But positioning it will take more.
Related
I'm trying to bind a regex to my HTML form for an EU bank account. So far, I was able to piece together that:
pattern="[A-Z]{2}[000000000-999999999]{9}
Will let something pass that's for example UK123456789
But I also want to let it pass for UK12 2345 6789
How do I go about accepting a space at exactly those placements?
pattern="[A-Z]{2}[000000000-999999999]{9}"
This only accidentally does what you want. ([000000000-999999999] says "this character should be a 0 or a 0 or a 0 or ... a character in the range of 0-9 or a 9 or a 9 or ... a 9.) The proper form is:
pattern="[A-Z]{2}[0-9]{9}"
or more accurately:
pattern="[A-Z]{2}\d{9}"
Now that we have something more rational, we can extend that to:
pattern="[A-Z]{2}\d{2}\s?\d{4}\s?\d{4}"
which allows optional whitespace at the specific locations.
If you want to allow just spaces rather than any whitespace character, you could do:
pattern="[A-Z]{2}\d{2} ?\d{4} ?\d{4}"
You can allow an optional whitespace using \s?, though it'l make your regex a little longer. Below regex will allow both with or without whitespace (DEMO)
\w{2}\d{2}\s?\d{4}\s?\d{4}
But be aware that an european IBAN is longer than what you have posted - though I'm not sure how it is in the UK.
If you don't care where the spaces are, as long as there are 9 digits, you can remove all the spaces before checking:
str = 'UK12 234 56789';
strToCheck = str.replace(/ /g, '');
validStr = strToCheck.match(/[a-zA-Z]{2}\d{9}/);
if (validStr) {
console.log('Valid');
}
While editing some old ColdFusion code I found a <td> which has a bgcolor property. The value of it was ##89969E. I copied the code to a HTML file and found out the color was different in ColdFusion.
Now, i noticed the double #, so i removed one and the color was the same. Why does the color change when adding/removing a #?
jsFiddle
As a basic premise, additional hashes are interpreted as a missing/erroneous value and so replaced with a zero, so ##89969E becomes #0089969E. Note that HEX codes can be as long as 8 digits following a hash (if aRGB), where the last two refer to transparency
Missing digits are treated as 0[...]. An incorrect digit is simply
interpreted as 0. For example the values #F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are all the same.
When color strings longer than 8 characters or shorter than 4
characters are used, things start to get strange.
However there are a lot of nuances - you can find out more about this here, and for some fairly entertaining results this creates, have a little read here
The character used in this question examples is the period, it appears that all characters behave the same way. Why does the period trail after the hyperlink by one space character when coded like this:
You can become one of us
<a href="http://www.somedomain.com/oneOfUs/allYourBaseAreBelongToUs/">
here
</a>
.
I checked the ascii character array for the above and it looks to be a simple space:
104 101 114 101 32 46
vs no trailing space after the hyperlink when coded like this:
You can become one of us
here.
The ascii character array for the above contains no space in output, but providing the character array for output comparison: 104 101 114 101 46
This is because the newline in the first example is converted to a space. There is a more thorough explanation in this thread: Prevent browser converting '\n' between lines into space (for Chinese characters)
I have written one XSLT to transform xml to html. If input xml node contains only space then it inserts the space using following code.
<xsl:text> </xsl:text>
There is another numeric character which also does same thing as shown below.
<xsl:text> </xsl:text>
Is there any difference between these characters? Are there any examples where one of these will work and other will not?
Which one is recommended to add space?
Thanks,
Sambhaji
is a non-breaking space ( ).
is just the same, but in hexadecimal (in HTML entities, the x character shows that a hexadecimal number is coming). There is basically no difference, A0 and 160 are the same numbers in a different base.
You should decide whether you really need a non-breaking space, or a simple space would suffice.
It's the same. It's a numeric character reference.
A0 is the same number as 160. The first is in base 16 (hexadecimal) and the second is in base 10 (decimal, everyday base).
I know there are HTML entities for 1/2, 1/4, and 3/4, but are there others? Like 1/3 or 1/8? Is there a good way to encode arbitrary fractions?
how about 15⁄16? (<sup>15</sup>⁄<sub>16</sub>)
1/2 → ½ or ½
1/4 → ¼ or ¼
3/4 → ¾ or ¾
1/8 → ⅛ or ⅛
3/8 → ⅜ or ⅜
5/8 → ⅝ or ⅝
7/8 → ⅞ or ⅞
1/3 → ⅓
2/3 → ⅔
1/5 → ⅕
2/5 → ⅖
3/5 → ⅗
4/5 → ⅘
1/6 → ⅙
5/6 → ⅚
...but you could also encode them as decimals: 15/16 = 0.9375 ;)
For the existing fractions as Unicode codepoints (which are mapped to by HTML entities), search for "vulgar fraction" in the Unicode Character Names Index.
Now, for generic fractions, which work in HTML but also work in plain text, use the super- and subscript digits (see Unicode Codepoint Chart, search for "Superscripts") separated by the fraction slash character.
Your example implemented as above:
¹⁵⁄₁₆
Isn't just 15/16ths alright? Or even 15/16ths (15/16<sup>ths</sup>)?
For more complex scenarios there is also MathML. The support for this is slowly getting better. Internet Explorer seems to lag behind with this as well.
There is also a standard called MathML. But is for XML unfortunately. However if you have more expressions you might consider switching to basic XML.
This would depend on your exact needs and audience.
For most purposes many methods would be appropriate.
15/16, 15 parts of 16, 93.75%, 15/16 all mean the same,
you might even use symbols like
++++++++++++++-
For some more complex scenarios you will need more complex solutions more like LaTeX than html. I believe there are also server side components that take LaTeX descriptions and create images that are browser compatible, such as described here: http://www.fauskes.net/nb/htmleqII/
In HTML, this can be done with Unicode code 2044, preceded by &#x and ending with a semicolon. The whole thing is placed between the numerator and the denominator.
For instance, with this solution, 15 divided by 16 in HTML is rendered like this: 15⁄16
This works for combinations of integers acting as numerators and denominators.