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
6
votes
2answers
7k views

Reformatting a date from YYYY-MM-DD to MM/DD/YYYY

In this small bit of JavaScript, a date is passed in as YYYY-MM-DD. It's formatted like this to be passed to the backend system. On the front end, we need to ...
5
votes
2answers
2k views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...
1
vote
1answer
33 views

JavaScript date format string to php date format string convert

Please find the following scenario, I've dynamic JS date format string from API but I am looking for the best way to convert the format that accepts in PHP date format. For now, I wrote it my own way ...
2
votes
3answers
103 views

Convert string format python

I want to fix number of digits after '.' in digit represented by string. Is there better solution than mine? My code ...
2
votes
3answers
6k 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, ...
6
votes
1answer
314 views

K&R Exercise 1-21. Write a program `entab` that replaces strings of blanks with tabs

Intro I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. I believe that the author's ...
15
votes
3answers
1k views

Logger module in C

I wrote a logger module in C, that is essentially a printf wrapper + some additional color coding: I'd like get feedback how I can improve performance and also use better coding style. Right now, I ...
14
votes
0answers
431 views

Document formatting markup engine in Postscript

I've been rewriting this same sort of thing off and on over the years, but finally here's the "perfected" monstrosity. Some kruft in the middle with attempting to predict the number of ...
10
votes
2answers
349 views

Comma formatted list printer

I'm working on a list practice project from the book "Automate the Boring Stuff with Python" which asks for this: Write a function that takes a list value as an argument and returns a ...
4
votes
1answer
2k views
4
votes
1answer
24 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
144 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
207 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 ...
12
votes
4answers
2k views

Prettify JSON class

It's not much, but I tried employing some of the things I learned yet never really got to use, since that kind of code isn't really needed where I work (for the most part). I tried making it as much C+...
4
votes
2answers
60 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 ...
5
votes
3answers
4k views

Efficient human readable timedelta

I wanted to write a human readable datetime.timedelta that can be used in log files. Eg, "Report issued 1 hour, 44 minutes, 20 seconds ago" I noticed that casting a timedelta to str() generates ...
7
votes
2answers
87 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 ...
36
votes
7answers
97k views

Setting a default value if a variable is empty

This is the pattern I've been using for "if the variable is empty, set a default value", and for variables like $muffin, it has all seemed well and good. But in ...
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
53 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 ...
6
votes
3answers
6k views

Print list items in a rectangular frame

The aim is to have that: list ["Hello", "World", "in", "a", "frame"] And make it printed like this: ...
4
votes
1answer
250 views

Polynomial implementation in Golang

I am writing a numerical analysis library in golang for which I need to implement a polynomial struct. Here is the source code: ...
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
2answers
386 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 ...
7
votes
3answers
6k views

Wrapping single line string to multiple lines with specific length

Problem A single line should be separated by Environment.NewLine so that each row has a length of columns (expect for the last ...
1
vote
1answer
28 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. ...
6
votes
2answers
339 views
5
votes
1answer
77 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
56 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
3k views

Printing an array in columns

I'm trying to define a function which takes an array and prints it to a predefined total width in as many columns as needed. Think of the way ls prints files for ...
15
votes
1answer
554 views

Signed integer-to-ascii x86_64 assembler macro

I have implemented an algorithm which converts a signed integer to its ASCII equivalent string with the corresponding sign as a first byte. I have tested it on several numbers and it worked correctly. ...
3
votes
1answer
48 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 ...
2
votes
1answer
158 views

Converting date format in range of cells

This code works, but I was wondering if there's a way to get excel to identify the date data more easily. This comes from an imported file where the date field(s) come in as text and in a European ...
0
votes
1answer
117 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: ...
21
votes
3answers
659 views

Formatted print without the need to specify type matching specifiers using _Generic

This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
1
vote
0answers
19 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 ...
44
votes
1answer
2k views

JSON formatter in your least favorite language

Just joking guys, Brainfuck is an awesome, challenging language. I've tested the following code with bf-x86 compiler and rather big JSON file. I believe code is fully functional on a valid (!) JSON ...
5
votes
2answers
903 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
91 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
122 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
68 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 ...
16
votes
1answer
4k views

Pretty printing of the numpy ndarrays

Following this idea for pretty printing of numpy ndarrays, I have developed a very primitive prototype: ...
5
votes
1answer
252 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/...
12
votes
2answers
887 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: ...
4
votes
2answers
201 views

/proc/net/tcp results filter and converter

Being unable to easily read the output of /proc/net/tcp I made a small C# console app that modifies the output to be in decimal notation instead of the standard hexadecimal, show the corresponding ...
15
votes
5answers
5k views

Program to print a Python list as “a, b, and c”

I am a beginner (with zero Python experience) working through the book Automate the boring stuff with Python. At the end of Chapter 4, the author provides a review problem. I was supposed to write a ...
1
vote
2answers
1k views

Function that adds commas between groups of 3 digits in a string

My program contains some very large integers and uses the GMP library. The output contains integers (probably small enough to fit into int). I would like to make ...
11
votes
2answers
9k views

Printing a calendar for a month based on user input

I have a long piece of code that has many repeating points. I am sure that it doesn't take this amount of code to create a simple calendar, but I do not know how to shorten this piece of code. ...
8
votes
3answers
3k views

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

Here is a practice exercise — Fantasy Game Inventory \$-\$ You are creating a fantasy video game. The data structure to model the player’s inventory will be a dictionary where the keys are string ...
7
votes
4answers
246 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 ...

1
2 3 4 5
11