human-readable

objective-c NSFilePosixPermissions to human readable NSString

匆匆过客 提交于 2019-12-19 06:56:08
问题 is there a way to get human readable string (@"drwxr-xr-x" for example) from an NSFilePosixPermissions integer ? 回答1: The file system permissions attribute is simply an unsigned long value. The code below could obviously be made more efficient but it shows [more or less] what needs to be done to get the string you want: // The indices of the items in the permsArray correspond to the POSIX // permissions. Essentially each bit of the POSIX permissions represents // a read, write, or execute bit

Natural/Relative days in Python

谁说胖子不能爱 提交于 2019-12-17 09:19:38
问题 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 not using the Django framework, and even if I were, it's more limited than what I'd like. Please let me (and generations of future searchers) know if there is a good working solution already. Since this is a common enough task, I imagine there must

Decode raw Scapy data to human readable

我只是一个虾纸丫 提交于 2019-12-11 00:34:00
问题 I'm trying to switch to using Scapy instead of Wireshark, but am having trouble decoding the data I'm getting. In Wireshark I can easily see the last layer for filtered packets labeled as "Distributed Interactive Simulation", but in Scapy the last layer is "Raw". I'm trying to get the data from this layer in the same human readable format. So far I've gotten: # Capture with Scapy from scapy.all import sniff capture = sniff(filter="dst 10.6.255.255 and port 3000", count=5) packet = capture[0]

Printing dictionaries (JSON) human readable

て烟熏妆下的殇ゞ 提交于 2019-12-10 17:22:59
问题 Lets say I have a (nested) dictionary like this (notice the lists-values): dic = {'level1': {'level2':(1, 2), 'level3': [ {'level4': (1, 2)}, {'level5': (1, 2)} ] } } I am looking for a proper way to print this dictionary, I am using json to do this: import json print json.dumps(dic, indent=4) and the above code gives me the following output: { "level1": { "level2": [ 1, 2 ], "level3": [ { "level4": [ 1, 2 ] }, { "level5": [ 1, 2 ] } ] } } While the above output is pretty good, it is still

Php - return count() in words

本小妞迷上赌 提交于 2019-12-07 18:02:55
问题 I have the following in my code: $my_count = count($total_elements[$array_object]); $my_count now contains the number of elements in $total_elements[$array_object] . I want to convert this number into its corresponding natural number (zero, one, two, ...) In this specific case , I only have 5 numbers : $numbers = array( 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', ); How to retrieve the number of elements in a given array and then echo the corresponding natural number

Scala Pattern Matching pretty printed

不羁岁月 提交于 2019-12-07 03:20:57
问题 Is that possible to somehow marshall PartialFunction (let's assume it will always contains only one case) into something human-readable ? Let's say we have collection of type Any (messages: List[Any]) and number of PartialFuntion[Any, T] defined using pattern matching block. case object R1 case object R2 case object R3 val pm1: PartialFunction[Any, Any] = { case "foo" => R1 } val pm2: PartialFunction[Any, Any] = { case x: Int if x > 10 => R2 } val pm3: PartialFunction[Any, Any] = { case x:

Grammatically correct human readable string from list (with Oxford comma)

我的梦境 提交于 2019-12-06 08:00:56
问题 I want a grammatically correct human-readable string representation of a list. For example, the list ['A', 2, None, 'B,B', 'C,C,C'] should return the string A, 2, None, B,B, and C,C,C . This contrived example is somewhat necessary. Note that the Oxford comma is relevant for this question. I tried ', '.join(seq) but this doesn't produce the expected result for the aforementioned example. Note the preexisting similar questions: How to print a list in Python "nicely" doesn't concern with a

Writing white-space delimited text to be human readable in Python

自古美人都是妖i 提交于 2019-12-06 06:03:17
问题 I have a list of lists that looks something like this: data = [['seq1', 'ACTAGACCCTAG'], ['sequence287653', 'ACTAGNACTGGG'], ['s9', 'ACTAGAAACTAG']] I write the information to a file like this: for i in data: for j in i: file.write('\t') file.write(j) file.write('\n') The output looks like this: seq1 ACTAGACCCTAG sequence287653 ACTAGNACTGGG s9 ACTAGAAACTAG The columns don't line up neatly because of variation in the length of the first element in each internal list. How can I write

Php - return count() in words

家住魔仙堡 提交于 2019-12-06 03:51:30
I have the following in my code: $my_count = count($total_elements[$array_object]); $my_count now contains the number of elements in $total_elements[$array_object] . I want to convert this number into its corresponding natural number (zero, one, two, ...) In this specific case , I only have 5 numbers : $numbers = array( 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', ); How to retrieve the number of elements in a given array and then echo the corresponding natural number (human readable number) from the array? Or better yet - is there a better way of doing this? (I have found

MongoDB geo distance/radius to useful units

旧街凉风 提交于 2019-12-04 13:08:29
问题 I'm using MongoDB geospatial queries -- $near , geoNear , etc. -- and I'd like to know how to turn the dis result of the geoNear command as well as the radius argument for $within queries to/from readable units like miles or kilometers. 回答1: if your data is in geographic coordinates (i.e. 30.47921 N -121.45724 W) then you need to convert your underlying projection with the units you want (choose a projection that preserves distance) or you need to convert the distance in coordinates to