Questions tagged [formatting]

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.

Filter by
Sorted by
Tagged with
4
votes
1answer
23 views

Creating formatted “[time] [unit] ago” messages from a seconds value

I have this function which calculates how many seconds, mins, hours etc ago a specific time string was. However, the way I have done it consists of a massive if statement block, and it goes through ...
10
votes
2answers
111 views

Text based rendering/animation engine for the terminal

This project was highly inspired by the popular drawille project, that lets one draw to the terminal using the braille unicode characters. The advantage of drawing with braille characters compared to ...
5
votes
2answers
130 views

Can it be shorter?: DNA Sequence Analyzer from CS50 written in Python

This is my first time requesting a code review. This is code I wrote in Python to create a DNA sequence analyzer. This is for the Harvard CS50 course. I was really hoping to get some constructive ...
4
votes
2answers
56 views

Format string processing similar to date or printf()

I wrote a function that is supposed to take a format string similar to what date accepts and replace all format specifiers with strings provided by a callback ...
3
votes
1answer
41 views

XML Tree Reformatter requested code. C#

So this is a post as per request in a different post on stack overflow: https://stackoverflow.com/questions/62412713/why-does-my-c-sharp-xml-code-only-work-when-i-enumerate-variable-enumerable. The ...
2
votes
1answer
49 views

Command Line app for calculating payroll in Java

I had an assignment last semester to program a payroll app utilizing methods. I went back to it and re-wrote it to include an extra class as well. I would like some feedback regarding whether my code ...
7
votes
2answers
85 views

Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
5
votes
2answers
379 views

Dynamic String Alignment Code

My code works for user output alignment to the right side by maximum length of 4 different user input. I have 2 question. Is there a simplier way for append method in my code ? Is there a simplier ...
6
votes
2answers
332 views

Creating and listing a song collection

Songs Class: ...
2
votes
1answer
42 views

Better filereading and print formating in R

I am a beginner using R and I am trying to solve some simple statistics problems and print the output. The following code takes in two datasets, computes the mean, ...
5
votes
1answer
69 views

ROT128 byte-transformation encoding

I'd like some feedback on code I wrote to obfuscate text on-disk. The basic idea is the same as ROT13 (which is implemented in the Python standard library), except instead of rotating the English ...
1
vote
1answer
27 views

Customized method for dataframe in my analysis module

Please download the file and save in home directory and extract it: https://www.dropbox.com/s/swtw8bk35zr1i6d/analyse.7z?dl=0 I can get some warrants info. ...
1
vote
1answer
55 views

Altering spreadsheet data

I have the below code that helps me do some formatting. But I want to increase the efficiency of the code by making it faster. Below are the formatting steps of the macro. Convert "Q" and "S" column ...
3
votes
1answer
46 views

A sequence/series formula solver

I made a formula retriever that works and allows importing of fractions. This python code is meant for the fx-cg50 calculator's micropython, where there are a lot of functions that don't work ...
0
votes
1answer
113 views

Format raw bytes in hex and ascii in manner like Wireshark does

This function formats raw buffer output in manner as Wireshark and many others does: ...
1
vote
0answers
16 views

Terraform/HCL - First element (or any arbitrary element) from a list of sets, combined into a list

So I am working with Terraform and I feel like there must be a faster or, at the very least, a prettier way to perform the operation I'm attempting. For some boilerplate, I have a data block that ...
0
votes
0answers
22 views

Formatter for converting legacy markup to markdown links

This program converts legacy markup in the form seen in the tests to the resulting markdown seen in the test's respective comment. The full program is as uploaded as a snippet, or you may see below <...
4
votes
1answer
84 views

Using composition instead of inheritance and abstract classes

I have a tool that displays data in some format. For example, it can display a list of dogs in a CSV or JSON formats. In the code, I had a lot of places where I had to check the format and display ...
7
votes
1answer
121 views

Writing a test to validate that the repo is formatted

I have a short test to validate that all committed files in the repo are formatted. I'm new to go so not sure what the best wat to do it is. The error handling, in particular, is rather gruesome as ...
3
votes
1answer
62 views

Formatting a type's name

I'm writing a code generation library, I've exposed a couple of methods and of course in order to define a member you need to specify it's type, the easiest way is to use ...
12
votes
2answers
875 views

Python algorithm that converts array-like data into MathJax

I frequently use MathJax, and often I need to write matrices. Since writing matrices using MathJax is very tiresome task, I decided to automate it. Code: ...
5
votes
1answer
192 views

Parsing and formatting var_export() string

I have this script to format var_export's result string. The information in the output is good, but I need know if the code performance is good or if it can be improved. https://wtools.io/php-sandbox/...
7
votes
4answers
230 views

Code that reads/writes to bytes of an ascii-encoded hex string

Problem Statement Given a hexadecimal string (hascii) and its binary specification (a list of byte field names, their offsets, and byte lengths), design classes to parse all byte-fields, cast bytes ...
4
votes
1answer
81 views

Manually formatting numbers in Python

I was working on a little Python challenge that was a bit more difficult than expected: format any non-negative number so 1000 turns into ...
12
votes
4answers
1k views

Comma Code - Automate the Boring Stuff with Python

Below is my code for the Comma Code problem from Chapter 4 of Automate the Boring Stuff with Python. Is there anything I can do to make it cleaner? Comma Code Say you have a list value like this: ...
7
votes
1answer
172 views

Replacing spaces with tabs. Exercise 1-21 in “The C Programming Language”

I'm looking for feedback on the code I came up with for exercise 1-21 in "The C Programming Language" by K&R. Write a program entab that replaces strings of blanks with the minimum number of ...
4
votes
3answers
379 views

Python process tracklist, get cumulative timestamp of each track

The code below parses a tracklist (sample input below) and generates a six-member tuple, including cumulative timestamps in mm:ss. (sample output at bottom). ...
10
votes
2answers
1k views

Converting time in number of minutes past midnight to HH:MM format

This program is a clock that only displays minutes passed since midnight. This program is supposed to be really simple but because of some "aesthetic bug", I wrote quite a lot if-else statements that ...
2
votes
2answers
87 views

Print Integers in a Pyramid

I need to write a method that will print the integers from [1, maxValue] in a pyramid where the nth row contains ...
17
votes
5answers
5k views

Printing a list as “a, b, c.” using Python

Is there a better way to do this? Assuming very long lists, is this slow and wasteful? ...
6
votes
2answers
351 views

Safe and simple strtol()

Until today, in the few cases where I needed something like this, it had been in simple programs which only I used, and where I didn't care about security, so I used the simple ...
-1
votes
2answers
100 views

Format and return a string from a function in C [closed]

Write a function that will format a string and return it A fixed length of string is malloc-ed. snprintf is used to format the string and then the buffer is ...
3
votes
1answer
58 views

List of dates with special formatting

I have a code that calls many times a function returning a list of the dates between two dates formatted as ('0001-01-01 00:01:00'),('0001-01-02 00:01:00'), ... The current solution is: ...
1
vote
1answer
33 views

Generating HTML for prerolled d20 RPG initiative tables

A fairly simple program that I tried to write in Common Lisp in order to practice/learn. I'm sure this can be done more elegantly but Lisp's string handling seems to be very werd. ...
1
vote
1answer
109 views

Constructor function for persons with hobbies

I'm trying to write a constructor function that generates instances of a user. One of the properties of the user class is an array of the user's hobbies. I'd like ...
7
votes
2answers
3k views

`printf` improvement with C++ variadic templates

I am currently working through learning C++'s variadic templates and I wanted to create an example use of them that is less trivial than the one in my book. I decided to create a modification of ...
3
votes
1answer
88 views

Date format function in JavaScript

How can I improve the date format function. I have written in javascript (ES5/ES6)? This code is just a part of an exercise. ...
2
votes
1answer
141 views

Image Processing - Comparing 2 images and Ranking Similarity

My code compares 2 images of any shape/dimension and ranks them in order of similarity. It starts with reading from a CSV file with columns image1, image2 which contain absolute paths and then ...
2
votes
2answers
4k views

HackerRank Time Conversion solution

The challenge (PDF) is to convert a time from 12-hour format (hh:mm:ssAM or hh:mm:ssPM) to 24-hour format. This is my solution, ...
15
votes
2answers
2k views

Message-formatting code with pluralization, revised to be more functional

I'm a C++ dev, and I've recently started working my way through Clean Code*. Whenever I encounter an example I think I could improve, I try to re-implement it in C++. On pp. 28-29 there is an example ...
4
votes
2answers
149 views

Displaying IP addresses in Go using Stringer interface

I am trying out some Go code examples (while coding a private project) to get more "in-depth" knowledge about the language. I have come across an exercise from the Go Tour website about displaying ...
4
votes
1answer
78 views

Pivotting SQL Table Response to JSON in JavaScript

Issue Our API returns two formats JSON and this SQL table format. I'm not sure what it is truly called so I'll give a few examples below. Like all API responses, it can be a list or a single response ...
1
vote
1answer
153 views

Format double to 3 decimal places without decimal separator to a certain length

I need to format a double value to three decimal places to a string with length of 9 with leading spaces and no decimal separator. My approach is this ...
4
votes
2answers
176 views

Print a pattern of text based on a line from an Excel file

I started to learn Python not long ago to automate certain tasks I work on. I want to optimize a script I wrote that takes a line in an Excel file and prints a pattern of text based on this line's ...
7
votes
3answers
378 views

Convert integer to full text string duration

I have a function I have written in VB for use in SSRS 2012. It takes an integer and converts it to full text duration - for example 900 becomes "15 minutes", 9000 becomes "2 hours 30 minutes", and ...
5
votes
3answers
235 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
3
votes
1answer
89 views

Left or right padding a string with the specified character

Can I improve performance of below method? Is there anything I need to optimize or any redundancy I need to remove to make it more efficient? It's a simple method used to pad strings by left or right. ...
5
votes
2answers
862 views

Printing a multiplication table in C [closed]

I'm a complete beginner, but I'd like to learn how to program. I really started 2 weeks ago. So I tried the common exercise, aka the multiplication table, but I tried to add little things I learnt ...
4
votes
1answer
75 views

Print a Connect 4 grid based on some rules for each cell

In a game of Connect4: we start with an empty grid two players place pieces X and O on the grid the first player to achieve 4 pieces in a line wins! this is a text based console game Here is the ...
3
votes
1answer
53 views

Apply same format function to each python print() parameter

I have a python print statement and inside the string I wish to print are four digits. I would like to apply the same formatting function to each param. I am not ...

1
2 3 4 5
11