As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label random. Show all posts

I was bored, looking for something to read, then I have:


I wrote a script rndeat.py, using python-recipes for accessing ActiveState Code and Pygments (optional) for syntax highlighting, to randomly pick one recipe:


You can query with one programming language and/or tags to get a random recipe. Here is the help of this simple script:
$ ./rndeat.py -h
usage: rndeat.py [-h] [-l LANG] [-t [TAG [TAG ...]]] [-s STYLE]

Random eats.

optional arguments:
  -h, --help            show this help message and exit
  -l LANG, --lang LANG  show recipe in the language (default: python)
  -t [TAG [TAG ...]], --tags [TAG [TAG ...]]
                        show recipe with tags
  -s STYLE, --style STYLE
                        highlighting style, "list" to get a list of styles
                        (default: default)
It ridiculously uses 3 API calls in order to get a random recipe, although it could possibly reduce to 1 API in a long run if adding caching in this script. The Python recipes only have a few thousands, there might be somewhere you can download entire recipe database. But, it might just like the API, I can't find any documentation about it except this python-recipes, basically it's been two years without new commits.

If you don't have Pygments, you can use sed to extract the code by looking for code +: and use your favorite highlighter, even load into Vim. Well, or just hack the script, that would be quicker.

Some are really fun to read, some are bored and too long, some are even older than your son or daughter (dated back to 2001, as far as I can see).

I am thinking a -i for interactive mode, so it can cache data in memory and allows you to bring up Python interpreter with the script if possible. It might be easier and fun to play with the recipe.

Disclaimer: This code is licensed under the MIT License, I am not responsible to anything that this code can cause, including, but not limited to, any health issues, such as obesity, food poisoning, etc.

Just happened to notice that today is 2/11/2011 when I was adding an update to one of my posts. So here is a post about random things, I currently have in mind. Or I have been messing up with those.

Do you ever feel yourself inconsistent?

One moment before, you are so determined to make something happen, then you abandon the determination. One day before, you believe in something, then you question it. One month before, you are happy with the color of your, uhm, pants (?), then you think you shouldn't wear jeans. Heck, it's not even about the colors. One year before, you are content with how you did things, then you change every way you used to do.

You write in a blue notebook, then write to another smaller and black one, then you go back to take notes with first one. You split your notes into different notebooks because you want to have better organization, then merge everything back to only one because it's too many to handle.

The philosophy, the principle, the rule, the method, the atom, the everything, you change them constantly and they never seem okay to you. They are in extreme risk, any of them could be replaced anytime you want or you don't want. Any of them could be revised at any moment you are struck by a new idea wherever they come from, originally from your mind or you adopt (steal is another way to describe) from others.

They just can't be steady because of you.
They have to be changed, they must be, because of you
They don't want to be replaced and you don't want to do that, either, do you? Still because of you.

So, you are the problem.

* * *

Sometimes, I wish I could live in the future. The time and place you don't need to open a door, it will open automatically for you unless your ship is attacked and the control panel is fried, then you will have to open it manually. Everyone in that ship is either dead or captured by disgusting green fluid covered monster alien. Gone to far?

The era is technologically advanced and so is the culture.

A mind probing device can interpret your brain wave, whatever alpha, beta, ..., it can translate your thought, the imaginary scene in your mind. Is it a room? Dark, bright? How does sun shine the room? Can you see the dust floating? Can you smell the morning sunshine? Is it quiet at the backyard? Or can you hear kids playing in the street?

Every detail you are imagining, every feeling you want to experience, this device can discern and translate all of them into the program which can be loaded into holodeck. You can relive them, well, re-experience them in totally different light (funny, photon). You can adjust any detail, adding or deleting. You don't even need to say the command, you just think what you want.

If you don't have artistic talent, you can think you want something more or different, then you will have options to choose. You want a cup of coffee to taste like Monday morning (sad, you still need to work), you might be given a cup of bitter coffee, less cream, an awful cup literally. The cup isn't a coffee cup or a mug, it's a small bowl and broken, you are given that because you have piled up dirty dishes in the sink. Though this is not a good proper option, but that's how the device works.

You think you want to walk in park. That's all you can think of. The device adds a lake, a trail, some joggers, a loving couple is pushing a stroller with a lovely baby, who is waving at you. You can hear bird chirping, you can see the reflection on the water and people row the boats. People have picnics on the vivid green lawn, laughing, enjoying.

Then,

you feel you hate this! Because you are not happy after you sober up and recall that you get fired yesterday. Yes, that's Sunday. You get informed via Futwitter. It isn't a formal notification, it's a futweet, reads "ur fired."

The device immediately adds a giant snake, which emerges from the lake, then eats everyone.

* * *

Have you ever seen this ᑕᓯᓗᓕᐊᕆᐊ (tasiluliaria) Road to Nowhere sign?



It's introduced, well just a view pan only to sum up, in Billy Connolly's Journey to the Edge of the World.

When I first saw this Inuktitut text, I thought am I watching a Sci-fi show? The text looks like so alien to me. Maybe this sign is brought by my Jack O'Neill? (It's O'Neill, with two L's!)

Anyway, I should put it (seeing this sign) into my bucket list. Wait! I don't have that.

* * *

Since this year is '11, have you ever wanted to catch this moment, 11:11:11 11/11/11?

Silly? If you miss this time, you will have to wait for another 100 years. Hold on, you can't and you don't, because 2012 is coming up next.

* * *

I think Writing is like Cooking. If you put too many ingredients, that won't enrich your dish. If you add too many spices or seasonings, that will only ruin the taste. Balance is the key. Not too much, nor too little.

And the method is critical, what goes in first for how long and what heat. You could burn a meal, or make a gourmet dish, just like you can write a masterpiece or a garbage.

* * *

I hate how people use transliteration. It has "trans" but it's not as in translation at all.

For example, people post "Jiaozi (Chinese Dumplings)" as the post title. Why not just use "Chinese Dumpling" or always put original words "餃子" or "饺子" on.

I beg you not to only use transliteration. In fact, I don't want you to use transliteration unless there isn't a meaningful/understandable translation. The problem of using transliteration, in this case, is Jiaozi could be represented dumplings in different cuisines over the Southeastern Asia. You may argue that Jiaozi is Chinese Pinyin, the problem is they could be missed by others. As well as Gyoza. They all are messed up into one a big ugly dark anti-matter. Isn't "Chinese Dumpling" crystal clear?

Yes, you can read (Latin) letter by letter, but if you have never learned how to pronounce the transliteration of the language, you still can not pronounce it correctly. And, most of people just can't, there is no luck in it, there is no such thing you happen to speak transliteration correctly.

So, please don't write transliteration only. In fact, just write the translation. Writing "Chinese Dumplings" wouldn't make this dumpling less Chinese, writing "Jiaozi" wouldn't make this dumpling more Chinese.

* * *

Some idea about coding I had:

Button to record when I wake up and go to sleep
Text-to-generated-image to upload to Flickr as like a tweet from CLI
Nudge the author button for blog. If the blogger gets too lazy, reader can press that button.
Gadget to showing my memorable words/quotes.
System monitoring dashboard in Vimperator.
Feeding gcal (GNU cal) with gcal (Google Calendar) data.
Google Code Issues analyzer.
Can I do Cheese + Noodle using OOP (in Python)? And output a Recipe?
Studying decryption of OO.o, so I can write a script to search in encrypted documents.
Vimlastyt = Vimperator + Last.fm scrobbler + YouTube.
Pagination on the fly JavaScript.
Table of Contents JavaScript.
Blogger XML Backup file viewer.
Revamp my g directory switcher script.
Falling hearts in X.
A StackWhatever tracker using urwid.
urclis.py, using urwid as TUI.

* * *

Well, I think I have dump enough smelling garbage.

See you at next dumpster!

1   Counting

Every time, Google App Engine releases new version of SDK, I always read the release notes. I was aware of

Results of datastore count() queries and offsets for all datastore queries are no longer capped at 1000,

when version 1.3.6 was released. I wrote a quick code to test it, something like the followings:

count = TestModel.all().count()

data1 = TestModel.all().fetch(1100, offset=5)
data2 = TestModel.all().fetch(1, offset=1100)

Using 1.3.8, first part still got me 1000 at most. The second part, I could fetch more than 1000 entities, and the offset could be bigger than 1000 without problems.

I finally saw someone asked and the correct way is:

count = TestModel.all().count(limit=None)

Now, I am reading the documentation again:

count() has no maximum limit. If you dont specify a limit, the datastore continues counting until it finishes counting or times out.

This doesnt sound like the same behavior in development server. I didnt try it on production server.

(I used to use this way to count.)

2   Randomly fetching

Before 1.3.6, there are some ways to get a random entity from datastore. All suck and are awkward. Now offset can be supplied with number bigger then 1000. Does it resolve? Read this line first:

The query has performance characteristics that correspond linearly with the offset amount plus the limit.

Well, I dont care at this moment since none of my data are too large.

I think Google is Einstein and Google App Engine is Quantnum Theory. ;)

Do you know the next blog button on Blogger.com's navigation bar or WordPress.com's next button? Even the Delicious.com's randomizer button?



Now you can have them all (and even more) with just one button on your bookmark toolbar!



Build Next Button helps you create your own next button as long as you have random sources.



Let's kill your free time by clicking on NEXT button!



If you have other random source, leave me a comment with the link, I might add it as default random source.