Search Results

Search found 5 results on 1 pages for 'bemmu'.

Page 1/1 | 1 

  • Average of two strings in alphabetical/lexicographical order

    - by Bemmu
    Suppose you take the strings 'a' and 'z' and list all the strings that come between them in alphabetical order: ['a','b','c' ... 'x','y','z']. Take the midpoint of this list and you find 'm'. So this is kind of like taking an average of those two strings. You could extend it to strings with more than one character, for example the midpoint between 'aa' and 'zz' would be found in the middle of the list ['aa', 'ab', 'ac' ... 'zx', 'zy', 'zz']. Might there be a Python method somewhere that does this? If not, even knowing the name of the algorithm would help. I began making my own routine that simply goes through both strings and finds midpoint of the first differing letter, which seemed to work great in that 'aa' and 'az' midpoint was 'am', but then it fails on 'cat', 'doggie' midpoint which it thinks is 'c'. I tried Googling for "binary search string midpoint" etc. but without knowing the name of what I am trying to do here I had little luck.

    Read the article

  • Filtering by entity key name in Google App Engine on Python

    - by Bemmu
    On Google App Engine to query the data store with Python, one can use GQL or Entity.all() and then filter it. So for example these are equivalent gql = "SELECT * FROM User WHERE age >= 18" db.GqlQuery(gql) and query = User.all() query.filter("age >=", 18) Now, it's also possible to query things by key name. I know that in GQL you do it like this gql = "SELECT * FROM User WHERE __key__ >= Key('User', 'abc')" db.GqlQuery(gql) But how would you now use filter to do the same? query = User.all() query.filter("__key__ >=", ?????)

    Read the article

  • Average of two strings in alphabetical order

    - by Bemmu
    Suppose you take the strings 'a' and 'z' and list all the strings that come between them in alphabetical order: ['a','b','c' ... 'x','y','z']. Take the midpoint of this list and you find 'm'. So this is kind of like taking an average of those two strings. You could extend it to strings with more than one character, for example the midpoint between 'aa' and 'zz' would be found in the middle of the list ['aa', 'ab', 'ac' ... 'zx', 'zy', 'zz']. Might there be a Python method somewhere that does this? If not, even knowing the name of the algorithm would help. I began making my own routine that simply goes through both strings and finds midpoint of the first differing letter, which seemed to work great in that 'aa' and 'az' midpoint was 'am', but then it fails on 'cat', 'doggie' midpoint which it thinks is 'c'. Rather than invent a method I thought it better to ask. I tried Googling for "binary search string midpoint" etc. but without knowing the name of what I am trying to do here I had little luck.

    Read the article

  • Pick random property from a Javascript object

    - by Bemmu
    Suppose you have a Javascript object like {'cat':'meow','dog':'woof' ...} Is there a more concise way to pick a random property from the object than this long winded way I came up with: function pickRandomProperty(obj) { var prop, len = 0, randomPos, pos = 0; for (prop in obj) { if (obj.hasOwnProperty(prop)) { len += 1; } } randomPos = Math.floor(Math.random() * len); for (prop in obj) { if (obj.hasOwnProperty(prop)) { if (pos === randomPos) { return prop; } pos += 1; } } }

    Read the article

  • Text to a PNG on App Engine (Python)

    - by Bemmu
    Note: I am cross-posting this from App Engine group because I got no answers there. As part of my site about Japan, I have a feature where the user can get a large PNG for use as desktop background that shows the user's name in Japanese. After switching my site hosting entirely to App Engine, I removed this particular feature because I could not find any way to render text to a PNG using the image API. In other words, how would you go about outputting an unicode string on top of an image of known dimensions (1024x768 for example), so that the text will be as large as possible horizontally, and centered vertically? Is there a way to do this is App Engine, or is there some external service besides App Engine that could make this easier for me, that you could recommend (besides running ImageMagick on your own server)?

    Read the article

1