A generic term meaning the process by which text transformed into a more meaningful or clearer output. A typical example would be the transformation of a decimal into a particular currency format with the correct number of decimal places.
4
votes
3answers
230 views
Rounding and formatting hours, minutes, seconds as HH:MM AM/PM
I have a program which is supposed to convert standard time to traditional time. (e.g: 15:24:31 = 3:25PM [rounded seconds])
I would like for someone to error check my code for me as well as give me ...
1
vote
2answers
54 views
Formatting a list of strings as a comma-separated string
I'm learning Haskell on my own and I'm following the material of a course.
I would like to know if this is idiomatic Haskell.
...
4
votes
3answers
172 views
Script to generate templated PHP code
I've created a script to create a module in our MVC framework
The structure of the module is like this (for this example, the module is called test
...
3
votes
2answers
48 views
Flexible presentation of a user's name based on a combination of available properties
The goal is to add a new displayValue property to each object depending on what it has available out of Firstname, ...
2
votes
2answers
46 views
Function to validate date format
I have this JavaScript function which checks if the format has 'yyyy' and replaces 'yy' with 'y':
...
7
votes
5answers
405 views
Python odd number diamond
I worked up a quick diamond program that takes only odd numbers while returning an error with even numbers or 0.
The code looks rather ugly to me, especially with the recurring ...
10
votes
3answers
560 views
Beginnings of a base-conversion game in Python
I'm pretty very new to python, so I thought that I'd write a game to teach me python and better teach me how to think in hexadecimal and binary. I'm starting off by writing a few functions to convert ...
3
votes
3answers
74 views
Padding a hexadecimal string with zeros
I'm given a hexadecimal number in string form with a leading "0x" that may contain 1-8 digits, but I need to pad the number with zeros so that it always has 8 ...
3
votes
1answer
78 views
Convert between two bases, each between 2 and 36
I'm doing some Python practice for fun and I wrote some code that converts between two bases. I'm thinking about expanding on this later, so the docstrings are pretty redundant from function to ...
2
votes
1answer
39 views
Print dict with varying-length lists
Is there a shorter way of taking a dict with varying length lists and printing it to screen? Shortcomings of this method also include that values which aren't lists are printed as letters separated by ...
14
votes
2answers
1k views
Retro Rocket ASCII Art
Inspired by Nested for-loop ASCII art, I looked at building a more complicated ASCII art than just the normal 'diamond' and 'triangle' variations that crop up occasionally here.
The challenge: ...
7
votes
3answers
78 views
Calendar Print Method
I'm currently learning Ruby and need help in editing code to be more idiomatic. I have the method below I could use some pointers on how to make more "Ruby" :-)
...
8
votes
4answers
188 views
Align Strings for Output
I wrote a class which can format input so that it is properly aligned.
I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc).
I'm especially wondering ...
7
votes
3answers
235 views
Validating lines in a file using certain specifications
I have written a program which basically reads a file named "data.txt" line-by-line. As a line is read, it validates the line with a certain specification. If the specification is met, it will ...
0
votes
1answer
51 views
Round division to two decimal places [closed]
I'm working on a revision of my electrical calculator. I used string formatting to round the answers it gives to two decimal places. On the operations that require multiplication (voltage, wattage), ...
3
votes
1answer
40 views
Format a number to include commas
This is my attempt to format a number and put commas where appropriate. I was wondering if this could be done in a simpler way.
It's used by calling ...
3
votes
3answers
324 views
Parsing and formatting a time two ways (perfectionistic approach)
I'm still not satisfied by the readability of the code. The wanted behavior which would be self descriptive would sound like: "I've two fields; one is for the date and one for the hour. This two ...
2
votes
2answers
160 views
“Nice Angles” - Code Eval challenge
Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0:
CHALLENGE DESCRIPTION:
Write a program that outputs the value of angle, reducing its
fractional part to minutes and ...
2
votes
0answers
17 views
sprintf for a microcontroller [closed]
I'm currently writing some code to running using a small micro controller, and need to implement a version of sprintf (the standard library version is too large). I ...
6
votes
2answers
78 views
writeln() and format() with variadic templates
I wanted to get better acquainted with variadic templates, so I decide to try to implement a function like D's writeln(), just for fun.
...
7
votes
1answer
179 views
Fully-working alternative to String.format(…)
PLEASE NOTE:
The code below has "commented out" code; however, no code is actually commented out!! Check my GitHub link below. I did that solely to highlight the relevant code sections. Code in my ...
3
votes
1answer
54 views
Implementation of *nix ipcalc
I posted a JS subnetting calc before, but I wanted to try a CLI version, so I made this.
The parts I'm most worried about are:
structure (could I refactor the layout better?)
Did I goof any math?
...
3
votes
1answer
61 views
How to better indent multiline strings with many string formatting args?
I have a function, that is used in flask, for logging application errors:
...
4
votes
3answers
104 views
Validate parameters within a range
Function to use several blocks of if:elif:else: that all take slightly different conditional statements. I'm trying to format integers into a 2 digit string, ...
3
votes
2answers
58 views
Go string formatting
I'm very new to Go, and am trying to get some experience by re-writing some of my Python code in Go. Below is a function that takes an IP address (ipv4) in integer form and returns the string ...
5
votes
1answer
154 views
Simple parsing for string formatting (version 2)
This is my second attempt (version 1) at writing a string formatting utility which uses parsing. This time I more explicitly designed it as a finite state machine. I have very little experience with ...
11
votes
2answers
1k views
A fraction of the code
Following up on this post, and including some major changes suggested, here's the revised code.
Changes include:
No longer keeping an IFormatProvider at instance ...
10
votes
1answer
194 views
Formattable Fraction
I have written this small little program, to test how my Fraction type behaves when used with and without a custom ...
4
votes
1answer
139 views
Simple parsing for string formatting
Recently I submitted some string formatting and printing code (found here) that I wrote as an small exercise. It was implemented naively using string replacement. This time around I wanted to actually ...
10
votes
1answer
211 views
Did I implement my string formatting code correctly?
As a small exercise I have written some string formatting and printing functions in C++11. I would like a bit of code review, not so much on the merits of using this over something like ...
6
votes
2answers
115 views
Scroll listener - about code style guidelines and standards
I'm an upstart, been only professionally programming for a bit less than 2 years, mainly in Java as I am currently working as an Android developer.
I often find myself thinking about how to improve ...
5
votes
1answer
114 views
A Lightweight Rich Link Label
This is my first post here - I hope I don't break any rules..
After reading the same question on SO about how to bold a word in a label for the nth time today, I decided to write a formatted Label.
...
5
votes
2answers
188 views
String representation of a polynomial
We all know that math notation is idiosyncratic. Canonical representation of math objects often have irregular grammar rules to improve readability. For example we write a polynomial \$3x^3 + x^2\$ ...
4
votes
1answer
96 views
Interface and implementation of this replacement for Rebol/Red REJOIN
This is a draft implementation of a function called COMBINE. It's not intended to be a complex formatting dialect, just a replacement for REJOIN that has a better name and more useful behavior. ...
3
votes
2answers
90 views
Java Cross with characters
I managed to make a perfectly even cross with for loops.
I'm trying to make this cross easier to code. I have to keep it with ...
4
votes
1answer
117 views
Shell script for creating CR questions
Inspired by Tool for creating Code Review questions.
This script generates a markdown document suitable for a CR question from a list of files. For each file it finds, it sends the following to ...
5
votes
3answers
73 views
Command line tools to format tables
I am a big fan of one-liners using sed awk perl and other tools. But there are that are ...
4
votes
2answers
305 views
Shortest possible way of printing a specific board
I am trying to print a board exactly like this with the multidimensional array.
char score[10][10] = {' '};
...
4
votes
3answers
132 views
4
votes
1answer
52 views
Refactor Oxford Comma function (and other functions)
I wrote a program that managed projects and created a set of SQL files for each project. In the logic, I have a few functions that, each time I look at them, I wonder if they could be written in a ...
1
vote
1answer
52 views
Pretty print with unit and physical suffix II
Follow up of Pretty print with unit and physical suffix
My first code didn't process negative numbers correctly. Additionally I tried to use all of the helpful input to come up with this solution.
I ...
4
votes
1answer
40 views
Code for adjusting linelength
I wrote the following groovy function for taking a string of multiple lines (or any other character for splitting the code into parts), and bringing each line/part to a specified number of characters, ...
4
votes
1answer
66 views
Number formatting
As part of a simple (naive) internationalization attempt in Go, I am trying to come up with a number formatting routine with customizable decimal and thousands separator.
Is this approach alright?
...
2
votes
1answer
149 views
A better way to read text files into html?
Currently I'm making a website that has a to-do list that will probably become quite long to write in html. So I decided to make a shorter version for me to write that I find more comfortable to read.
...
6
votes
2answers
77 views
Building shape based on user input
The purpose of the below code is to build a shape based on the user input, specifically:
Prompt the user to enter a shape - either a triangle or a square
Determine which "texture" to use for the ...
10
votes
5answers
2k views
Vertically placing the words in a string
Please let me know a better approach to solve below problem:
Problem: Vertically arrange the words in a string and print on console.
Sample Input:
Hello Jack
...
3
votes
1answer
200 views
Format string inline
For this project, I do not have access to Boost or C++11.
Note: I updated the question's description to clarify what I am doing. I have not changed the code though, so no answer has been invalidated.
...
0
votes
1answer
51 views
Dealing with a dirty table
I have to deal with a really ugly looking response I get back from a particular device. The string represents a table. Each section of the string represents the form:
...
-1
votes
2answers
91 views
Efficient way to sort a formatted array (Chris Pine book, ch 7)
I'm on chapter 7 of Chris Pine's book, trying to work on the last exercise in that chapter. This code works fine, but I'm wondering if there is a better way to do this...
...
6
votes
1answer
200 views
Auto-Format GPA while typing
I'm looking for a more cleaner and simpler solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code:
...