optional arguments:
-h, --help show this help message and exit
-b insert bold tag
-i insert italics tag
-o insert overline tag
-u insert underline tag
-s insert strikethrough tag
-m insert monospace tag
-spoiler insert spoiler tag
-sub insert subscript tag
-sup insert superscript tag
-aa insert Shift JIS tag
-code insert code tag
--faggot insert ``faggot'' quotes
--mode {all,random,ransom}
special modes for applying all tags to the text, a
random selection of tags to the text, or a random
selection of tags to each character of the text.
$ cat ~/bin/bb | bb -code #!/usr/bin/env python
def text_to_bbcode(text, tags):
while tags:
text = '[{0}]{1}[/{0}]'.format(tags.pop(), text)
return text
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='BBCode encode user input.')
parser.add_argument('text', nargs='*', help='text to be encoded')
for tag, desc in _TAG_DESC_PAIRS:
parser.add_argument('-%s' % tag, action='append_const', dest='tags',
const=tag, help='insert %s tag' % desc)
parser.add_argument('--faggot', action='store_true',
help="insert ``faggot'' quotes")
parser.add_argument('--mode', choices=['all', 'random', 'ransom'],
help=('special modes for applying all tags to the '
'text, a random selection of tags to the text, '
'or a random selection of tags to each '
'character of the text.'))
args = parser.parse_args()
# Make sure 'code' comes last because tags inside it will not render.
if args.tags and 'code' in args.tags:
args.tags.append(args.tags.pop(args.tags.index('code')))
text = ' '.join(args.text) or sys.stdin.read().strip()
if args.faggot is True:
text = "``%s''" % text
if args.mode is None:
print text_to_bbcode(text, args.tags)
if args.mode == 'all':
print text_to_bbcode(text, _TAGS)
elif args.mode == 'random':
print text_to_bbcode(text, _random_tags())
elif args.mode == 'ransom':
print ''.join(c if c.isspace() else text_to_bbcode(c, _random_tags()) for c in text)
If you decide to hack it, post the code here. Have fun.
>>3
You forgot to take into consideration that most people do not BBCode their whole post, but often word by word with different tags. For example, BBCode. This would literally take me forever with your ``tool''.
>>6
$ bb -spoiler you don\'t have to write `bb -i --faggot the whole thing` in `bb -biou ONE LINE` you don't have to write ``the whole thing'' in ONE LINE
It's just for fun, lighten up.
>>9
Whatevs. It was supposed to be an Easter egg but I couldn't find an option to hide it form the help menu. Either way, it makes more sense when working with the command line. Observe:
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-b insert bold tag
-i insert italics tag
-o insert overline tag
-u insert underline tag
-s insert strikethrough tag
-m insert monospace tag
-spoiler insert spoiler tag
-sub insert subscript tag
-sup insert superscript tag
-aa insert Shift JIS tag
-code insert code tag
--faggot insert ``faggot'' quotes
--cruise CRUISE CONTROL
--rot13 awesoma powa!
--omg-optimized VROOM VROOM!
--mode {all,random,ransom}
special modes for applying all tags to the text, a
random selection of tags to the text, or a random
selection of tags to each character of the text.
$ cat ~/bin/bb | bb -code #!/usr/bin/env python
import argparse
import logging
import random
import sys
def text_to_bbcode(text, tags):
while tags:
text = '[{0}]{1}[/{0}]'.format(tags.pop(), text)
return text
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='BBCode encode user input.')
parser.add_argument('text', nargs='*', help='text to be encoded')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s 1.1')
for tag, desc in _TAG_DESC_PAIRS:
parser.add_argument('-%s' % tag, action='append_const', dest='tags',
const=tag, help='insert %s tag' % desc)
parser.add_argument('--faggot', action='store_true',
help="insert ``faggot'' quotes")
parser.add_argument('--cruise', action='store_true',
help='CRUISE CONTROL')
parser.add_argument('--rot13', action='store_true',
help='awesoma powa!')
parser.add_argument('--omg-optimized', action='store_true',
help='VROOM VROOM!')
parser.add_argument('--mode', choices=['all', 'random', 'ransom'],
help=('special modes for applying all tags to the '
'text, a random selection of tags to the text, '
'or a random selection of tags to each '
'character of the text.'))
args = parser.parse_args()
# Make sure 'code' comes last because tags inside it will not render.
if args.tags and 'code' in args.tags:
args.tags.append(args.tags.pop(args.tags.index('code')))
text = ' '.join(args.text) or sys.stdin.read().rstrip('\n')
if args.rot13 is True:
text = text.encode('rot13')
if args.cruise is True:
text = text.upper()
if args.faggot is True:
text = "``%s''" % text
if args.mode is None:
text = text_to_bbcode(text, args.tags)
elif args.mode == 'all':
text = text_to_bbcode(text, _TAGS)
elif args.mode == 'random':
text = text_to_bbcode(text, _random_tags())
elif args.mode == 'ransom':
text = ''.join(c if c.isspace() else text_to_bbcode(c, _random_tags())
for c in text)
if args.omg_optimized is True:
text = _optimize(text)
print text
if len(text) > _MAX_CHARS:
logging.warning("it's over %d (too big for Shiichan)", _MAX_CHARS)
Name:
Anonymous2011-08-11 15:57
$ ./sex.py Greetings {spoiler /prog/} from an {b.i.o.u EXPERT {sup B{sup B{sup C{sub O{sub D{sub E}}}}}} PROGRAMMER !!}
Since you can't into Unix, I wrote you a S{sub e}x{sup p}C{sub o}d{sup e} interpreter.
It's doesn't support things like \{sup*3 this\} because I didn't feel like it.
That is left as an exercise for the hacker on ``her'' way to becoming a {b.i.o.u ``SEXPERT'' PROGRAMMER}.
{i Have fun !!}
Greetings /prog/ from an EXPERT BBCODE PROGRAMMER !!
Since you can't into Unix, I wrote you a SexpCode interpreter.
It's doesn't support things like {sup*3 this} because I didn't feel like it.
That is left as an exercise for the hacker on ``her'' way to becoming a ``SEXPERT'' PROGRAMMER. Have fun !!
def parse(exp):
start = None
depth = 0
output = str(exp)
for i, c in enumerate(exp):
if c == '{' and (i == 0 or exp[i-1] != '\\'):
if start is None:
start = i
else:
depth += 1
elif c == '}':
if depth == 0:
old = exp[start:i+1]
new = eval_(old)
output = output.replace(old, new)
start = None
else:
depth -= 1
return output.replace('\{', '{').replace('\}', '}')
if __name__ == '__main__':
text = ' '.join(sys.argv[1:]) or sys.stdin.read()
print parse(text)
Name:
Anonymous2011-08-11 16:35
This thread reeks of FIOC, IHBT!!!
Name:
Anonymous2011-08-11 16:47
>>13
Yeah I couldn't help but notice that even though /prog/ will cry ``FIOC'' and attack it every chance it gets, 99% of the complete working programs posted here are written in Python. Either Lisp is shit or Listhpers can't program. Likely both.
>>14
Lisp is ugly, but not terrible. I do agree with your latter point. All of the current batch of ``Listhpers" on here can't do shit. They are those people who see Lisp and instantly think of it as a divine silver bullet without considering its drawbacks. Fucking hate them.
>>22 Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators.
Where ITT is it being used incorrectly?
Although this thread is OLD AS FUCK, >>16 is correct. There are probably 1-2 experienced Lispers on this board. The rest are probably incompetent and/or learning.
>>28
But calling someone a jew is okay? Anyways, I was hoping the computer science major who can't seem to get a job would have posted at least completed one of the exercises in this thread. Ya know, at least show us that he/she/it can do more than google shit.
Name:
Anonymous2012-01-13 12:59
>>29
Well, if you're doing it directly to him I think it's okay to call him a Jew, but I don't think it's right to attack his family members. For all we know his mother is a great programmer and his father is a mental midget so he came out a mental midget as well, it's not his mothers fault.
That's great that you've written a BB code generating program, OP, but I've written a BB code generating program generating program: #include <stdio.h>
int main(void)
{
puts("#!/usr/bin/env python\n\nimport argparse\nimport random\nimport sys\n\n\n_TAG_DESC_PAIRS = [\n\t\t('b', 'bold'), ('i', 'italics'), ('o', 'overline'), ('u', 'underline'),\n\t\t('s', 'strikethrough'), ('m', 'monospace'), ('spoiler', 'spoiler'),\n\t\t('sub', 'subscript'), ('sup', 'superscript'), ('aa', 'Shift JIS'),\n\t\t('code', 'code')]\n\n\n_TAGS = [tag for tag, desc in _TAG_DESC_PAIRS]\n\n\ndef _random_tags():\n\treturn random.sample(_TAGS, random.randint(1, len(_TAGS)-1))\n\n\ndef text_to_bbcode(text, tags):\n\twhile tags:\n\t\ttext = '[{0}]{1}[/{0}]'.format(tags.pop(), text)\n\treturn text\n\n\nif __name__ == '__main__':\n\tparser = argparse.ArgumentParser(description='BBCode encode user input.')\n\tparser.add_argument('text', nargs='*', help='text to be encoded')\n\tfor tag, desc in _TAG_DESC_PAIRS:\n\t\tparser.add_argument('-%s' % tag, action='append_const', dest='tags',\n\t\t\t\t\t\t\tconst=tag, help='insert %s tag' % desc)\n\tparser.add_argument('--faggot', action='store_true',\n\t\t\t\t\t\thelp='insert ``faggot'' quotes')\n\tparser.add_argument('--mode', choices=['all', 'random', 'ransom'],\n\t\t\t\t\t\thelp=('special modes for applying all tags to the '\n\t\t\t\t\t\t\t 'text, a random selection of tags to the text, '\n\t\t\t\t\t\t\t 'or a random selection of tags to each '\n\t\t\t\t\t\t\t 'character of the text.'))\n\targs = parser.parse_args()\n\t# Make sure 'code' comes last because tags inside it will not render.\n\tif args.tags and 'code' in args.tags:\n\t\targs.tags.append(args.tags.pop(args.tags.index('code')))\n\ttext = ' '.join(args.text) or sys.stdin.read().strip()\n\tif args.faggot is True:\n\t\ttext = '``%s''' % text\n\tif args.mode is None:\n\t\tprint text_to_bbcode(text, args.tags)\n\tif args.mode == 'all':\n\t\tprint text_to_bbcode(text, _TAGS)\n\telif args.mode == 'random':\n\t\tprint text_to_bbcode(text, _random_tags())\n\telif args.mode == 'ransom':\n\t\tprint ''.join(c if c.isspace() else text_to_bbcode(c, _random_tags()) for c in text)");
return 0;
}
Consider yourself one-upped.