Questions tagged [humanize]

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

37 questions
164
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
  • 12,867
  • 9
  • 42
  • 52
86
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
  • 60,067
  • 49
  • 172
  • 221
37
votes
6 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…
jamtoday
  • 4,734
  • 5
  • 37
  • 48
28
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
  • 813
  • 2
  • 11
  • 18
21
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
  • 11,951
  • 16
  • 49
  • 98
17
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
  • 175
  • 1
  • 1
  • 4
11
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
  • 18,642
  • 20
  • 100
  • 212
9
votes
2 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,490
  • 4
  • 25
  • 45
8
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,395
  • 11
  • 51
  • 81
8
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
  • 38,095
  • 68
  • 199
  • 359
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
  • 171
  • 2
  • 7
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
  • 51,803
  • 63
  • 138
  • 208
4
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
  • 4,670
  • 6
  • 41
  • 76
2
votes
1 answer

Python's humanize timedelta() tells me that minimum_unit is an invalid argument?

I am trying to print the approximate time difference between two dates. In the really well answered question here: Format timedelta to string several answers were given, and I can use one of those to solve my issue. However, I really liked the…
Maxim Moloshenko
  • 295
  • 2
  • 10
2
votes
2 answers

Forcing "humanized" names of fields to be lowercase in Rails 3

As far as I know, the accepted way to set the "humanized" names of fields in Rails 3 is to use locales: # config/locales/en.yml en: activerecord: attributes: member: username: 'username' # rather than 'Username' However, I…
ClosureCowboy
  • 18,648
  • 13
  • 53
  • 68
1
2 3