Q:

Multiple Recordsets Issue

I have the below SQL Script which is run from Excel VBA using ADO against a SQL Server 2000 database.
The issue I have is that although there is only one SELECT statement in the script, I sometimes receive three recordsets back when executing the .Open method. I say sometimes as on occassion and on other 'parallel' databases I only receive one recordset back.
I know all about the .NextRecordset() method etc. but I am trying to understand why I get three recordsets back some times and other times I only receive one. I'm shortly going to run a SQL trace to see if that throws up any ideas but as usual, any help or advice would be greatly appreciated.
SET NOCOUNT ON
DECLARE @RunDate VARCHAR(8)

SET @RunDate = CONVERT(VARCHAR(8), DATEADD(d, -1 * 1, GETDATE()), 112)

IF OBJECT_ID('tempdb..#ActiveOrders') IS NOT NULL DROP TABLE #ActiveOrders
IF OBJECT_ID('tempdb..#ApplicableOrders') IS NOT NULL DROP TABLE #ApplicableOrders
IF OBJECT_ID('tempdb..#FilterOut') IS NOT NULL DROP TABLE #FilterOut

/*Temp table created as it has a self-join in the below query */
CREATE TABLE #ActiveOrders(
    order_id VARCHAR(30)
    , instrument_id VARCHAR(30)
    , side CHAR(1)
    )

CREATE INDEX idx_ActiveOrders_orderId ON #ActiveOrders(order_id)

/*Build dataset of all orders which have had activity on the run date or are in an Open status. Ignoring Program Trades.*/
INSERT INTO #ActiveOrders
SELECT o1.order_id COLLATE Latin1_General_CI_AS
        , o1.instrument_id
        , o1.side
FROM orders o1
INNER JOIN desk d1 ON d1.desk_id = o1.investment_desk
INNER JOIN (SELECT o0.order_id
            FROM orders o0
            WHERE ((LEFT(o0.added_datetime, 8) = @RunDate
                    OR LEFT(o0.approved_datetime, 8) = @RunDate)
                    OR (LEFT(o0.added_datetime, 8) <= @RunDate
                    AND o0.summary_status IN (1, 2, 3, 5, 8, 9))) /*Approved, Assigned, Acknowledged, Working, Partial, WorkingPartial*/
            UNION
            (SELECT r0.order_id
            FROM releases r0
            WHERE LEFT(r0.added_datetime, 8) = @RunDate)
            UNION
            (SELECT e0.order_id
            FROM executions e0
            WHERE LEFT(e0.execution_datetime, 8) = @RunDate
                    OR LEFT(e0.allocated_datetime, 8) = @RunDate)
            ) t1 ON o1.order_id = t1.order_id
WHERE d1.location_id = 'LDEQ'
        AND o1.summary_status <> 4
        AND o1.list_id IS NULL /*Ignore program trades*/

/*This is now the actual dataset we are interested in.
This is everything which could be a contender for aggregation.*/
CREATE TABLE #ApplicableOrders(
    order_id VARCHAR(30)
    , instrument_id VARCHAR(30)
    , side CHAR(1)
    , approved_datetime DATETIME
    , acknowledged_datetime DATETIME
    , last_allocation_datetime DATETIME
    , latest_status INT
    , merged_orders VARCHAR(500)
    , dealer VARCHAR(100)
    , manager VARCHAR(100)
    , limit_price FLOAT
    , original_qty FLOAT
    , executed_qty FLOAT
    , trader_instruction TEXT
    , dealer_note TEXT
    )

CREATE INDEX idx_ApplicableOrders_orderId ON #ApplicableOrders(order_id)
CREATE INDEX idx_ApplicableOrders_lastAllocation ON #ApplicableOrders(last_allocation_datetime)
CREATE INDEX idx_ApplicableOrders_approved ON #ApplicableOrders(approved_datetime)

/*All orders from #ActiveOrders where there are two or more orders which are for the same instrument and in the same direction.*/
INSERT INTO #ApplicableOrders
SELECT o.order_id
        , o.instrument_id
        , o.side
        , dbo.mglz_datetime(o.approved_datetime)
        , dbo.mglz_datetime(o.ack_datetime)
        , MAX(dbo.mglz_datetime(e.allocated_datetime)) "Last Allocation DateTime"
        , o.summary_status
        , o.merged_orders
        , o.ack_id
        , o.approver_id
        , o.limit_price
        , o.original_qty
        , o.executed_qty_at
        , CONVERT(VARCHAR(900), o.trader_instruction)
        , CONVERT(VARCHAR(900), o.dealer_note)
FROM orders o
        INNER JOIN #ActiveOrders t ON o.order_id = t.order_id COLLATE Latin1_General_CI_AS
        INNER JOIN #ActiveOrders s ON s.order_id <> o.order_id COLLATE Latin1_General_CI_AS
                                        AND s.instrument_id = o.instrument_id COLLATE Latin1_General_CI_AS
                                        AND s.side = o.side COLLATE Latin1_General_CI_AS
        LEFT JOIN executions e ON e.order_id = o.order_id
GROUP BY o.order_id
        , o.instrument_id
        , o.side
        , o.approved_datetime
        , o.ack_datetime
        , o.summary_status
        , o.merged_orders
        , o.ack_id
        , o.approver_id
        , o.limit_price
        , o.original_qty
        , o.executed_qty_at
        , CONVERT(VARCHAR(900), o.trader_instruction)
        , CONVERT(VARCHAR(900), o.dealer_note)

/*Filter out any orders where Order2.Approved_Date > Order1.Last_Release_Date AND Order1.Is_Complete
Order1 is defined as the order which was approved first.*/
SELECT t1.*
INTO #FilterOut
FROM #ApplicableOrders t1
WHERE EXISTS (SELECT 1
                FROM
                    (SELECT order2.order_id
                    FROM (SELECT b.order_id
                                    , b.instrument_id
                                    , b.side
                                    , b.approved_datetime
                                    , b.last_allocation_datetime
                                    , b.latest_status
                                    , b.executed_qty
                                    , b.original_qty
                            FROM #ApplicableOrders b
                            WHERE b.approved_datetime = (SELECT MIN(b1.approved_datetime) FirstApproval
                                                        FROM #ApplicableOrders b1
                                                        WHERE b1.instrument_id = b.instrument_id
                                                            AND b1.side = b.side)
                        ) order1
                    INNER JOIN
                        (SELECT c.order_id
                                , c.instrument_id
                                , c.side
                                , c.approved_datetime
                            FROM #ApplicableOrders c
                            WHERE c.approved_datetime > (SELECT MIN(c1.approved_datetime) FirstApproval
                                                        FROM #ApplicableOrders c1
                                                        WHERE c1.instrument_id = c.instrument_id
                                                            AND c1.side = c.side)
                        ) order2
                    ON order1.instrument_id = order2.instrument_id
                        AND order1.side = order2.side
                        AND order2.approved_datetime > order1.last_allocation_datetime
                        AND (order1.latest_status = 6 OR order1.executed_qty = order1.original_qty)) filter1
                WHERE t1.order_id = filter1.order_id)

/*Filter out any orders where Order2.Acknowledged_Date > Order1.Last_Allocation_Date.*/
INSERT INTO #FilterOut
    SELECT t1.*
    FROM #ApplicableOrders t1
    WHERE EXISTS (SELECT 1
                    FROM
                        (SELECT order2.order_id
                        FROM (SELECT b.order_id
                                    , b.instrument_id
                                    , b.side
                                    , b.approved_datetime
                                    , b.last_allocation_datetime
                            FROM #ApplicableOrders b
                            WHERE b.approved_datetime = (SELECT MIN(b1.approved_datetime) FirstApproval
                                                        FROM #ApplicableOrders b1
                                                        WHERE b1.instrument_id = b.instrument_id
                                                            AND b1.side = b.side)
                            ) order1
                        INNER JOIN
                            (SELECT c.order_id
                                    , c.instrument_id
                                    , c.side
                                    , c.approved_datetime
                                    , c.acknowledged_datetime
                                FROM #ApplicableOrders c
                                WHERE c.approved_datetime > (SELECT MIN(c1.approved_datetime) FirstApproval
                                                            FROM #ApplicableOrders c1
                                                            WHERE c1.instrument_id = c.instrument_id
                                                                AND c1.side = c.side)
                            ) order2
                        ON order1.instrument_id = order2.instrument_id
                            AND order1.side = order2.side
                            AND order2.acknowledged_datetime > order1.last_allocation_datetime) filter2
                    WHERE t1.order_id = filter2.order_id)
    AND NOT EXISTS (SELECT 1
                    FROM #FilterOut a1
                    WHERE a1.order_id = t1.order_id)

/*Filter any 'single' orders. I.e. all 'matching' orders have been excluded so the instrument/direction combination is not applicable for Aggregation.*/
INSERT INTO #FilterOut
    SELECT t1.*
    FROM #ApplicableOrders t1 INNER JOIN (SELECT DISTINCT t.instrument_id
                                                            , t.side
                                            FROM #ApplicableOrders t
                                            INNER JOIN #FilterOut a ON t.instrument_id = a.instrument_id
                                                                                AND t.side = a.side
                                            GROUP BY t.instrument_id
                                                    , t.side
                                            HAVING COUNT(t.instrument_id) > 1) t2 ON t1.instrument_id = t2.instrument_id
                                                                                AND t1.side = t2.side
    WHERE NOT EXISTS (SELECT 1
                        FROM #FilterOut a1
                        WHERE a1.order_id = t1.order_id)

/*Final Report*/
/*A list of all orders where aggregation could have possibly occurred but didn't.*/
SELECT t1.order_id "Order ID"
        , i.name "Name"
        , t1.side "B/S"
        , userDealer.short_name "Dlr"
        , userManager.short_name "FM"
        , t1.limit_price "Limit"
        , t1.approved_datetime "Order Approved"
        , t1.acknowledged_datetime "Order Acknowledged"
        , t1.last_allocation_datetime "Last Execution"
        , t1.merged_orders "Merged Orders"
        , m.description "Status"
        , t1.dealer_note "Dealer Note"
        , t1.trader_instruction "Trader Instruction"
FROM #ApplicableOrders t1
    INNER JOIN instrument i ON t1.instrument_id = i.instrument_id COLLATE Latin1_General_CI_AS
    INNER JOIN mnemonics m ON t1.latest_status = m.value AND m.attribute = 'order_summary_status'
    LEFT JOIN users userDealer ON userDealer.user_id = t1.dealer COLLATE Latin1_General_CI_AS
    LEFT JOIN users userManager ON userManager.user_id = t1.manager COLLATE Latin1_General_CI_AS
WHERE NOT EXISTS (SELECT 1
                    FROM #FilterOut t2
                    WHERE t1.order_id = t2.order_id)
ORDER BY t1.name
        , t1.side
        , t1.approved_datetime

IF OBJECT_ID('tempdb..#ActiveOrders') IS NOT NULL DROP TABLE #ActiveOrders
IF OBJECT_ID('tempdb..#ApplicableOrders') IS NOT NULL DROP TABLE #ApplicableOrders
IF OBJECT_ID('tempdb..#FilterOut') IS NOT NULL DROP TABLE #FilterOut

A:

I finally found the issue and thought I would report back. The problem was with NULL values in two of the Aggregation Functions in the script. The reason this only occurred occasionally is because the data was constantly changing.
Although SQL Server handles the issue 'silently' it does produce warnings which ADO sees as recordsets although in my case (might be every case) these recordsets are closed and so impossible to actually see what they contain or what produced them.
Instead of re-writing the SQL script with ISNULL() logic, I have opted simply to include the
SET ANSI_WARNINGS OFF

statement at the top of the script. This prevents the warnings from being reported and thus ADO does not produce these additional, unwanted recordsets.
Disappointed I didn't spot this earlier but at least I've learnt something new. :)


Q:

Sqlalchemy enum migration update fails saying does not exist

I have following sqlalchemy model:
class Cart(db.Model):
    __tablename__ = 'carts'
    #...
    cart_status = db.Column(db.Enum('confirmed', 'canceled', name='cart_statuses'))

Which generates following migration script:
"""empty message

Revision ID: c7cbe7d1d686
Revises: 56e9612a77ee
Create Date: 2017-06-21 08:52:00.987769

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'c7cbe7d1d686'
down_revision = '56e9612a77ee'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('carts', sa.Column('cart_status', sa.Enum('confirmed', 'canceled', name='cart_statuses'), nullable=True))
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('carts', 'cart_status')
    # ### end Alembic commands ###

When I try to upgrade, I get following error:
(ecom_bot) root@logicandthoughts:~/ecom/ecombot# python manage.py db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 56e9612a77ee -> c7cbe7d1d686, empty message
Traceback (most recent call last):
  File "manage.py", line 37, in <module>
    manager.run()
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
    res = handle(*args, **config)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/flask_migrate/__init__.py", line 247, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/command.py", line 254, in upgrade
    script.run_env()
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/script/base.py", line 421, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/util/compat.py", line 75, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "migrations/env.py", line 87, in <module>
    run_migrations_online()
  File "migrations/env.py", line 80, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/runtime/environment.py", line 817, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/runtime/migration.py", line 329, in run_migrations
    step.migration_fn(**kw)
  File "/root/ecom/ecombot/migrations/versions/c7cbe7d1d686_.py", line 21, in upgrade
    op.add_column('carts', sa.Column('cart_status', sa.Enum('confirmed', 'canceled', name='cart_statuses'), nullable=True))
  File "<string>", line 8, in add_column
  File "<string>", line 3, in add_column
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/operations/ops.py", line 1551, in add_column
    return operations.invoke(op)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/operations/base.py", line 318, in invoke
    return fn(self, operation)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/operations/toimpl.py", line 123, in add_column
    schema=schema
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 172, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 118, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1002, in _execute_ddl
    compiled
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "/root/ecom/ecom_bot/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "cart_statuses" does not exist
LINE 1: ALTER TABLE carts ADD COLUMN cart_status cart_statuses
                                                 ^
 [SQL: 'ALTER TABLE carts ADD COLUMN cart_status cart_statuses']

A:

I had to update to following:
"""empty message

Revision ID: 51aa3bff68d6
Revises: c7cbe7d1d686
Create Date: 2017-06-21 09:02:55.252361

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '51aa3bff68d6'
down_revision = 'c7cbe7d1d686'
branch_labels = None
depends_on = None

def upgrade():
    cart_status = postgresql.ENUM('user_unconfirmed', 'user_confirmed', 'client_unconfirmed', 'client_confirmed', name='cart_status')
    cart_status.create(op.get_bind())

    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('carts', sa.Column('cart_status', sa.Enum('user_unconfirmed', 'user_confirmed', 'client_unconfirmed', 'client_confirmed', name='cart_status'), nullable=True))
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('carts', 'cart_status')
    # ### end Alembic commands ###
    cart_status = postgresql.ENUM('user_unconfirmed', 'user_confirmed', 'client_unconfirmed', 'client_confirmed', name='cart_status')
    cart_status.drop(op.get_bind())


Q:

SVG image not displaying using the standard code

I am using the standard code stated in the example of the library of https://code.google.com/p/svg-android/wiki/Tutorial, here is my OnCreate method :
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        ImageView imageView =  (ImageView)findViewById(R.id.imageViewTest);
        // Set the background color to white
        imageView.setBackgroundColor(Color.GRAY);
        // Parse the SVG file from the resource
        SVG svg = SVGParser.getSVGFromResource(getResources(), R.drawable.android);

        //Get a drawable from the parsed SVG and set it as the drawable for the ImageView
        imageView.setImageDrawable(svg.createPictureDrawable());
    }

I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
It does not give any error but it also does not display the image.
I was earlier getting doubts that the image is incorrect, then I used the one in the same example.
Yet it is not displaying the image nor giving any error.
Please suggest how to debug further.

A:

Your problem is almost certainly hardware acceleration.  You may need to set the View LayerType to software mode.
See Having issue on Real Device using vector image in android. SVG-android
If that doesn't fix it, then it may be an issue with svg-android, which can have trouble rendering correctly anything other than simple SVGs.  You might have better luck with my library AndroidSVG.


Q:

SQL Server Plan cache size only 4GB on a server with 500GB RAM

I have a SQL server 2016 SP1 that has been up and running over a year and using the query below, I see that the plan cache size is approx only 4GB where as the physical server has 500GB and there is no max memory setting on the sql instance and there is only one sql instance on the server and no other application.
My understanding is based on how sql server sizes the plan cache using the formula below, the plan cache on my server should be atleast 30GB or more but sql server allocated only 4GB and i have a mix of SP's, sp_executesql and exec(sql) queries on the db. Can experts please help me understand why the plan cache would be so small. Thanks!

SQL Server 2005 SP2 and higher
     75% of visible target memory from 0-4GB
    + 10% of visible target memory from 4GB-64GB
    + 5% of visible target memory > 64GB

SELECT
        [objtype] AS [CacheType],
        COUNT_BIG(*) AS [Total Plans],
        SUM(CAST([size_in_bytes] AS DECIMAL(18,2)))/1024/1024 AS [Total MBs],
        AVG([usecounts]) AS [Avg Use Count],
        SUM(CAST((CASE WHEN [usecounts] = 1 THEN [size_in_bytes] ELSE 0 END)
        AS DECIMAL(18,2)))/1024/1024 AS [Total MBs – USE Count 1],
        SUM(CASE WHEN [usecounts] = 1 THEN 1 ELSE 0 END) AS [Total Plans – USE Count 1]
    FROM [sys].[dm_exec_cached_plans]
    GROUP BY [objtype]
    ORDER BY [Total MBs – USE Count 1] DESC;

A:

SQL Server uses memory only as it needs to... with in-memory technology as the exception, it won't jump to using up all of the memory indicated in the configuration for max server memory (or even min server memory), until you actually request data or plans that require memory.
So if SQL Server has not been up for a long time (maybe you restart every night, or recently installed patches), it won't use that memory until your workload makes it happen. And it may never happen, depending on your available memory and the size of your data. As an example, if you allocate 30GB to SQL Server, but the sum of your data is only 10GB, you're unlikely to see all of your max server memory ever being used, regardless of uptime.
Several of these aspects of SQL Server memory management are widely misunderstood.


Q:

Will iphone 5s convert text emoticons in SMS? Text emoticon for Rose emoji

I don't have iphone myself and that is why I ask this question. Also I don't have a smartphone and don't think that my cellphone is able to send Unicode SMS.
I would like to know whether iphone 5s automatically converts text emoticons to emoji pictures in SMS. If it does, then what text emoticon will be converted to "Rose emoji" (http://emojipedia.org/rose/).
Wikipedia (https://en.wikipedia.org/wiki/List_of_emoticons)
lists several strings for Rose:

@};-
@}->--
@}‑;‑'‑‑‑
@>‑‑>‑‑

Will one of this strings be converted to "Rose emoji" if sent via SMS to Iphone 5s?
Thank you.

A:

None of these are converted for me by my iPhone on iOS 9.3.3.


Q:

NodeJS object.keys error

My nodeJS script needs to make a put/post action to provide an xml file as payload.
However it keeps on failing here saying :
     Object.keys(data).forEach(function(key) {
            ^
TypeError: Object.keys called on non-object
    at Function.keys (native)
    at Object.exports.getBodyString

printing data to stdout gives me the whole xml file in text.
The type of data is string.
    exports.getBodyString = function(data) {  var body = '';

 if(data && !this.isEmpty(data)){
     Object.keys(data).forEach(function(key) {
      var val = data[key];
      if (exports.isArray(val)) {
       for (var i=0; i<val.length; i++) {
        body += key + '[]=' + encodeURIComponent(val[i]) + '&';
       }
      } else {
       body += key + '=' + encodeURIComponent(val) + '&';
      }
     });
     return body;  }  return null; };

What I try to recreate is:
curl -X POST -H "Content-Type: application/xml" -d @config.xml "http://localhost:11000/oozie/v1/jobs?action=start"

to conclude
How do I properly parse a while xml file (indents and new lines and everything) to proper JSON? I'm struggling with xml2js. That seems to return [Object], [Object], ... instead of proper values.

A:

I can still just deliver the xml file and skip the whole function when using
headers: {"content-type": "application/xml"}

instead of
headers: {"content-type": "application/x-www-form-urlencoded"},


Q:

How to start multiple animations at once in Kivy?

Goal:

To start multiple animations all at once.

Expected Result:

All animation defined and started at once must run parallel.

Actual Result:

The only animation that has been started first shows, the below animations doesn't even start.

The Code for Reference:
class KivySplash(Screen):
    def __init__(self, **kwargs):
        super(KivySplash, self).__init__(**kwargs)
        anim1 = MyAnimation(duration=4, opacity=0)
        anim1.bind(on_complete=self.on_anim1_complete)
        self.animation = MyAnimation(duration=3) + MyAnimation(duration=4, opacity=1) + MyAnimation(duration=5) + anim1
        self.img1 = Image(source=os.path.join(original_dir, "Kivy-logo-black-512.png"), opacity=0)
        self.img2 = Image(source=os.path.join(original_dir, "python-powered-w-200x80.png"))
        self.label1 = Label(text="Powered by:", font_size=48)
        box_layout = BoxLayout(orientation="vertical")
        box_layout1 = BoxLayout()
        box_layout.add_widget(self.label1)
        box_layout1.add_widget(self.img1)
        box_layout1.add_widget(self.img2)
        box_layout.add_widget(box_layout1)
        self.add_widget(box_layout)

    def on_anim1_complete(self, *args):
        do_nothing(self, *args)
        if self.img1 in self.animation.animated_widgets:
            pass

    def on_enter(self, *args):
        self.animation.start(self.img1)
        self.animation.start(self.img2)

Thanking You.

A:

I believe you have encountered a bug in the kivy Animation. If you are just using a simple Animation, then starting that Animation on multiple Widgets should work fine. The bug happens when you are using a Sequence (Animations connected with '+'). Sequences work by running the first Animation and binding an internal on_complete method that starts the next Animation in the Sequence. When you call start, that on_complete method is bound. But as soon as the first Animation on the first Widget in the Sequence completes, the second Animation is started and the on_complete method is unbound. Now, when the first Animation on the second Widget completes, the on_complete is not called (is was unbound after the first Widget completed), and the second Animation is not started.
Here is the code from Sequence:
def on_anim1_complete(self, instance, widget):
    self.anim1.unbind(on_complete=self.on_anim1_complete)
    self.anim2.start(widget)

In your case, it looks like the Animation is not starting on the second Widget, but because your first Animation doesn't actually animate anything, you don't see it.
Unfortunately, there are not many alternatives to avoid this problem.

You can build a copy of the entire Animation a second time (copy() or deepcopy() will not work), and just use two different animations (one for each Widget).
You can do your own sequencing by just using simple Animations and use your own on_complete to start the next Animation. Conveniently, the on_complete arguments includes the animated widget that you need for the next start() call.
In some situations, you may be able to animate a single container (like a Layout). Since that is only animating a single Widget, the sequencing should work correctly.


Q:

How do I specify a DateTime mapping in nhibernate when using Firebird?

I'm using nhibernate as my ORM and Firebird embedded as the database. How would I got about saving a DateTime to the database?
This is an example definition of a class.
[Class(Table = "table")]
public class Table
{
    private int mId;
    private DateTime mDate;

    [Id(Name = "Id"),Generator(1, Class = "native")]
    public virtual long Id
    {
      get { return mId; }
      set { mId = value; }
    }

    [Property]
    public virtual DateTime Date
    {
      get { return mDate; }
      set { mDate = value; }
    }
}

I'm guessing that I have to specify something in the Property attribute but I don't know what.
When trying this mapping I get the follwoing error:
FirebirdSql.Data.FirebirdClient.FbException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 63
Date

A:

Just a guess, but could it be related to the property name being a reserved word (Date)?


Q:

Textbook on group theory

Can you recommend me a good textbook on group theory? I am interested in particular in tensor representation of a group, e.g. why $ 3 \otimes 3 = 6 \oplus \bar 3$ for $ \rm SU(3) $. Is there any textbook that can explain clearly that?

A:

As JamalS said, I would also suggest Georgi's book as #1 for your question. Also the one by S. Sternberg, Group Theory and Physics. If you want something more formal, check Fulton and Harris.


Q:

Split string based on certain logic in psql

I have some strings that look like this:
'george hughes and steve jones'

And I am wanting to split this up in to two strings. I am doing this by:
select regexp_split_to_table('george hughes and steve jones and dennis lowe',' and ') into names;

Which returns george hughes and steve jones and dennis lowe.
However, I also have some strings that look like this:
'john and mark jackson'

These two people have the same surname but using the above function would return john and mark jackson as opposed to john jackson and mark jackson
Is there any way I can apply some logic to the regexp function and if the split word (in this case ' and ' only has one word then to use some different functionality?
This would allow the first example to still work, but the second example will split to john jackson and mark jackson as I will use another function that will likely apend the last word in the full string (jackson) to the broken down sections that contain one word only (john).

A:

You could try the following, which fills in any missing surnames:
SELECT regexp_replace(
  'tim price and neil and adam sutcliffe and clive johnson and john and mark jackson',
  '(?<=^| and )(\w+?) and (\w+?) (?!and )(\w+?)(?=$| )',
  '\1 \3 and \2 \3',
  'g'
);

This returns:
                                           regexp_replace
-----------------------------------------------------------------------------------------------------
 tim price and neil sutcliffe and adam sutcliffe and clive johnson and john jackson and mark jackson
(1 row)

This looks for a word followed by ' and ', followed by another word, followed by a word that isn't 'and ' followed by either the end of the text or another space, then adds in the surname from the second name after the first name.  The 'g' is a global flag meaning it'll keep going after the first substitution.
You could then split this by your original method.


Q:

How to construct a Promise wrapper for MongoClient methods in Node.js

I'm trying to wrap various MongoDB methods in a Promise wrapper for a Node.js server but I'm getting a
TypeError: Promise is not a constructor

All the code inside the new Promise constructor wrapper works just fine on its own but I need it inside an asynchronous Promise in order to call it from another place.
const MongoClient = require("mongodb").MongoClient;
const Promise = require("promise");
const mongoURL = "...";

function checkURL (domain, path) {
return new Promise(function (resolve, reject) {
    const client = new MongoClient(mongoURL, { useNewUrlParser: true });

    client.connect()
    .then(db => {
        const collection = client.db("websites").collection("cool_websites");
        return collection.find({domain: domain, path: path}).toArray();
    })
    .then(result => {
        resolve(result);
        client.close();
    })
})
}

console.log(checkURL("www.stackoverflow.com", "/"));

I expect a console.log of
[ { _id: 123abc,
    domain: 'www.stackoverflow.com',
    path: '/questions/',
    cool_website: true } ]

but in the terminal, I just recieve:
TypeError: Promise is not a constructor

A:

You don't need to require("promise"), it doesn't make any sense. It's probably failing because of that.
Also, your test should be:
checkURL("www.stackoverflow.com", "/")
  .then(result => {
    console.log(result);
  });

Because checkURL is a promise now.


Q:

AES encryption on embedded device: Can this be secure?

I plan to create an encryption program for an embedded device with the following characteristics:

CPU is Intel 80186 compatible @ ~20 MHz
128 KB RAM, of which I have ~20 KB at my disposal for purposes of encryption
application binary size limited to 128 KB, but I'd like to keep the encryption part < 16 KB
persistent storage in Flash memory

These are the requirements:

encrypt small text files and bitmaps < 32 KB
I can always decrypt the entire file to RAM, i.e. I don't need random access
the encrypted files are not "locked in" by the hardware, i.e. they can be transferred to a PC at any time, so I want to protect against someone who steals the device and tries to decrypt the data
I am not worried about software exploits, keyloggers and so on (assume I never borrow the device to anyone and keep it under my pillow at night, and also assume the NSA doesn't break into my house to chloroform me and install a targeted exploit)

I'm far from being a crypto expert, but I spent some time reading Wikipedia on AES, block cipher modes and key derivation algorithms, and I also read "If You're Typing The Letters A-E-S Into Your Code, You're Doing It Wrong". All this has made me doubt whether I can succeed given to the limitations of the hardware and my superficial knowledge of the subject, but I'll try.
The following steps line out what I plan to do:

I plan to follow the basic procedure lined out in this response, that is: encryption with AES in CBC mode, key derivation with PBKDF2, random salt, random IV.
Because I'd prefer AES-256 instead of AES-128, I would use PBKDF2 with SHA-512 so I can derive a key of double length.
There is no reliable random number source on the embedded device, so my plan is to have the user generate the random key (k1) on a PC and transfer it (probably by manually typing it in). This should not be a problem because it only happens once, i.e. I use the same key (k1) to encrypt any number of files.
The play/essay "If You're Typing The Letters A-E-S Into Your Code, You're Doing It Wrong" points out the dangers of an attacker who has control over the encryption process, i.e. who can supply arbitrary plaintext and have it encrypted, because this enables all kinds of side-channel attacks such as "error oracle". Am I right to assume this is not an issue for me because the attacker only gets to see my encrypted files?
My understanding is that I should generate a random IV and salt for every individual encryption so as to avoid identical outcome for identical plaintext. But do IV and salt have to be cryptographically strong random numbers? The best I can do would be a Mersenne Twister (or preferably something more efficient) seeded with hash(concat(time, battery voltage)); but is this neccessary at all? I store both IV and salt in plaintext anyway, so I only need to make sure they are different each time, not worry about their predictability.
I plan to use either this implementation or one of the implementations linked here, of course after verifying them with the NIST test vectors. Is there anything else I must check for when choosing an implementation?

I'd be grateful for comments telling me which parts are wrong, unsecure or should be improved. Also, if there is a trusted AES-256 implementation for Intel 80186 I'd love to know about it. And finally, if you think it is hopeless, don't hesitate to tell me.

A:

You don't specify a use case for this, so it's difficult to understand the limitations, and if this is "secure".
You didn't mention using an HMAC, but I'm assuming you're aware of the need for one under certain applications.
You want to use AES-256 over AES-128, but don't specify why.  AES-256 requires 14 rounds, vs only 10 for AES-128, so AES-128 is considerably faster, which may be significant in the very limited environment you're dealing with (16 bit words for instance).  AES-128 is already extremely secure, and there's little if any additional security offered by a larger keyspace, especially if you're using user typed passwords which almost never have a full 128 bits of entropy.
IV doesn't need to be unpredictable (the IV must be known to any attacker anyway).  The only important thing about an IV is that it's not re-used.  Personally I'd use a random seed that's hashed every time a new file is encrypted, and the results saved back the random hash.  The next IV will always be predictable, but given enough initial entropy will never be re-used, even globally across all devices.


Q:

SQL not showing data when executing the script

I have database. Recently added two rows to the database from third party software
1) When I executed below script it not listing updated data which executed recently by third party software. But showing old data.
Select  top 5000 [T_idx]  ,[T_TAG]   ,[T_Date] from [house].[dbo].[total]

2) When I execute below code it script it showing updated data which was executed recently by third party software.
Select * from [house].[dbo].[total]
where T_TAG like '%HO%' order by T_Date DESC

A:

You need to order it correctly (if you want it in date order that is):
SELECT
  TOP 5000 [T_idx], [T_TAG], [T_Date]
FROM
  [house].[dbo].[total]
ORDER BY
  T_Date DESC


Q:

Want to use 1 rails app for multiple sites/domains

I have a client who needs the same custom CMS developed for about 5 apps.  All apps will have a "similar" but different look and feel and I'd really like to have 1 rails application handle this and just modify the layout/views as needed.  Is there a gem/plugin or a precedent for this?

A:

Doug's suggestion will work if the differences between the sites are purely style and static-content -- e.g., if you're basically just "skinning". But I'd be cautious following that approach if the differences will be more involved than that. You could very easily end up with a maintenance nightmare, with all your business logic surrounded by case statements and lots of special case code spread through your application. And you'd really feel the pain if you ever wanted to separate the sites onto different servers or make significant functional changes to some of the sites but not others.
If you anticipate any significant differences between the sites, you might want to consider developing them as separate Rails projects with shared components. Put the code that they'll share into gems or plugins, and reserve the separate projects for the attributes they don't share. For a small increase in overhead up front, you'd buy yourself a lot more flexibility down the road.

A:

You could start with DHH's Account Location plugin as a start, but modify it to use the Top Level Domain name (TLD) instead of a subdomain. Its a very simple library, but it gets the job done. Just be sure to scope all your finds in your app by the Account associated with the domain name.


Q:

Combining scatter and customBars in Dygraphs

I'm trying to build a dygraphs with 2 series one type: scatter another type: errorBars but it seems like it can only display either one:
This is my code:
<!DOCTYPE html>

<link rel="stylesheet" src="dygraph.css" />

If customBars are commented off,it shows the scatter plot.
If not it shows custom bars. Never both.
Here is the picture
here is the JSfiddle
Any help will be greatly appreciated!!
Thank you!

A:

I´m not sure if it is possible to mix custombar graphs with non custom bars ones. But I have found the next solution to your problem. Why don´t you create the graph you want without custombar as a custombar with no custom bar area. Below I leave you my solution.
I hope this could be a solution for you ;)

new Dygraph(
    document.getElementById("container"),
 [
     [new Date("2016/2/3"), [1,3,6], [4,4,4]],
     [new Date("2016/3/3"), [1,3,6], [3,3,3]],
     [new Date("2016/4/3"), [1,3,6], [1,1,1]],
     [new Date("2016/5/3"), [1,3,6], [2,2,2]],
     [new Date("2016/6/3"), [1,3,6], [6,6,6]],
     [new Date("2016/7/3"), [1,3,6], [5,5,5]]
 ],
 {
       labels: [ "Date", "SD" , "Scatter"],
       showRangeSelector: true,
       customBars: true,
       drawPoints: true,

   series: {
    "SD" : {

    },
    "Scatter" : {
     strokeWidth: 1
    }
   },
   includeZero: true

  }
 );
<link href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.css" rel="stylesheet"/>


Q:

ng-repeat not displaying data from function

I am following a basic tutorial on Angular from http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_uppercase
I wanted to change the string array within the controller to the return of a function to make it dynamic but data are not displayed.
I have found some similar questions and answers but no answer helped me. I know there is some tric with the ng-init to use but i can not get it.
Here is my code :

                {{ x }}

Thank you for any help.

A:

ng-repeat requires unique values.  The way to accomplish that in your case is to do this:

That and fix this line in your func:
ruban.push("b");

to be:
result.push("b");

And move someFunction() into your controller, then declare it before calling it.  Like this:
.controller('namesCtrl', function($scope) {

  function someFunction(param) {
    var result = [];
    result.push('a');

    for (i = 1; i <= param; i++) {
      result.push('b');
    }
    return result;
  }

  $scope.names = someFunction(10);
});


Q:

There are integers such that this determinant is nonzero?

I was wondering if given a strictly decreasing sequence of non-negative integers $\mu_{n},\mu_{n-1},\cdots,\mu_{1}$ it is always possible to find $x_{1}=2$ and $x_{2},\cdots,x_{n}$ odd integers such that $$det\begin{pmatrix}
x_{1}^{\mu_{1}} & x_{1}^{\mu_{2}} & \cdots & x_{1}^{\mu_{n}}\\
x_{2}^{\mu_{1}} & x_{2}^{\mu_{2}} & \cdots & x_{2}^{\mu_{n}}\\
\vdots & \vdots & \vdots & \vdots\\
x_{n}^{\mu_{1}} & x_{n}^{\mu_{2}} & \cdots & x_{n}^{\mu_{n}}
\end{pmatrix}\not = 0$$

A:

Of course it is possible. First look at the value of $\det\begin{pmatrix}
x_{1}^{\mu_{1}} & x_{1}^{\mu_{2}} \\
x_{2}^{\mu_{1}} & x_{2}^{\mu_{2}}
\end{pmatrix}$ as a function of $\bf x_2$. It is a polynomial, and hence may only have so many roots, so there must be quite a few integers which are not roots, and we pick any of them for our $x_2$. Then go on to $x_3$ and the corresponding $3\times3$ determinant, and repeat the same line of thought: as a function of $x_3$ it is a polynomial, hence...
You might wonder why did we need the $2\times2$ determinant. Well, that was to  make sure that at least one coefficient of the next polynomial is non-zero.


Q:

Error migrations: Cannot declare class X, because the name is already in use

I do not know why this error jumps when I execute the migrations but I do not have repeated classes.
migrations:

error:

class:

A:

First Solution :
It seems like you have 2 migrations done at different time with essentially same name.
for example : 2019_01_18_020910_create_roles_table.php
and 2019_01_16_020910_create_roles_table.php
Laravel will convert this filename eliminating the date signature and Camel Casing the remaining text.
So both of these migration will have class CreateRolesTable even if the time signatures are different. Check if your migrations directory have such 2 files.
To check this run this from terminal in project root : grep -ri 'createrolestable' database/migrations
Second Solution :
Sometimes composer's internal class autoloading causes this issue. Do following to check if it resolves :
run composer install
Third Solution :
This is likely to be invalid but a same file should not have same class declaration 2 files by mistake.
Fourth Solution :
There might be a package you have installed which has a migration with same class name. To find run grep -ril 'createrolestable' vendor
If it shows any file then thats what causing 2 classes to have same names.
You can create a new one php artisan make:migration create_roles_table_custom . and then copy what you have in current migration to the new one and delete the existing one(not from package but the one you have created).
This will create a class CreateRolesTableCustom which is different than what the package already has.


Q:

Binding data to collapsible set in phonegap

i have a collapsible set to which i am trying to the append query result as the listview. but i am unable to bind the result as listview.
This is what i am trying to do
function queryDB(tx) {
    tx.executeSql('SELECT * FROM FOLDER', [], querySuccess, errorCB);
}

function listdata(tx,results){
    list= ("
");
    count = results.rows.length;
    $.each(results.rows,function(index){
        var row = results.rows.item(index);
        var li = '
'+row['Date']+'
';
        list = $(list).append(li);
    });
}

function querySuccess(tx, results) {
    $.each(results.rows,function(index){
        var row = results.rows.item(index);

        tx.executeSql('SELECT Date FROM ALLIGNMENT WHERE name="'+row[name]+'"', [], listdata, errorCB);

        var div = '

'+
            row["name"]+'10

';

        $(list).appendTo(div).parent().appendTo('[data-role="content"]').end().trigger("create");
        $('div[data-role="collapsible"]').collapsible({theme:'c',refresh:true});
        $('[data-role="listview"]').listview().listview('refresh');
    });
}

If i try to display just a collapsible set, i am able to display. but when i try to display the listview nothing is getting displayed. what is the mistake i am doing?
Thanks:)
New function structure
function queryDB(tx) {
tx.executeSql('SELECT * FROM FOLDER', [], querySuccess, errorCB);
}

 function listdata(tx,resultset){

   list = $("
").attr({'data-role':'listview','data-inset':'false','id':'mylist'});
   count = resultset.rows.length;

    $(list).remove();

   $.each(resultset.rows,function(index){
    var row = resultset.rows.item(index);
   // alert(row['CreatedDate']);
     var li = '
'+row['Date']+'
';
    list.append(li);

    });

div = '

'+
 row1["name"]+''+count+'

';
 }
list.appendTo(div).parent().appendTo('[data-role="content"]').end().trigger("create");
$('div[data-role="collapsible"]').collapsible({theme:'b',refresh:true});
$('[data-role="listview"]').listview().listview('refresh');

 }

function querySuccess(tx, results) {

$.each(results.rows,function(index){

   row1 = results.rows.item(index);

tx.executeSql('SELECT CreatedDate FROM ALLIGNMENT WHERE name="'+row1["name"]+'" ', [], listdata, errorCB);

});

}

A:

You have an error in your function listdata.
jQuery object can't be created like this:
list= ("
");

For start you are missing $ sign before ( but even with that it will not work.
Do it like this:
var list = $("
").attr({'data-role':'listview','data-inset':'false','id':'mylist'});

Also in this case you don't need to use this line like this:
list = $(list).append(li);

it will not work, it should look like this:
list.append(li);

EDIT :
You will need to make addition changes. When you execute this line:
tx.executeSql('SELECT Date FROM ALLIGNMENT WHERE name="'+row[name]+'"', [], listdata, errorCB);

call to function listdata is asynchronous. Which means that rest of the code will not wait for this function to run. Basically you will need to move some of this lines:
    var div = '

'+
    row["name"]+'10

';

    $(list).appendTo(div).parent().appendTo('[data-role="content"]').end().trigger("create");
    $('div[data-role="collapsible"]').collapsible({theme:'c',refresh:true});
    $('[data-role="listview"]').listview().listview('refresh');

into the function listdata. Currently list is empty because function is still running when you try to append list object.


Q:

Why doesn't an RC circuit change the shape of an input sine?

In above picture, red square wave is the input and blue wave is the output of an RC circuit. I'm not able to understand why I get a perfect sine wave when I feed a sine wave as input. The capacitor has to take some time to charge and discharge. So my intuition cries the output to be some periodic wave whose period is half the input. Could somebody clear this up for me ? Thanks!

In time domain shouldn't it do something like this ?
At t=0, the capacitor has 0 voltage. Since the input voltage is large, the capacitor keeps charging and meets the input sine wave when its falling.
Then the input voltage goes lower than the capacitor voltage, so the capacitor starts discharging and again meets the input sine wave when it is rising.

A:

Learn to think in frequency space.  This is one of those things that is difficult to see in the time domain, but falls out nicely in the frequency domain.
A sine wave is a single "pure" frequency.  A RC filter is a linear system that can't distort, meaning it can't create frequencies in the output that aren't in the input.  When you only put in one frequency, the output can only contain that one frequency.  The only questions are what the relative amplitude and phase shift will be from input to output.
The reason that a square wave in does not result in a square wave out is because a square wave contains lots of frequencies.  Each of those can be attenuated and phase shifted independently.  When you change the relative strength and phases of harmonics, you get a different looking signal in the time domain.
A square wave can be thought of as the superposition of a infinite series of sines.  These are at all the odd harmonics (odd integer multiples of the fundamental frequency).  The amplitude of these harmonics falls off at higher frequencies.
You can pass a square wave thru several RC low pass filters in succession, each with a rolloff frequency well below that of the square wave frequency.  After each filter, the result looks more and more like a sine.  That is because such filters attenuate high frequencies more than low ones.  This means the harmonics of the square wave are attenuated more than the fundamental.  If you do this enough, the harmonics have so little amplitude relative to the fundamental, that all you see is the fundamental.  That's a single frequency, so a sine.
Added

This is not how any RC filter would react:
For a RC low pass filter, when the input frequency is well below the rolloff, the output mostly just follows the input.  At well above the rolloff frequency, the output is the integral of the input.
Either way, there won't be sudden changes in output slope as you show.  There is nothing special about the input crossing above or below the output since this happens smoothly.  You get a inflection point in the output, but its a smooth hump since the input approaches smoothly before and leaves smoothly after.
It might be instructive to write a loop to simulate this yourself.  All you have to do each step is change the output by a small fraction of the instantaneous difference of the input minus the output.  That's it.  Then throw a sine wave at it and see how the output smoothly follows to make another sine, although lagging in phase and lower in amplitude.

A:

Remember that the rate of change of the capacitor voltage depends on the voltage difference between the input voltage and the capacitor voltage. Your graph doesn't represent this.
When the input and the capacitor are at 0 V and the input starts rising, the capacitor voltage should start rising slowly, since the input voltage (and hence the voltage difference) is also small.
When the input peaks, the difference in voltage is at maximum, and here the capacitor voltage rises fastest. When the input voltage starts going down, the rate of the capacitor's charging also goes down. After the two voltages have met, the difference is again small to begin with, so the discharge rate is also small. As it turns out, this happens to result in another sine wave.
The graph below was simulated (with a spreadsheet) with the rule mentioned above. The voltage difference between the input and the capacitor voltage is greatest a bit before the peak of the input voltage.
Note that the graph also shows that the capacitor voltage doesn't go back to zero at \$ 2\pi \$, but stays below it. This is consistent with the capacitor voltage being phase-shifted relative to the input, it's just that it takes some time to reach a steady state after both voltages started from zero.

In your graph, the capacitor discharges fastest right after the two voltages meet, but that's not where the voltage difference is at its greatest.
With a square-wave input, it would be, since the input voltage wouldn't change again until another "step" in the square-wave. A sine-wave input however changes constantly.

A:

You will get a sine wave out from a sine wave in if your RC time constant allows the capacitor to charge/discharge at the same rate or faster as the input waveform changes.
Your output waveform will be delayed by the capacitor charging and discharging slightly behind the changes to the input waveform, referred to as phase lag.
You will find plenty of the theory and maths behind it on the internet, if you don't have it already.


Q:

What's the difference between \ref and \autoref?

I've always used \ref for referring to labelled items, but a LaTeX template I downloaded uses \autoref instead. What is the difference?

A:

\autoref is a command from the hyperref package which is used to have some automatic prefix added to the reference. For instance if you used \label{sec:intro} just after your command for the introduction section the \autoref{sec:intro} command will output "section X" with X being the good number.
Of course you can imagine that the prefix depends on the type of the object to which the label is linked. If it is a figure, it will output "figure" and so on.
Note that you can redefine the prefix for the autoref command associated to a given type of object. For instance for the sections use:
\def\sectionautorefname{New prefix for the sections}

More generally,
\def\<type>autorefname{<new name>}

A:

The difference is easy to see in the following example:
\documentclass{article}
\usepackage{hyperref}
\begin{document}

\begin{table}\centering
\caption{foo}\label{foo}
\tabular{c}
foo\\\hline
bar\\\hline
\endtabular
\end{table}
\begin{table}\centering
\caption{bar}\label{bar}
\tabular{c}
foo\\\hline
bar\\\hline
\endtabular
\end{table}

See Table~\ref{foo} and
          \autoref{bar}
\end{document}


Q:

C# Sorting list by another list

I have now 2 lists:
list<string> names;
list<int> numbers;

and I need to sort my names based on the values in numbers.
I've been searching, and most use something like x.ID, but i don't really know what that value is. So that didn't work.
Does anyone know, what to do, or can help me out in the ID part?

A:

So i assume that the elements in both lists are related through the index.
names.Select((n, index) => new { Name = n, Index = index })
     .OrderBy(x => numbers.ElementAtOrDefault(x.Index))
     .Select(x => x.Name)
     .ToList();

But i would  use another collection type like Dictionary<int,string> instead if both lists are related insomuch.

A:

Maybe this is a task for the Zip method. Something like
names.Zip(numbers, (name, number) => new { name, number, })

will "zip" the two sequences into one. From there you can either order the sequence immediately, like
.OrderBy(a => a.number)

or you can instead create a Dictionary<,>, like
.ToDictionary(a => a.number, a => a.name)

But it sounds like what you really want is a SortedDictionary<,>, not a Dictionary<,> which is organized by hash codes. There's no LINQ method for creating a sorted dictionary, but just say
var sorted = new SortedDictionary<int, string>();
foreach (var a in zipResultSequence)
    sorted.Add(a.number, a.name);

Or alternatively, with a SortedDictionary<,>, skip Linq entirely, an go like:
var sorted = new SortedDictionary<int, string>();
for (int idx = 0; idx < numbers.Count; ++idx)  // supposing the two list have same Count
    sorted.Add(numbers[idx], names[idx]);


Q:

Intersystems Cache - Maintaining Object Code to ensure Data is Compliant with Object Definition

I am new to using intersytems cache and face an issue where I am querying data stored in cache, exposed by classes which do not seem to accurately represent the data in the underlying system. The data stored in the globals is almost always larger than what is defined in the object code.
As such I get errors like the one below very frequently.
Msg 7347, Level 16, State 1, Line 2
OLE DB provider 'MSDASQL' for linked server 'cache' returned data that does not match expected data length for column '[cache]..[namespace].[tablename].columname'. The (maximum) expected data length is 5, while the returned data length is 6.

Does anyone have any experience with implementing some type of quality process to ensure that the object definitions (sql mappings) are maintained in such away that they can accomodate the data which is being persisted in the globals?
Property columname As %String(MAXLEN = 5, TRUNCATE = 1) [ Required, SqlColumnNumber = 2, SqlFieldName = columname ];

In this particular example the system has the column defined with a max len of 5, however the data stored in the system is 6 characters long.
How can I proactively monitor and repair such situations.
/*
I did not create these object definitions in cache
*/

A:

It's not completely clear what "monitor and repair" would mean for you, but:
How much control do you have over the database side?  Cache runs code for a data-type on converting from a global to ODBC using the LogicalToODBC method of the data-type class.  If you change the property types from %String to your own class, AppropriatelyNamedString, then you can override that method to automatically truncate.  If that's what you want to do.  It is possible to change all the %String property types programatically using the %Library.CompiledClass class.
It is also possible to run code within Cache to find records with properties that are above the (somewhat theoretical) maximum length.  This obviously would require full table scans.  It is even possible to expose that code as a stored procedure.
Again, I don't know what exactly you are trying to do, but those are some options.  They probably do require getting deeper into the Cache side than you would prefer.
As far as preventing the bad data in the first place, there is no general answer.  Cache allows programmers to directly write to the globals, bypassing any object or table definitions.  If that is happening, the code doing so must be fixed directly.
Edit: Here is code that might work in detecting bad data.  It might not work if you are doing cetain funny stuff, but it worked for me.  It's kind of ugly because I didn't want to break it up into methods or tags.  This is meant to run from a command prompt, so it would have to be modified for your purposes probably.
{
    S ClassQuery=##CLASS(%ResultSet).%New("%Dictionary.ClassDefinition:SubclassOf")
    I 'ClassQuery.Execute("%Library.Persistent")  b  q
    While ClassQuery.Next(.sc) {
    If $$$ISERR(sc) b  Quit
        S ClassName=ClassQuery.Data("Name")
        I $E(ClassName)="%"   continue
        S OneClassQuery=##CLASS(%ResultSet).%New(ClassName_":Extent")
        I '$IsObject(OneClassQuery) continue  //may not exist
        try {
        I 'OneClassQuery.Execute()  D OneClassQuery.Close() continue
        }
        catch
        {

            D OneClassQuery.Close()
            continue
        }
        S PropertyQuery=##CLASS(%ResultSet).%New("%Dictionary.PropertyDefinition:Summary")
        K Properties
        s sc=PropertyQuery.Execute(ClassName)  I 'sc D PropertyQuery.Close()  continue
        While PropertyQuery.Next()
        {
            s PropertyName=$G(PropertyQuery.Data("Name"))
            S PropertyDefinition=""
            S PropertyDefinition=##CLASS(%Dictionary.PropertyDefinition).%OpenId(ClassName_"||"_PropertyName)
            I '$IsObject(PropertyDefinition)  continue
            I PropertyDefinition.Private  continue
            I PropertyDefinition.SqlFieldName=""
            {
                S Properties(PropertyName)=PropertyName
            }
            else
            {
                I PropertyName'="" S Properties(PropertyDefinition.SqlFieldName)=PropertyName
            }
        }
        D PropertyQuery.Close()

        I '$D(Properties) continue

        While OneClassQuery.Next(.sc2)  {
            B:'sc2
            S ID=OneClassQuery.Data("ID")
            Set OneRowQuery=##class(%ResultSet).%New("%DynamicQuery:SQL")
            S sc=OneRowQuery.Prepare("Select * FROM "_ClassName_" WHERE ID=?") continue:'sc
            S sc=OneRowQuery.Execute(ID) continue:'sc
            I 'OneRowQuery.Next() D OneRowQuery.Close() continue
            S PropertyName=""
            F  S PropertyName=$O(Properties(PropertyName))  Q:PropertyName=""  d
            . S PropertyValue=$G(OneRowQuery.Data(PropertyName))
            . I PropertyValue'="" D
            .. S PropertyIsValid=$ZOBJClassMETHOD(ClassName,Properties(PropertyName)_"IsValid",PropertyValue)
            .. I 'PropertyIsValid W !,ClassName,":",ID,":",PropertyName," has invalid value of "_PropertyValue
            .. //I PropertyIsValid W !,ClassName,":",ID,":",PropertyName," has VALID value of "_PropertyValue
            D OneRowQuery.Close()
        }
        D OneClassQuery.Close()
    }
    D ClassQuery.Close()
}


Q:

Is it possible to map a discontiuous data on disk to an array with python?

I want to map a big fortran record (12G) on hard disk to a numpy array. (Mapping instead of loading for saving memory.)
The data stored in fortran record is not continuous as it is divided by record markers. The record structure is as "marker, data, marker, data,..., data, marker". The length of data regions and markers are known.
The length of data between markers is not multiple of 4 bytes, otherwise I can map each data region to an array.
The first marker can be skipped by setting offset in memmap, is it possible to skip other markers and map the data to an array?
Apology for possible ambiguous expression and thanks for any solution or suggestion.

Edited May 15
These are fortran unformatted files. The data stored in record is a (1024^3)*3 float32 array (12Gb).
The record layout of variable-length records that are greater than 2 gigabytes is shown below:

(For details see here -> the section [Record Types] -> [Variable-Length Records].)
In my case, except the last one, each subrecord has a length  of 2147483639 bytes and separated by 8 bytes (as you see in the figure above, a end marker of the previous subrecord and a begin marker of the following one, 8 bytes in total ) .
We can see the first subrecord ends with the first 3 bytes of certain float number and the second subrecord begins with the rest 1 byte as 2147483639 mod 4 =3.

A:

I posted another answer because for the example given here numpy.memmap worked:
offset = 0
data1 = np.memmap('tmp', dtype='i', mode='r+', order='F',
                  offset=0, shape=(size1))
offset += size1*byte_size
data2 = np.memmap('tmp', dtype='i', mode='r+', order='F',
                  offset=offset, shape=(size2))
offset += size1*byte_size
data3 = np.memmap('tmp', dtype='i', mode='r+', order='F',
                  offset=offset, shape=(size3))

for int32 byte_size=32/8, for int16 byte_size=16/8 and so forth...
If the sizes are constant, you can load the data in a 2D array like:
shape = (total_length/size,size)
data = np.memmap('tmp', dtype='i', mode='r+', order='F', shape=shape)

You can change the memmap object as long as you want. It is even possible to make arrays sharing the same elements. In that case the changes made in one are automatically updated in the other.
Other references:

Working with big data in python and numpy, not enough ram, how to save partial results on disc?
numpy.memmap documentation here.


Q:

TeamCity build labeling failing intermittently on a git repository

My build is running on Windows Server 2003, TeamCity 6.0.3. The git repository is stored on the same server and is accessed via cygwin's sshd and gitd. My vcs configuration in TeamCity is as follows:

Fetch URL: git://server/Repo
Push URL: ssh://server/~/Repo
Authentication settings
Authentication Method: Password
User name: TeamCitySC (this is a local account set up specifically for labeling)
Password: * * * * * *

for each user there is a symlink in their home path to the Repository hence the ~/Repo path. Labeling worked just fine for about a 100 builds, recently it has periodically started to complain with the following message:

Labeling failed for root 'git root'
  org.eclipse.jgit.api.errors.JGitInternalException:
  Updating the ref refs/tags/build-108
  to
  Tag[03e70a74b39c1393f5ce684424194210513b4d48]={
  object
  0f6101df222f5370a17f5ce1c97eb2348d64970c
  type commit tag build-108  tagger
  PersonIdent[SYSTEM,
  SYSTEM@server, Thu May 26
  16:16:07 2011 -0600] } failed.
  ReturnCode from RefUpdate.update() was
  REJECTED at
  org.eclipse.jgit.api.TagCommand.call(TagCommand.java:159)
  at
  jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport.label(GitVcsSupport.java:1334)
  at
  jetbrains.buildServer.vcs.impl.VcsLabeler.setLabel(VcsLabeler.java:80)
  at
  jetbrains.buildServer.vcs.impl.VcsLabeler.setLabel(VcsLabeler.java:1)
  at
  jetbrains.buildServer.serverSide.impl.FinishedBuildImpl.setLabel(FinishedBuildImpl.java:10)
  at
  jetbrains.buildServer.serverSide.impl.auth.SecuredBuildFactory$SecuredFinishedBuildImpl.setLabel(SecuredBuildFactory.java:3)
  at
  jetbrains.buildServer.controllers.SetLabelAction.doProcess(SetLabelAction.java:11)
  at
  etc...

It continues to fail even when I manually try to label the build via TeamCity (i.e. 'Label this build sources' link in the Changes tab for a given build).

A:

From the ReturnCode REJECTED in the error message it seems like your repository already has tag refs/tags/build-108 and TeamCity does not force rewrite existing tag.


Q:

Loading images in ImageView from a url

I found this snippet on the internet:
try{
        URL url = new URL(imgUrl+imageId[position]+".png");
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        InputStream is = con.getInputStream();
        Bitmap bmp = BitmapFactory.decodeStream(is);
        imageView.setImageBitmap(bmp);
    }catch(Exception e) {
        System.out.println(e.getMessage());
    }

The code doesn't give me any errors,I am getting the exact url I want. But the ImageView stays empty. Running the debugger I got no problem upto: InputStream is = con.getInputStream();
After this the debugger goes to the catch block, and debugger window shows
NetworkOnMainThreadException

I know it's because I am doing network operations on the UI thread , but my activity already is extending another class, so I can't extend AsycnTask. Any workaround for this?
Plus: If there is an exception, shouldn't the app crash? My app runs fine, but the imageview doesn't show anything.

A:

You can use Picasso that will help you also in async thread:
Picasso.with(context).load(imgUrl+imageId[position]+".png").into(imageView);

You can download the source here: http://square.github.io/picasso/
or add it as dependency directly from Android Studio


Q:

Running a java "background application" in application server

My experience with application servers is limited to some basic servlet coding, so I am not even sure how to frame this question appropriately.
I need to write a java program that runs on the (java) application server and continuously executes a certain method (it will check for files in a certain directory).
I have found a way to schedule the start of applications but need to know where to put the code that I would normally put in the main() method in a regular java program.

A:

You can use Quartz, or the EJB timer service (if you can learn EJBs) for this task.
If you have just a servlet container like Tomcat, it is preferable to go with Quartz. In fact, Quartz also comes with a web application to monitor a scheduler.
On the other hand, the EJB timer service is available in all EJB containers that support EJB 2.1 and above.


Q:

CodeIgniter Path Issue

I am use Codeigniter to creat my site. it is a huge site with a lot of contents.
i use the default welcome controller for all pages.
the path is like this now
http://mydomain.com/index.php/welcome
and my folder structure is like this
/root
  /codeigniter Application folder
      /controller
      /view
  /static/
      /images/
      /css/
      /pdf/
  .htaccess

because i am doing the content first, so all the images are set to absolute patch (http://mydomain.com/static/images/foldername/pc.jpg)
now when i use the rewrite to remove "inde.php" and "welcome"
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]

all css and image file are not accessible anymore.  I have nearly a thousand pages with images. I don't have the time to change the page one by one. the deadline is coming, please help.
thanks

A:

Have you tried adding the css-folder to your excluded rewriteconditions?
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)

Does not seem to exclude the folder css from rewriting (see images is excluded).
Try something like
RewriteCond $1 !^(index\.php|images|css|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)

Good luck


Q:

Pygame: Initial menu leading up to game loop

I'm making a version of this game, and I'm trying to make the starting menu like so:

My plan is to start by doing surface.fill(overlaycolor) then blitting this image onto the screen. That will be in one while loop. Afterwards, after the users wants to play (save that for another question) then we will enter into another while loop.
I tried doing that, but it just gives me a black screen.
Here is my code:
import pygame, sys, random
from pygame.locals import *

# set up pygame
pygame.init()
mainClock = pygame.time.Clock()

# set up the window
width = 800
height = 600
thesurface = pygame.display.set_mode((width, height), 0, 32)
pygame.display.set_caption('')

bg = pygame.image.load("bg.png")
menu1 = pygame.image.load("menu1.png")

basicFont = pygame.font.SysFont('calibri', 36)

# set up the colors
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
overlay = (121, 126, 128)
playercolor = BLUE
# set up the player and food data structure
foodCounter = 0
NEWFOOD = 20
FOODSIZE = 10
splitting = False
player = pygame.draw.circle(thesurface, playercolor, (60, 250), 40)

foods = []
for i in range(20):
    foods.append(pygame.Rect(random.randint(0, width - FOODSIZE), random.randint(0, height - FOODSIZE), FOODSIZE, FOODSIZE))

# set up movement variables
moveLeft = False
moveRight = False
moveUp = False
moveDown = False

MOVESPEED = 10
size = 10
score = size
gameisplaying = False
while True:
    thesurface.fill(overlay)
    thesurface.blit(menu1, (400,400))
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONUP:
            pos = pygame.mouse.get_pos()

            gameisplaying = True
    break
# run the game loop
while gameisplaying:
    thesurface.blit(bg, (0, 0))
    # check for events
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            # change the keyboard variables
            if event.key == K_LEFT or event.key == ord('a'):
                moveRight = False
                moveLeft = True
            if event.key == K_RIGHT or event.key == ord('d'):
                moveLeft = False
                moveRight = True
            if event.key == K_UP or event.key == ord('w'):
                moveDown = False
                moveUp = True
            if event.key == K_DOWN or event.key == ord('s'):
                moveUp = False
                moveDown = True
            if event.key == K_SPACE and size >= 32: # XXX if size and space set splitting to true
                splitting = True
        if event.type == KEYUP:
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key == K_LEFT or event.key == ord('a'):
                moveLeft = False
            if event.key == K_RIGHT or event.key == ord('d'):
                moveRight = False
            if event.key == K_UP or event.key == ord('w'):
                moveUp = False
            if event.key == K_DOWN or event.key == ord('s'):
                moveDown = False
            if event.key == ord('x'):
                player.top = random.randint(0, height - player.height)
                player.left = random.randint(0, width - player.width)
        if event.type == MOUSEBUTTONUP:
            foods.append(pygame.Rect(event.pos[0], event.pos[1], FOODSIZE, FOODSIZE))

    foodCounter += 1
    if foodCounter >= NEWFOOD:
        # add new food
        foodCounter = 0
        foods.append(pygame.Rect(random.randint(0, width - FOODSIZE), random.randint(0, height - FOODSIZE), FOODSIZE, FOODSIZE))
    if 100>score>50:
        MOVESPEED = 9
    elif 150>score>100:
        MOVESPEED = 8
    elif 250>score>150:
        MOVESPEED = 6
    elif 400>score>250:
        MOVESPEED = 5
    elif 600>score>400:
        MOVESPEED = 3
    elif 800>score>600:
        MOVESPEED = 2
    elif score>800:
        MOVESPEED = 1
    # move the player
    if moveDown and player.bottom < height:
        player.top += MOVESPEED
    if moveUp and player.top > 0:
        player.top -= MOVESPEED
    if moveLeft and player.left > 0:
        player.left -= MOVESPEED
    if moveRight and player.right < width:
        player.right += MOVESPEED

    # splitting
    if not splitting:
        pygame.draw.circle(thesurface, playercolor, player.center, size)
    else:
        pygame.draw.circle(thesurface, playercolor,(player.centerx,player.centery),int(size/2))
        pygame.draw.circle(thesurface, playercolor,(player.centerx+size,player.centery+size),int(size/2))
    # check if the player has intersected with any food squares.
    for food in foods[:]:
        if player.colliderect(food):
            foods.remove(food)
            size+=1

    # draw the food
    for i in range(len(foods)):
        pygame.draw.rect(thesurface, GREEN, foods[i])

    printscore = basicFont.render("Score: %d" % size, True, (0,0,0))
    thesurface.blit(printscore, (10, 550))

    pygame.display.update()
    # draw the window onto the thesurface
    pygame.display.update()
    mainClock.tick(80)

Help is appreciated!

A:

Let's look at this code:
...
gameisplaying = False
while True:
    thesurface.fill(overlay)
    thesurface.blit(menu1, (400,400))
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONUP:
            pos = pygame.mouse.get_pos()

            gameisplaying = True
    break
# run the game loop
while gameisplaying:
   ...

First, you immediatly break the first while loop at the end of the first iteration. So you leave the loop without setting gameisplaying to True, which in turn means the second while loop never runs.
Second, you draw something on the screen in the first loop, but you never call pygame.display.flip() to make that changes actually visible.

Here's a little example I hacked together while I was bored. Note how the action goes on in the background while the game is in the MENU state, and you can switch to the RUNNING state by clicking with the mouse:
import pygame
import math
import random
from collections import namedtuple
from itertools import cycle

def magnitude(v):
    return math.sqrt(sum(v[i]*v[i] for i in range(len(v))))

def add(u, v):
    return [(a+b) for (a, b) in zip(u, v)]

def sub(u, v):
    return [(a-b) for (a, b) in zip(u, v)]

def dot(u, v):
    return sum((a*b) for a, b in zip(u, v))

def normalize(v):
    vmag = magnitude(v)
    return [ v[i]/vmag  for i in range(len(v)) ]

def length(v):
  return math.sqrt(dot(v, v))

def angle(v1, v2):
  return math.acos(dot(v1, v2) / (length(v1) * length(v2)))

class Cell(object):

    id = 0

    def __init__(self, pos, color, speed, size, controller):
        self.x, self.y = pos
        self.speed = speed
        self.color = color
        self.size = size
        self.target_vector = [0, 0]
        self.controller = controller
        Cell.id += 1
        self.id = Cell.id

    @property
    def pos(self):
        return self.x, self.y

    @property
    def int_pos(self):
        return [int(v) for v in self.pos]

    @property
    def int_size(self):
        return int(self.size)

    def update(self, surroundings):

        if self.size > 6:
            self.size *= 0.999

        eatting = [c for c in surroundings if can_a_eat_b(self, c)]
        for c in eatting:
            self.size += int(c.size / 2.5)

        if self.speed == 0: return eatting
        self.target_vector = self.controller(self, surroundings)
        if length(self.target_vector ) < 1: return eatting
        move_vector = [c * self.speed for c in normalize(self.target_vector)]
        self.x, self.y = add(self.pos, move_vector)
        return eatting

    def draw(self, s):
        pygame.draw.circle(s, self.color, self.int_pos, self.int_size)
        if not str(self.id).startswith('Food'):
            s.blit(write(str(self.id)), add(self.int_pos, (5, 5)))

def can_a_eat_b(a, b):
    return a.id != b.id and a.size > b.size and length(sub(a.pos, b.pos)) <= a.size + b.size

def player_controller(cell, surroundings):
    return sub(pygame.mouse.get_pos(), cell.pos)

colors = [c for c in pygame.color.THECOLORS.values()]
def rand_color():
    return random.choice(colors)

def rand_pos(rect):
    return random.randint(0, rect.width), random.randint(0, rect.height)

def food_controller(cell, surroundings):
    return (0, 0)

def food_factory(rect):
    cell = Cell(rand_pos(rect), rand_color(), 0, 5, food_controller)
    cell.id = 'Food' + str(cell.id)
    return cell

def ai_controller(cell, surroundings):
    targets = [(c, length(sub(cell.pos, c.pos))) for c in surroundings if c.size < cell.size and cell.id != c.id]
    targets_sorted = sorted(targets, key=lambda i: i[1])

    if targets_sorted:
        return sub(targets_sorted[0][0].pos, cell.pos)

    return (0, 0)

def ai_factory(rect):
    return Cell(rand_pos(rect), rand_color(), 0.7, 6, ai_controller)

Info = namedtuple('Info', ['size', 'pos', 'id'])

MENU, RUNNING = 0, 1

font = None
def write(text):
    return font.render(text, True, (0, 0, 0))

def main():
    state = MENU
    pygame.init()
    global font
    font = pygame.font.SysFont('Consolas', 17)
    s = pygame.display.set_mode((800, 600))
    s_rect = s.get_rect()
    c = pygame.time.Clock()
    CREATEFOOD = pygame.USEREVENT + 1
    CREATEAI = pygame.USEREVENT + 2
    pygame.time.set_timer(CREATEFOOD, 1000)
    pygame.time.set_timer(CREATEAI, 3000)

    marquee = cycle(range(800))

    player = None
    for _ in range(10): pygame.event.post(pygame.event.Event(CREATEFOOD))
    for _ in range(4): pygame.event.post(pygame.event.Event(CREATEAI))

    actors = []

    while True:

        for e in pygame.event.get():
            if e.type == pygame.QUIT: return
            if e.type == CREATEFOOD: actors.append(food_factory(s_rect))
            if e.type == CREATEAI: actors.append(ai_factory(s_rect))
            if state == MENU:
                if e.type == pygame.MOUSEBUTTONUP:
                    player = Cell((200, 200), rand_color(), 0.7, 6, player_controller)
                    actors.append(player)
                    player.id = 'Player'
                    state = RUNNING

        surroundings = [Info(c.size, c.int_pos, c.id) for c in actors]
        killed = []
        for ar in actors:
            for eaten in ar.update(surroundings):
                killed.append(eaten)

        actors = [a for a in actors if not a.id in [k.id for k in killed]]

        s.fill((255, 255, 255))

        for ar in actors:
            ar.draw(s)

        if state == MENU:
            s.blit(write('Click anywhere to start'), (next(marquee), 300))

        pygame.display.flip()
        c.tick(60)

if __name__ == '__main__':
    main()

I hope you can take some inspiration.


Q:

Password Security

I've been using generated passwords for a while now.  I generate a salt, then some input information, and generate something in return. On a large banking website, I used such a password schema and recently noticed I was unable to login.  Apparently they truncated the length of passwords from 32 characters to 31 and now 30 characters.
My question is, if they truncated the passwords, the only way it would be possible for them to truncate your password properly is if they did not run it through a one-way hash algorithm to securely store the password.  Meaning, they're either storing the password in plain text, or using a weak schema to encode the password.
I'm considering dropping my account with them for obvious security reasons and general negligence to obvious security practices.
Am I incorrect in my assumptions, I am not a math nor a computer science major.
Walter

A:

Were you able to login simply by taking a character off your password or did you have to change it?
If the answer is yes, I think it is most likely that they are storing as plain text or a weak encryption.
If the answer is no, they simply changed the policy - yours no longer matches and it didn't work any more...
However, especially if you have different passwords for different sites, I wouldn't bother changing just because of this - if they ever got hacked or similar, They wouldn't hold it against you.... However, it sounds like you are very cautious with security, so changing may be the only way to make you feel safe!

A:

They might not have truncated your password in the database, it might be a pre submit check on the length of the string before it gets checked.
However, if you were able to get in by typing the first 31 (or 30) characters then it would have to have been stored in clear text.


Q:

Loop through strings stored as hash values Perl

I have created a hash which has following key:value structure.
%multifasta = ('sequence1', ACCGTG, 'sequence2' , AGTCGTAGC, 'sequence3' , AGTCGCTAGCATAGCA)

where, the ACGT strings are stored as hash values and sequence number is stored as hash keys.
I want to loop through the strings stored as hash values to count the number of A,C,G, and T nucleotide.
What I tried is :
while(my($key, $value) = each %multifasta){
    print "$key\n";
    my $len = length($value);
    my $nucl;
    foreach $nucl($value){
        print "$nucl\n";
    }
}

but, instead of printing values like this for sequence1 in the print "$nucl\n";
A
C
C
G
T
G

it is printing output like
ACCGTG

Do I need to convert the values to array and then iterate through array or I can loop through the strings and print individual element of the string?

A:

It looks like you want to convert a string into a list of individual characters.  The split function with an empty pattern will perform this transformation.
...
my @chars = split //, $value;
foreach my $nucl (@chars) {
    print "$nucl\n";
}


Q:

How do I make a change set in RTC (eclipse) re-editable?

I've submitted for review a change set. Unfortunately i forgot to refresh my sandbox first, so that means I did not include some changes in that set.
So i lost the option to add changes to my change set.
I don't want to discard that change set because it contains important changes. I also don't want to have to deliver 2 change sets, because they contain atomic logic (logic that can't be split).
I'm having a feeling that the "reverse" option would get my change set back into an editable state, but i really have no idea what to do here.
To sum up: i need to make my change set editable again, so that i can merge it with another one.
Anyone know how i would do this?
Thx, you guys rule!

A:

I don't think you can revert back to a mutable state for your change set, if that change set was "completed" before being submitted for review.
In that case, a "reverse" (ie doing a new changeset cancelling the previous changeset), followed by a new changeset in which you redo your work and re-submit it for review might be the only solution.
However, following this example of code review in RTC, change sets should be ket mutable during the review (for the original programer to check-in new revisions of his files based on the feedback of the reviewers).

A:

You should create the new change set.
I say this for two reasons:
1) The aesthetic argument for only having one change set per work item quickly breaks down in practice - it's easy to forget a change, and you may have to make amendments due to bugs or review comments.
2) Having multiple change sets makes your changes easier to understand. Each change set can contain a logical set of changes, so a single work item may have three change sets: "Refactor code", "Update copyrights", and "Changes from review". That way, when someone annotates the files in future, they'll get something at a finer granularity than the initial work item.
Regarding the "atomic logic" argument: it probably isn't an issue unless your team is in the habit of delivering/discarding individual change sets. On the RTC project, we regularly split logically discrete changes across multiple change sets and multiple components.
If you're concerned that you may deliver change sets that logically depend on changes in other components (as I occasionally do), I suggest you chime in on bug 150421. Bug 153907 describes a similar problem, but requires a much more complex solution (making it less likely to be implemented without customer pressure).


Q:

Which murdered king was mentioned in Tywin's history lesson?

In episode 3 of season 4, there is a chilling scene with Tywin, Cersei, and

 soon to be King Tommen.

Tywin gives a history lesson and talks about the three rulers that lacked wisdom. They were Baelor who was holy, the last was Robert who was strong, but the second one he mentions I am unfamiliar with. His name was either Orys or Horace and Tywin talked about him being just but it didn't stop him from being murdered in his sleep by his brother.
I do not remember anything like this from the books so I am wondering which king Tywin is speaking about. Perhaps Orys Baratheon who was Aegon's bastard brother, but I don't remember anything about him being murdered.

A:

It appears that D&D made up King Orys I for the show. The wikia page on Orys I has this to say about the character:

As Elio Garcia of Westros.org, co-author of the World of Ice and Fire sourcebook explained, this was also not simply a matter of Charles Dance (Tywin) mispronouncing a name, because he had seen the broadcast script, and it clearly said "Orys the First" (the on-screen subtitles also spell this name the same way). Garcia stated that Benioff and Weiss had apparently just invented this "Orys the First" and he doesn't correspond to any character from the books. In order to reconcile this, Garcia said that this "Orys the First" should probably be interpreted as just a king of the independent Kingdom of the Stormlands, from long before the Targaryen Conquest - in which case he was not one of the established Targaryen kings but a local king of House Durrandon. This would make his full name "Orys I Durrandon". Tywin therefore wasn't citing him as a king who sat on the Iron Throne, but an infamous example of a (local) king, remembered over three centuries later for how his own brother murdered him. Garcia also pointed out that "Orys" was not a common name used in the Stormlands until after Orys Baratheon became their new ruler during the Targaryen Conquest.

However, as far as I can see all of this information is gathered from the following quote and no others:

Having seen the broadcast script, D&D invented a King Orys. Fairly sure he's intended to be a Storm King, though of course the name Orys is not originally from the stormlands.
  Don't worry, Oberyn's daughters are safe.

Therefore the full quote from the wikia seems to be making guesses as to who Orys I is. As far as we know he was some Storm King though again that is only a guess but at least it is by Elio.
The previous quote states that the script stated Orys and not Aerys. Both transcripts I was able to find also state Orys I:

A good king must be just. Orys I was just. Everyone applauded his reforms.
  Springfield! Springfield!

And:

TYWIN: Yeah. A good king must be just. Orys I was just. Everyone applauded his reforms. Nobles and commoners alike. But he wasn't just for long. He was murdered in his sleep
  after less than a year by his own brother. Was that truly just of him? To abandon his subjects to an evil that he was too gullible to recognize?
  Genius


Q:

What do you call a pair of words which would be meaningless without one of them?

I am referring to a set of words that wouldn't make sense if one word or the other was omitted. Like barbershop quartet, or Cyber Security. What do you exactly call this set of words?

A:

A collocation is also an option, though the meaning is broader than requested.

In corpus linguistics, collocation defines a sequence of words or terms that co-occur more often than would be expected by chance.
A pair or group of words that are juxtaposed in such a way

“strong coffee” and “heavy drinker” are typical English collocations

A:

A phrase.

Noun: A small group of words standing together as a conceptual unit, typically forming a component of a clause.

A:

This phenomenon is called a

stormy petrel

which is both the name of the kind of bird and the name of the linguistic phenomenon because there is no such thing as a petrel of any other kind other than 'stormy'.
There are a number of examples here
It is also mentioned here at ELU.
The phenomenon could also be seen in single words which are formed from multiple morphemes, such as 'disgruntled', for which one of them never appears alone. Here is a Language log posting that is a quote of a passage intentionally filled with examples of these uncommonly exposed roots (mostly negatively prefixed words that have had the prefix removed).
From either of these lists, I don't see any examples where -neither- part stands alone.


Q:

Create a dynamic table with adding column and row that depends on data in JQuery or JavaScript

I have a table that I wish to make it more dynamic.
How to change this code into dynamic table like for example.
Example for Current Version and Revision Date column.
If the Current Version and Revision Date th have a data it will create another column to make it 3 or 4 and so on Current Version and Revision Date column.
Example for Remarks column.
If the Remarks column have a data add another column inside Remarks column which is 1st, 2nd, 3rd, 4th ... and so on.
Please see the sample output below.

                    ID
                    Document Name
                    Document ID
                    Current Version
                    Current Version
                    Remarks
                    Signature

                    Revision Date
                    Revision Date
                    1st
                    2nd

Sample Output

A:

I would suggest you using the JsViews package - it will fit to your task very well.
I have prepared an example using your sample data, extended for 2 rows: jsfiddle
Here is jsViews/jsRender template code:

            ID
            Document Name
            Document ID
            {{for ~makeArray(maxVersions)}}
            Current Version
            {{/for}}
            Remarks
            Signature

            {{for ~makeArray(maxVersions)}}
            Revision Date
            {{/for}}
            {{for ~makeArray(maxRemarks)}}
            {{:~getNumberWithOrdinal(#index+1)}}
            {{/for}}

    {{for rows ~maxVersions = maxVersions ~maxRemarks = maxRemarks}}

            {{:Section_No}}
            {{:Document_Title}}
            {{:Document_ID}}
            {{for Revisions}}
            {{:#data.No}}
            {{/for}}
            {{for ~makeArray(~maxVersions - Revisions.length)}}

            {{/for}}
            {{for remarks}}
            {{:#data}}
            {{/for}}
            {{for ~makeArray(~maxRemarks - remarks.length)}}

            {{/for}}
            {{:Signature}}

            {{for Revisions}}
            {{:#data.Approval_Date}}
            {{/for}}
            {{for ~makeArray(~maxVersions - Revisions.length)}}

            {{/for}}

    {{/for}}

And JS:
var APIData = [
  {
    Section_No: '4.1',
    Document_Title: 'Sample Document Title',
    Document_ID: 'QM-CI-001',
    Revisions: [
      { No: '01', Approval_Date:'8/23/2017' },
      { No: '02', Approval_Date: '3/12/2018' },
    ],
    remarks: [ 'OK', 'OK' ],
    Signature: 'Signature'
  },
  {
    Section_No: '4.2',
    Document_Title: 'Sample Document Title 2',
    Document_ID: 'QM-CI-002',
    Revisions: [
      { No: '01', Approval_Date: '3/12/2018' },
    ],
    remarks: [ 'OK', 'OK', 'OK' ],
    Signature: 'Signature2'
  },
];

$.views.helpers({
  getNumberWithOrdinal: function(n) {
    var s=["th","st","nd","rd"],
    v=n%100;
    return n+(s[(v-20)%10]||s[v]||s[0]); },
  makeArray: function(count) {
    var array = [];
    if(count) { array[count-1] = {}; }
    return array;
  }
});

var template = $.templates("#theTmpl");

var data = {
  maxVersions: 1,
  maxRemarks: 1,
  rows: APIData
};

APIData.forEach(function(row){
  var versions = row.Revisions.length;
  if( versions > data.maxVersions) { data.maxVersions = versions; }
  var remarks = row.remarks.length;
  if( remarks > data.maxRemarks) { data.maxRemarks = remarks; }
});

template.link("#result", data);


Q:

A dynamic column name with value in sql query

I'm trying to execute a SQL query which will return a custom column with a default value.
This is the actual query:
SELECT A.ID, A.NAME
FROM dbo.A
WHERE (A.ID NOT IN (SELECT B.ID FROM dbo.B)) AND (A.ID = 5)

But I would like to return the result as follows-
ID  |   Name   |   Address
===============================
1   |  abc     |  Not available
2   |  xyz     |  Not available

Please note that, Address column is not in the database table.
Is there any way to do it?

A:

you can do this. Should work
SELECT A.ID, A.NAME, 'Not available' as Address
FROM dbo.A
WHERE (A.ID NOT IN (SELECT B.ID FROM dbo.B)) AND (A.ID=5)


Q:

Developing Chat/Real time web application

I am currently doing my research on building a chat system with more than 10k users connected online. I came across technologies and ways to do it such as jabber(XMPP), websockets, long polling, push. As far as I now, long polling might not work given the number of users. I know there is a lot of ways to accomplish this. I also know that facebook and Google chat systems are developed on XMPP.
I would truly appreciate if anyone could point me to the right direction. I believe all these methods and technologies out there are good depending on the scale of the project. I definitely need performance and scalability.

A:

I've used Socket.io together with NodeJS for such a chat application. It scaled to over 10K concurrent users on moderate servers and there was a lot of room to grow.
This does depend on your limitations, tho.

What kind of hardware are you planning on using?
Which operating system would power your servers?
Which client platforms are you targeting?
Do you have an existing infrastructure you need to fit this into?
Do you have a previously selected programming language?
The existing skill sets your team members have and your team's ability to adopt new platforms and languages if necessary.

Take all of the above into consideration when making your decision.
Personally, I've found XMPP to be quite adequate, but a bit bloated for my purposes. YMMV.