Questions tagged [humanize]

To humanize is to make something friendlier to humans. Humanizing makes things more civilized, refined, and understandable.

44 questions
171
votes
12 answers

How do I convert CamelCase into human-readable names in Java?

I'd like to write a method that converts CamelCase into a human-readable name. Here's the test case: public void testSplitCamelCase() { assertEquals("lowercase", splitCamelCase("lowercase")); assertEquals("Class", splitCamelCase("Class")); …
Frederik
  • 14,156
  • 10
  • 45
  • 53
110
votes
9 answers

How to capitalize the first character of each word, or the first character of a whole string, with C#?

I could write my own algorithm to do it, but I feel there should be the equivalent to ruby's humanize in C#. I googled it but only found ways to humanize dates. Examples: A way to turn "Lorem Lipsum Et" into "Lorem lipsum et" A way to turn "Lorem…
marcgg
  • 65,020
  • 52
  • 178
  • 231
47
votes
12 answers

Title case a string containing one or more last names while handling names with apostrophes

I want to standardize a user-supplied string. I'd like the first letter to be capitalized for the name and if they have entered two last names, then capitalize the first and second names. For example, if someone enters: marriedname maidenname It…
user1048676
  • 9,756
  • 26
  • 83
  • 120
39
votes
5 answers

Natural/Relative days in Python

I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 has a "humanize" method in django.contrib. I'm…
JJ.
  • 4,974
  • 5
  • 39
  • 48
33
votes
1 answer

Django humanize outside of template?

I know I can use the humanize module to convert date/time to a friendlier format in the django templates. I was wondering if I can convert those things outside the templates. For example in a views.py function or a models.py class(meaning outside of…
averageman
  • 893
  • 3
  • 12
  • 19
23
votes
4 answers

Make big and small numbers human-readable

I would like to print my very small numbers in C# in a human friendly way, such as: 30µ for 3E-5 or 456.789n for 0.000000456789. I know of the Humanize_number() function from BSD in C, but only compatible with bit ints, not floats and doubles. Is…
Gui13
  • 12,993
  • 17
  • 57
  • 104
19
votes
4 answers

How to display "x days ago" type time using Humanize in Django template?

When I do this: {% load humanize %} {{ video.pub_date|naturaltime|capfirst }} I get 2 days, 19 hours ago How can I get just 2 days without the hours. Basically if the video was published in less than a day ago then it should say X hours ago, then…
Veme
  • 195
  • 1
  • 1
  • 4
14
votes
5 answers

Humanize a string in JavaScript

How do I humanize a string? Based on the following criteria: Deletes leading underscores, if any. Replaces underscores with spaces, if any. Capitalizes the first word. For example: this is a test -> This is a test foo Bar Baz -> Foo bar…
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
11
votes
3 answers

How to get human readable class name in Ruby on Rails?

I am building an application with Ruby 1.9.3 and Rails 3.0.9 I have a class like below. module CDA class Document def humanize_class_name self.class.name.gsub("::","") end end end I want the class name like "CDADocument". Is my…
Soundar Rathinasamy
  • 6,658
  • 6
  • 29
  • 47
9
votes
3 answers

How to properly calculate remaining time in JS using getTime() from the two dates?

I'm trying to calculate remaining time (ex: 10 years, 2 months and 10 days from today(2014/03/02) in JS using this function: var d2 = new Date(2024, 3, 12); var d1 = new Date(); var d0 = new Date(1970, 0, 1); var diff = new Date(d2.getTime() -…
craftApprentice
  • 2,697
  • 17
  • 58
  • 86
9
votes
5 answers

Formatting Large Numbers with .NET

I have a requirement to format large numbers like 4,316,000 as "4.3m". How can I do this in C#?
DaveDev
  • 41,155
  • 72
  • 223
  • 385
5
votes
2 answers

From: "1 hour ago", To: timedelta + accuracy

Is there a function to 'reverse humanize' times? For example, given (strings): '1 minute ago' '7 hours ago' '5 days ago' '2 months ago' Could return (apologies for the pseudo-code): datetime.now() - timedelta (1 minute), accuracy (60…
David Toy
  • 180
  • 2
  • 9
5
votes
1 answer

How to use django.contrib.humanize in a model

I would like to use the django.contrib.humanize outside of a template, actually inside a model to humanize some dates in some text messages. Is it possible? How can I do this?
André Luiz
  • 6,642
  • 9
  • 55
  • 105
5
votes
5 answers

What are the best ways to prevent fake registrations?

I would like to know more about the solutions to restrict registering for a website for humans only. Captcha may seem a proper solution but as it turns out it's not as good as it sounds. And it's not a problem if a solution is not an option for…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
3
votes
3 answers

Make first letter of each word/name uppercase, unless a known all-lowercase component of a surname

I use PHP to insert form entries into a MySQL database. Sometimes users enter text in all caps. Is there any way to change it so that only the first letters are capitalized? ucwords(strtolower($word)) won't work for me because I do not want to…
Brian
  • 26,662
  • 52
  • 135
  • 170
1
2 3