Search Results

Search found 77 results on 4 pages for 'claudiu'.

Page 3/4 | < Previous Page | 1 2 3 4  | Next Page >

  • SQL get data out of BEGIN; ...; END; block in python

    - by Claudiu
    I want to run many select queries at once by putting them between BEGIN; END;. I tried the following: cur = connection.cursor() cur.execute(""" BEGIN; SELECT ...; END;""") res = cur.fetchall() However, I get the error: psycopg2.ProgrammingError: no results to fetch How can I actually get data this way? Likewise, if I just have many selects in a row, I only get data back from the latest one. Is there a way to get data out of all of them?

    Read the article

  • shared global variables in C

    - by Claudiu
    How can I create global variables that are shared in C? If I put it in a header file, then the linker complains that the variables are already defined. Is the only way to declare the variable in one of my C files and to manually put in externs at the top of all the other C files that want to use it? That sounds not ideal.

    Read the article

  • gcc run "light" preprocessor

    - by Claudiu
    Is there any way to run the gcc preprocessor, but only for user-defined macros? I have a few one-liners and some #ifdef etc... conditionals, and I want to see what my code looks like when just those are expanded. As it is, the includes get expanded, my fprintf(stderr)s turn into fprintf(((__getreeent())-_stderr), etc...

    Read the article

  • What percent of web sites use JavaScript?

    - by Claudiu
    I'm wondering just how pervasive JavaScript is. This article states that 73% of websites they tested rely on JavaScript for important functionality, but it seems to me that the number must be larger. Have any surveys been done on this topic? Maybe a better way to phrase this question is - are there any sites that don't use JavaScript? EDIT: By 'use', I don't necessarily mean "rely on for important functionality" - that was just the statistic that one article gave.

    Read the article

  • sql combine two subqueries

    - by Claudiu
    I have two tables. Table A has an id column. Table B has an Aid column and a type column. Example data: A: id -- 1 2 B: Aid | type ----+----- 1 | 1 1 | 1 1 | 3 1 | 1 1 | 4 1 | 5 1 | 4 2 | 2 2 | 4 2 | 3 I want to get all the IDs from table A where there is a certain amount of type 1 and type 3 actions. My query looks like this: SELECT id FROM A WHERE (SELECT COUNT(type) FROM B WHERE B.Aid = A.id AND B.type = 1) = 3 AND (SELECT COUNT(type) FROM B WHERE B.Aid = A.id AND B.type = 3) = 1 so on the data above, just the id 1 should be returned. Can I combine the 2 subqueries somehow?

    Read the article

  • Find most significant bit (left-most) that is set in a bit array

    - by Claudiu
    I have a bit array implementation where the 0th index is the MSB of the first byte in an array, the 8th index is the MSB of the second byte, etc... What's a fast way to find the first bit that is set in this bit array? All the related solutions I have looked up find the first least significant bit, but I need the first most significant one. So, given 0x00A1, I want 9.

    Read the article

  • sql generate unique table/view name

    - by Claudiu
    I want to create some mad robust code. I want to take a query as a string, create a temporary view / table to store the results, use it, then drop the table. I want to use a name that is guaranteed to not already exist in the database. Is there an SQL command to generate a unique table name? I'm using postgresql if this is implementation-specific.

    Read the article

  • bash "map" equivalent: run command on each file

    - by Claudiu
    I often have a command that processes one file, and I want to run it on every file in a directory. Is there any built-in way to do this? For example, say I have a program data which outputs an important number about a file: ./data foo 137 ./data bar 42 I want to run it on every file in the directory in some manner like this: map data `ls *` ls * | map data to yield output like this: foo: 137 bar: 42

    Read the article

  • Why is Postgres doing a Hash in this query?

    - by Claudiu
    I have two tables: A and P. I want to get information out of all rows in A whose id is in a temporary table I created, tmp_ids. However, there is additional information about A in the P table, foo, and I want to get this info as well. I have the following query: SELECT A.H_id AS hid, A.id AS aid, P.foo, A.pos, A.size FROM tmp_ids, P, A WHERE tmp_ids.id = A.H_id AND P.id = A.P_id I noticed it going slowly, and when I asked Postgres to explain, I noticed that it combines tmp_ids with an index on A I created for H_id with a nested loop. However, it hashes all of P before doing a Hash join with the result of the first merge. P is quite large and I think this is what's taking all the time. Why would it create a hash there? P.id is P's primary key, and A.P_id has an index of its own.

    Read the article

  • get n records at a time from a temporary table

    - by Claudiu
    I have a temporary table with about 1 million entries. The temporary table stores the result of a larger query. I want to process these records 1000 at a time, for example. What's the best way to set up queries such that I get the first 1000 rows, then the next 1000, etc.? They are not inherently ordered, but the temporary table just has one column with an ID, so I can order it if necessary. I was thinking of creating an extra column with the temporary table to number all the rows, something like: CREATE TEMP TABLE tmptmp AS SELECT ##autonumber somehow##, id FROM .... --complicated query then I can do: SELECT * FROM tmptmp WHERE autonumber>=0 AND autonumber < 1000 etc... how would I actually accomplish this? Or is there a better way? I'm using Python and PostgreSQL.

    Read the article

  • PostgreSQL function to iterate through/act on many rows with state

    - by Claudiu
    I have a database with columns looking like: session | order | atype | amt --------+-------+-------+----- 1 | 0 | ADD | 10 1 | 1 | ADD | 20 1 | 2 | SET | 35 1 | 3 | ADD | 10 2 | 0 | SET | 30 2 | 1 | ADD | 20 2 | 2 | SET | 55 It represents actions happening. Each session starts at 0. ADD adds an amount, while SET sets it. I want a function to return the end value of a session, e.g. SELECT session_val(1); --returns 45 SELECT session_val(2); --returns 55 Is it possible to write such a function/query? I don't know how to do any iteration-like things with SQL, or if it's possible at all.

    Read the article

  • create temporary table from cursor

    - by Claudiu
    Is there any way, in PostgreSQL accessed from Python using SQLObject, to create a temporary table from the results of a cursor? Previously, I had a query, and I created the temporary table directly from the query. I then had many other queries interacting w/ that temporary table. Now I have much more data, so I want to only process 1000 rows at a time or so. However, I can't do CREATE TEMP TABLE ... AS ... from a cursor, not as far as I can see. Is the only thing to do something like: rows = cur.fetchmany(1000); cur2 = conn.cursor() cur2.execute("""CREATE TEMP TABLE foobar (id INTEGER)""") for row in rows: cur2.execute("""INSERT INTO foobar (%d)""" % row) or is there a better way? This seems awfully inefficient.

    Read the article

  • More elegant way to initialize list of duplicated items in Python

    - by Claudiu
    If I want a list initialized to 5 zeroes, that's very nice and easy: [0] * 5 However if I change my code to put a more complicated data structure, like a list of zeroes: [[0]] * 5 will not work as intended, since it'll be 10 copies of the same list. I have to do: [[0] for i in xrange(5)] that feels bulky and uses a variable so sometimes I even do: [[0] for _ in " "] But then if i want a list of lists of zeros it gets uglier: [[[0] for _ in " "] for _ in " "] all this instead of what I want to do: [[[0]]*5]*5 Has anyone found an elegant way to deal with this "problem"?

    Read the article

  • step attribute not working with HTML5 <input type="range"> on Safari

    - by Claudiu
    Are there known issues with range inputs not working fully on Safari? I have the following input element: <input type=?"range" min=?"0" max=?"360" step=?"0.0001" value=?"0">? On Chrome, the input goes according to the step variable. On Safari, it only goes by integer values. Even setting the step to 10 still makes it go by increments of 1. I'm confused because I thought Chrome and Safari both used WebKit.

    Read the article

  • Python - Create a list with initial capacity

    - by Claudiu
    Code like this often happens: l = [] while foo: #baz l.append(bar) #qux This is really slow if you're about to append thousands of elements to your list, as the list will have to constantly be re-initialized to grow. (I understand that lists aren't just wrappers around some array-type-thing, but something more complicated. I think this still applies, though; let me know if not). In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be re-factored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there any equivalent for us python programmers?

    Read the article

  • change php variable on click event

    - by Claudiu
    I want to change php variable ($start and $end called by var b1 and var b2) if the user clicks on button. Now I know that php is server side, but how can I do it? I read something about using $get but I don't know how to implement it: <?php if ( is_user_logged_in() ) { ?> <input type="submit" value="Start Chat" id="start_chat" style="position: absolute; top: 30px; left: 10px;" /> <?php } ?> <script> jQuery('#start_chat').click(function(){ $(this).data('clicked', true); }); var b1 = '<?php echo $start; ?>'; var b2 = '<?php echo $end; ?>'; if(jQuery('#start_chat').data('clicked')) { // change var b1 and b2 } else { // do not change anything } </script> <div id="eu_la"> <?php $start = strtotime('9:30'); $end = strtotime('12:30'); $timenow = date('U'); if((date('w') == 4) && ($timenow >= $start && $timenow <= $end)) { // day 2 = Tuesday include('facut_mine.php'); } else { do_shortcode('[upzslider usingphp=true]'); } ?>

    Read the article

  • Optimizing Code

    - by Claudiu
    You are given a heap of code in your favorite language which combines to form a rather complicated application. It runs rather slowly, and your boss has asked you to optimize it. What are the steps you follow to most efficiently optimize the code? What strategies have you found to be unsuccessful when optimizing code? Re-writes: At what point do you decide to stop optimizing and say "This is as fast as it'll get without a complete re-write." In what cases would you advocate a simple complete re-write anyway? How would you go about designing it?

    Read the article

  • twisted .loseConnection does not immediately lose connection?

    - by Claudiu
    I have a server with a few clients connected to it. When CTRL+C is hit (that is, reactor starts shutting down), I want to close all my connections, wait until they are cleanly closed, and then stop. I do this by going through the connected clients' transports and calling .loseConnection(). On the ones that are connected locally, they immediately disconnect. However, on one that is connected through the internet, the connection is not immediately lost. Communication stops - and closing the client program no longer even tells the server that the connection has died, although it does before calling .loseConnection() - but the connection is not deemed 'lost' until a few minutes later after I send a few heartbeat requests from the server. I understand that if a connection dies, there's no way for the server to know unless it tries to send some data. But if I specifically ask for a connection to be closed, why does it not just close/disconnect immediately? Am I calling the wrong function?

    Read the article

  • sqlobject: No connection has been defined for this thread or process

    - by Claudiu
    I'm using sqlobject in Python. I connect to the database with conn = connectionForURI(connStr) conn.makeConnection() This succeeds, and I can do queries on the connection: g_conn = conn.getConnection() cur = g_conn.cursor() cur.execute(query) res = cur.fetchall() This works as intended. However, I also defined some classes, e.g: class User(SQLObject): class sqlmeta: table = "gui_user" username = StringCol(length=16, alternateID=True) password = StringCol(length=16) balance = FloatCol(default=0) When I try to do a query using the class: User.selectBy(username="foo") I get an exception: ... File "c:\python25\lib\site-packages\SQLObject-0.12.4-py2.5.egg\sqlobject\main.py", line 1371, in selectBy conn = connection or cls._connection File "c:\python25\lib\site-packages\SQLObject-0.12.4-py2.5.egg\sqlobject\dbconnection.py", line 837, in __get__ return self.getConnection() File "c:\python25\lib\site-packages\SQLObject-0.12.4-py2.5.egg\sqlobject\dbconnection.py", line 850, in getConnection "No connection has been defined for this thread " AttributeError: No connection has been defined for this thread or process How do I define a connection for a thread? I just realized I can pass in a connection keyword which I can give conn to to make it work, but how do I get it to work if I weren't to do that?

    Read the article

  • sql select from a large number of IDs

    - by Claudiu
    I have a table, Foo. I run a query on Foo to get the ids from a subset of Foo. I then want to run a more complicated set of queries, but only on those IDs. Is there an efficient way to do this? The best I can think of is creating a query such as: SELECT ... --complicated stuff WHERE ... --more stuff AND id IN (1, 2, 3, 9, 413, 4324, ..., 939393) That is, I construct a huge "IN" clause. Is this efficient? Is there a more efficient way of doing this, or is the only way to JOIN with the inital query that gets the IDs? If it helps, I'm using SQLObject to connect to a PostgreSQL database, and I have access to the cursor that executed the query to get all the IDs.

    Read the article

  • Java: Efficient Equivalent to Removing while Iterating a Collection

    - by Claudiu
    Hello everyone. We all know you can't do this: for (Object i : l) if (condition(i)) l.remove(i); ConcurrentModificationException etc... this apparently works sometimes, but not always. Here's some specific code: public static void main(String[] args) { Collection<Integer> l = new ArrayList<Integer>(); for (int i=0; i < 10; ++i) { l.add(new Integer(4)); l.add(new Integer(5)); l.add(new Integer(6)); } for (Integer i : l) { if (i.intValue() == 5) l.remove(i); } System.out.println(l); } This, of course, results in: Exception in thread "main" java.util.ConcurrentModificationException ...even though multiple threads aren't doing it... Anyway. What's the best solution to this problem? "Best" here means most time and space efficient (I realize you can't always have both!) I'm also using an arbitrary Collection here, not necessarily an ArrayList, so you can't rely on get.

    Read the article

< Previous Page | 1 2 3 4  | Next Page >