generator

PHP function to generate v4 UUID

So I've been doing some digging around and I've been trying to piece together a function that generates a valid v4 UUID in PHP. This is the closest I've been able to come. My knowledge in hex, decimal, binary, PHP's bitwise operators and the like is nearly non existant. This function generates a valid v4 UUID up until one area. A v4 UUID...

Can you tell me why this generates time limit exceeded in spoj(Prime Number Generator)

#include<iostream> #include<string.h> #include<math.h> using namespace std; bool prime[1000000500]; void generate(long long end) { memset(prime,true,sizeof(prime)); prime[0]=false; prime[1]=false; for(long long i=0;i<=sqrt(end);i++) { if(prime[i]==true) { for(long long y=i*...

Modify a file with a rails generator

How do you make a generator that alters a file. Im trying to make it so that it finds a pattern in a file and adds come content to the line below it. ...

Error Using Ruby generator in Rails (not Rails::Generator)

Edit: To be clear, I'm trying to use this kind of generator (i.e. with a 'yield' statement) not a Rails generator. I have the following (simplified) initializer mixin in a Rails project that I could use some help with. What I wanted to do was create a generator to track Twitter API calls (this is just for debugging, I know about rate_li...

Symfony (Propel) Admin Generator Behavior - Why does it work like this?

Hi there, I've been having some 'issues' with the admin generator (Propel version). The HTML generation behavior between the list view and the form view is very different, and I'd like to know why, as the form view works better (and as expected) compared to the list view. I have the following YAML for the 'edit' action, edit: action...

I'm a pretty good C# developer, but I've never done something like this; how would I create a CRUD application generator?

I found SubSonic, but I'd rather roll my own with a few buddies. I've never done something like this before, but if you tell me technically how I should proceed, I can figure it out. I want to have a sort of visual designer. Ask the user what tables there are going to be, the relations, what fields, which are primary keys, etc. Then g...

What good open source programs exist for fuzzing popular image file types?

I am looking for a free, open source, portable fuzzing tool for popular image file types that is written in either Java, Python, or Jython. Ideally, it would accept specifications for the fuzzable fields using some kind of declarative constraints. Non-procedural grammar for specifying constraints are greatly preferred. Otherwise, might...

How to implement an efficient infinite generator of prime numbers in Python?

This is not a homework, I am just curious. INFINITE is the key word here. I wish to use it as for p in primes(). I believe that this is a built-in function in Haskell. So, the answer cannot be as naive as "Just do a Sieve". First of all, you do not know how many consecutive primes will be consumed. Well, suppose you could concoct 100...

Retrieving related data in the Symfony Admin Generator

I have a problem with the Admin Generator. The Table of Pages have the column sf_guard_user_id. The rest of the table looks as this part of the generator.yml in the line display, list: title: Pages display: [=title, sfGuardUser, views, state, privacy, created_at, updated_at] sort: [created_at, desc] fields: sfGu...

hash functions family generator in python

Hi, I am looking for a hash functions family generator that could generate a family of hash functions given a set of parameters. I haven't found any such generator so far. Is there a way to do that with the hashlib package ? For example I'd like to do something like : h1 = hash_function(1) h2 = hash_function(2) ... and h1 and h2 would...

Random number in iphone sdk?

How do you generate a random number when a button is clicked, and depending on that number, different actions take place. I probably only need a random number from 1-10. -(IBACTION)buttonClicked{ "generate the random number" if(number == 1){ something happens } else if(number == 2){ somethine else happens } etc } ...

Get the nth item of a generator in Python

Is there a more syntactically concise way of writing the following? gen = (i for i in xrange(10)) index = 5 for i, v in enumerate(gen): if i is index: return v It seems almost natural that a generator should have a gen[index] expression, that acts as a list, but is functionally identical to the above code. ...

cx_Oracle, generators, and threads in Python

Hi all, What is the behavior of cx_Oracle cursors when the connection object is used by different threads? How would generators affect this behavior? Specifically... Edit: The original example function was incorrect; a generator was being returned by a sub function, yield wasn't used directly in the loop. This clarifies when finally...

Index and Slice a Generator in Python

Lets say I have a generator function that looks like this: def fib(): x,y = 1,1 while True: x, y = y, x+y yield x Ideally, I could just use fib()[10] or fib()[2:12:2] to get indexes and slices, but currently I have to use itertools for these things. I can't use a generator for a drop in replacement for lists. ...

Ugly combination of generator expression with for loop

The following appears in my Python 2.6 code: for src, dst in ([s,d] for s in universe for d in universe if s != d): Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression. I'm uncertain whether I'd prefer: for src, dst in ...

I'm looking for a good menu's picture generator that based on photoshop script.

I'm looking for a good menu's picture generator that based on photoshop script. It should be have an .psd file as input. the .pas file will contain the form of the menu item in the following modes: hovered, unovered and selected. Each mode defined by hiding and showing a few layers. The text layer will contain a 'placeholder-text' that ...

Nestedset in Admin Generator

Hello, in a table "list" i save the id of another table, list also act as a nestedset. In a form i can add a child to a root. I set the value of the root as hidden field in the form. So in doSave when he detected a value in the hidden field, he do this, $parent = Doctrine::getTable('list')->findOneById($this->getValue('parent_id')); $...

Does the Entity Framework 4 support generators for id values like NHibernate?

Does the Entity Framework 4 support generators for id values like NHibernate? NHibernate has generator classes to help with this. ...

How to get one value from a generator in Python?

Very basic question - how to get one value from a generator in Python? So far I found I can get one by writing gen.next(). I just want to make sure this is the right way? Thanks, Boda Cydo. ...

How do I modify a generator in Python?

Is there a common interface in Python that I could derive from to modify behavior of a generator? For example, I want to modify an existing generator to insert some values in the stream and remove some other values. How do I do that? Thanks, Boda Cydo ...