Android: keeping a background service alive (preventing process death)

For Android 2.0 or later you can use the startForeground() method to start your Service in the foreground. The documentation says the following: A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and … Read more

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

As mentioned by @anon you can’t attach model once you loaded the entity with the same key. The changes must be applied to attached entity. Instead of this: db.Entry(model).State = EntityState.Modified; use this: db.Entry(v).CurrentValues.SetValues(model);

How to give outer glow to an object in a transparent png using CSS3?

This can be done using filter(drop-shadow). Here is a demo http://jsfiddle.net/jaq316/EKNtM/ And here is the code <style> .shadowfilter { -webkit-filter: drop-shadow(12px 12px 7px rgba(0, 0, 0, 0.5)); filter: drop-shadow(12px 12px 7px rgba(0, 0, 0, 0.5)); } .bottleimage { width: 500px; } </style> <img src=”http://upload.wikimedia.org/wikipedia/commons/c/ce/Coca_Cola_Zero_bottle.png” class=”shadowfilter bottleimage”/>

Simple file server to serve current directory [closed]

python3 -m http.server or if you don’t want to use the default port 8000 python3 -m http.server 3333 or if you want to allow connections from localhost only python3 -m http.server –bind 127.0.0.1 See the docs. The equivalent Python 2 commands are python -m SimpleHTTPServer python -m SimpleHTTPServer 3333 There is no –bind option. See … Read more

Force the compiler to ignore some lines in the program

Short answer: Use macros and #ifdef checking. For example: #ifdef MY_CONTROL_MACRO … #endif the code within this scope will only be compiled if you already defined the MY_CONTROL_MACRO macro. More stuff: To define such a macro, you can Add #define MY_CONTROL_MACRO to your code. Or, For VS, add MY_CONTROL_MACRO to Project > Properties > C/C++ … Read more

How to read JSON error response from $http if responseType is arraybuffer

Edit: As @Paul LeBeau points out, my answer assumes that the response is ASCII encoded. Basically you just need to decode the ArrayBuffer into a string and use JSON.parse(). var decodedString = String.fromCharCode.apply(null, new Uint8Array(data)); var obj = JSON.parse(decodedString); var message = obj[‘message’]; I ran tests in IE11 & Chrome and this works just fine.

Performing raw SQL queries in Yii2?

You can execute raw sql like this $connection = Yii::$app->getDb(); $command = $connection->createCommand(” SELECT SUM(bets.balance_return) AS total_win , bets.user_id , users.user_name , users.user_status FROM bets INNER JOIN users ON bets.user_id = users.id WHERE users.user_status=”verified” AND bets.date_time > :start_date GROUP BY bets.user_id ORDER BY total_win DESC”, [‘:start_date’ => ‘1970-01-01’]); $result = $command->queryAll(); I recommend reading: http://www.yiiframework.com/doc-2.0/yii-db-connection.html#createCommand()-detail … Read more