text:
Q: Do bots run code in React's ComponentDidMount? I would like to know if bots (e.g. Google search engine crawlers) run a client side JavaScript and hence can trigger ComponentDidMount.
My app has many profiles, and is recording the number of profile views by making a POST request in the profile components' ComponentDidMount
e.g.
class Profile extends React.Component {
    componentDidMount() {
      const { params: { id } } = this.props;
        client.post(`/profile/${id}/views`)
         .catch(err => console.log('Error while incrementing view', err));
    }
    ....
}

But I noticed that the number of views I recorded is greater than page views in Google Analytics  by about 30%.
My app is server-side rendered and does not have <meta name="fragment" content="!> in the <head />.
Could the disparity have been caused by bots running client side javascript, and hence running ComponentDidMount code? If so, what would be a reliable way to measure the profile views?
Edit
I did an experiment to detect bots and check if they are doing a POST request to the URL given above. If so, it means that they are running ComponentDidMount.
I put the following middleware in my Express server:
app.use((req, res, next) => {
  const ua = req.headers['user-agent'];
  if (isBot(ua)) {
    console.log('BOT DETECTED', req.url, ua);
  } else {
    console.log('not a bot', req.url, ua);
  }
  next();
});

When a bot hits the profile page, the log shows:
BOT DETECTED /profile/1111 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

When I, as a user, hit the profile page, the log shows:
not a bot /profile/1111 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
not a bot /profile/1111/views/views Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

So it seems that Google crawlers do not run my componentDidMount code.
But what caused the disparity? Could it have been that Google Analytics page views is not at all accurate?

A: Google crawlers now read javascript, so your front end frameworks and libraries work amazingly well. BUT, the things are not really that simple.
Google bots do parse your dynamic content, but if you call any API's(get/post) from your javascript bots generally dont wait for them, thus if most of your content is coming through API calls bot wont read the text.
Now coming to google analytics, yes componentDidMount() is read by google crawlers. I would suggest firing an event as first thing in your componentDidMount() before the API call starts.


text:
Q: How to avoid grey screen when I close excel? I use an addin that once opened opens other workbooks ( *.xlsm files) with some macros. These workbooks are hidden and contribute their macros only.
When I close excel what I see is that grey screen which indicates there is still a hidden workbook open.
How to avoid that and make excel close all hidden workbooks automatically like it happens with PERSONAL.xlsb macrobook?
Thanks.

A: You can write the event in Thisworkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.Visible = False
End Sub

redpajama_set_name: RedPajamaStackExchange


text:
Q: How can I send PNG image over TCP sockets using ZeroMQ? I have a Keras model working on Python and I want to send frames to this model from Unity 3D camera. I can easily transport strings among them by using an external library. This external library sends a byte array to Python. So, I converted Unity's camera frames to a byte array. However, I do not know how to read the sent images (byte array) on Python.
In order to handle this problem, I have tried some Sender-Receiver codes using only Python. However, those did not work.
Here are the codes:
Sender :
import zmq
import base64

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")

f = open("sample.png", 'rb')
bytes = bytearray(f.read())
strng = base64.b64encode(bytes)
socket.send(strng)
f.close()

Receiver :
import zmq
import base64

context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")

import base64
message = socket.recv()
f = open("sample.png", 'wb')
ba = bytearray(base64.b64decode(message))
f.write(ba)
f.close()

Is that a good way for sending frames from Unity to Python? Or are there other ways? How can I handle my problem? What is wrong with the codes above?

A:
Q : "Is that a good way for sending frames from Unity to Python?"

I dare to say.

However, I do not know how to read the sent images (byte array) on Python.

Why would ever one use a tool to "encode" something,without having the matching tool to "decode"?

Q : "Or are there other ways?"

Oh sure there are.

Q : "How can I handle my problem?"

Best learn such tools, that you can safely use, both for the encode & the decode phases. Plenty of such available as Python standard modules - numpy with pil/pillow or cv for image conversions, dill or pickle for SER/DES or even a struct.

Having used these for ages with ZeroMQ, you may be sure to go in the right direction using safe tools.

Q : "What is wrong with the codes above?"

This will never fly.
The "Sender",having been proposed as a REP-instance can never start with a call to the .send()-method.Never.
The "Receiver",having been proposed as a REQ-instance can never start with a call to the .recv()-method.Never.
Sounds complicated? Yes, the choice of REQ/REP was not mine.
ZeroMQ REQ/REP Formal Scalable Communication Archetype is one of the most complicated ( operating an internal distributed Finite-State-Automaton (dFSA), actually 1:N of them, having not a risk, but a solid certainty of un-salvageably self-deadlocking any one of these N dFSA and the story ends... )
Do not get me wrong, I love ZeroMQ since ever and admire Pieter HINTJENS' & Martin SUSTRIK's immense amounts of invention & performance polishing they've breathed into the ZeroMQ's Zen of Zero, yet I try you to warn it takes some time to master the Zen start to end.
The link above has a full solution of using rather the PUB/SUB for image-sending plus some performance tweaking hints for further thinking.


text:
Q: getting no return data on notification url from paypal in adaptive paypal chained payment I am using chained method of adaptive payment:
params are like this:
$bodyparams = array("requestEnvelope.errorLanguage" => "en_US",
            "actionType" => "PAY",
            "currencyCode" => "USD",
            "cancelUrl" => "www.example.com/courses/cancelPurchase/",
            "returnUrl" => "www.example.com/courses/buyCourse/" . $courseId . "/" . $courseDetails['Course']['certificate_amount'],
            "receiverList.receiver(0).email" => $adminDetails['paypal_email'],
            "receiverList.receiver(0).amount" => round($courseDetails['Course']['certificate_amount'], 2),
            "receiverList.receiver(0).primary" => "true",
            "receiverList.receiver(1).email" => $courseDetails['UsersRole']['User']['paypal_email'],
            "receiverList.receiver(1).amount" => $courseCreatorAmount,
            "receiverList.receiver(1).primary" => "false",
            "ipnNotificationUrl" => "www.example.com/courses/ipnReturn",
        );

Here I am not getting  any data on ipnNotificationUrl provided.
It seems that after returning from paypal it is not at all hitting this url.
Please help!!
FYI: I am using cakephp as framework.

A: Do you have IPN's turned on in the account? Should be under Profile -> My Selling Tools -> Instant Payment Notifications.
Make sure this is turned on.
If it is, contact http://www.paypal.com/mts and ask them to look at the IPN history and see if there they can find any reason why this is not working properly.


text:
Q: Py-cord bot goes online but doesnt respond I have been trying to make a discord bot but when I put this piece of code tougether the bot turned online but if I use the command there is no response from the bot.
I used the import command from their github
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.command()
async def test(ctx):
    await ctx.send(content="Test")

bot.run('token')

Thanks.

A: With the latest Pycord versions (starting from 2.0.0b5 if I recall correctly), they use a Discord gateway version high enough that you have to enable the (privileged) message content intent both on your application's developer site (https://discord.com/developers/applications/YOUR_APPLICATION_ID/bot, but you can also go to https://discord.com/developers/applications and then navigate to your bot page from there)

and in your code:
intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

With this setup, your bot will receive message events with the content and can actually process your commands

Note that once your bot reaches 100 servers, this intent will require you to undergo a whitelisting process by Discord. Until then, you can freely enable the intent to test and build your bot


text:
Q: How can I achieve an infinite scrolling animation effect in Xamarin Android? I'm making an app in Xamarin Android and I want to achieve something like this:
https://github.com/Q42/AndroidScrollingImageView
Basically, it's an infinite scrolling image animation. I'm really new to android development let alone Xamarin so I'm at a loss here. I dont think the Translate animation in XML would work here. I'm thinking of translating 2 ImageViews but I dont know how to do that outside XML.
Is there a library similar to that one for Xamarin? Thanks in advance!

A: The cool thing about Xamarin.Android is that you can easily reuse existing Java libraries. If you are fine with using the AndroidScrollingImageView library instead of rolling out your own implemenetation, here's what you should do:

*

*Clone or download the project to your own computer and build the library.

*As a result, you'll get a JAR file that contains the AndroidScrollingImageView control.

*Create a new binding project and import the JAR file.

*Xamarin.Android wraps the library with C# wrappers so you can invoke Java code from C#.

*Now you can use the control in your AXML layouts and call the methods in code.

It's worth reading the binding article to understand how this works. There's also a good binding library example here, where James Montemagno does exactly what you want to do. You might want to study it to see how the binding works in real life.


text:
Q: Laravel 5.1 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint I'm trying to run the migration (see below) and seed the database, but when I run
php artisan migrate --seed

I get this error:
Migration table created successfully.
Migrated: 2015_06_17_100000_create_users_table
Migrated: 2015_06_17_200000_create_password_resets_table
Migrated: 2015_06_17_300000_create_vehicles_table

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
)) (SQL: truncate `users`)

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
))

I looked up what this error is supposed to mean, and also found examples of other people running into the same problem, even just related to using MySQL, and their solutions, but applying:
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); and
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

Within down() doesn't seem to work and when I run describe in MySQL the tables look right.
The migrations are named properly to make sure the users table is migrated first, and then vehicles so the foreign key can be applied, and the tables being setup up correctly suggests the migrations were run, but then the error occurs.  I dropped and recreated the DB and tried it again and it is the same result.  I also don't understand why it is trying to truncate on the first migration and seed of the database, I wouldn't have thought that would occur when you tried to run php artisan migrate:refresh --seed.
// 2015_06_17_100000_create_users_table.php

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username', 60)->unique();
            $table->string('email', 200)->unique();
            $table->string('password', 255);
            $table->string('role')->default('user');
            $table->rememberToken();
            $table->timestamps();
        });
    }
}

public function down()
{
    Schema::drop('users');
}

// 2015_06_17_300000_create_vehicles_table.php

class CreateVehiclesTable extends Migration
{
    public function up()
    {
        Schema::create('vehicles', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->string('make');
            $table->string('model');
            $table->string('year');
            $table->string('color');
            $table->string('plate');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');
        });
    }
}

public function down()
{
    Schema::drop('vehicles');
}

A: DB::statement('SET FOREIGN_KEY_CHECKS=0;');
App\User::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

And it works!

A: To clear a table using Eloquent:
Model::query()->delete();

Example using default user model
User::query()->delete();

A: I faced the same issue with my Role and Permission setup and this is what I did that worked as I wanted. Truncate() will reset the Increment column to 1 but throw a foreign key error while delete on the other hand works fine but doesn't reset the increment column, so I did the following in my Seeder's file (i.e RoleSeeder.php in my case)
1. [ delete() method ]
$roles = [];

... // Some foreach statement to prepare an array of data for DB insert()

// Delete and Reset Table
DB::table('roles')->delete();
DB::statement("ALTER TABLE `roles` AUTO_INCREMENT = 1");
// Insert into table
DB::table('roles')->insert($roles);

This will cascade all other child tables attached to the roles table. in my case users_roles table. This way I avoided disabling and enabling foreign key checks.
2. Something to put in mind / Second Approach [ truncate() method ]
if you don't have the intention of deleting all the data stored in the child's table (in my case users_roles table) ... You can go with truncate() and then in the DatabaseSeeders.php file you disable and enable foreign key check. As I tested this and the users_roles data was intact, the seed on affected roles table.
//RoleSeeders.php File

$roles = [];

... // Some foreach statement to prepare an array of data for DB insert()

// Truncate Table
DB::table('roles')->truncate();
// Insert into table
DB::table('roles')->insert($roles);

Then in the DatabaseSeeder.php file, you do;
public function run()
{
    DB::statement('SET FOREIGN_KEY_CHECKS=0;');

    $this->call([
        RoleSeeder::class,
    ]);

    DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}

But I prefer the delete() method, since I don't have to disable/enable the foreign key check

A: As the error says, you can not truncate tables referenced by foreign keys.  Delete should work though...
DB::table('some_table')->delete();

A: you can use
DB::table('your_table_name')->delete();

to empty a table, this won't delete the table structure. But the auto increment id will not start from initial number.

A: before drop
Schema::disableForeignKeyConstraints();

and before close run method
Schema::enableForeignKeyConstraints();

A: Here is what works for me every time.
When you're adding the foreign key, make sure to add cascade.
the syntax is like this
$table->foreign('column')->references('id')->on('table_name')->onDelete('cascade');

Make sure to replace id with whatever field is applicable for you.
Now before running the seeding add this instead of trucate
DB::statement('DELETE FROM table_name');

It will delete all the data.
Hope this helps.

A: You could just drop it with.
$table->dropForeign('posts_user_id_foreign');

A: I'm using Laravel 7.x, this worked for me. Goes without saying that it should only be used in development. To read more, check it out here.
DatabaseSeeder.php
    <?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // the Eloquent part and disabling and enabling of foreign keys is only intended for development
        Eloquent::unguard();

        //disable foreign key check for this connection before running seeders
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');

        $this->call(RolesTableSeeder::class);
        $this->call(UsersTableSeeder::class);

        // supposed to only apply to a single connection and reset it's self
        // but I like to explicitly undo what I've done for clarity
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
    }
}


text:
Q: How many cannonballs would it take to go from 70-99 slayer in Runescape? With 99 range and 99 defence, approximately how many cannonballs would it take to go from 70-99 slayer if one used cannon alone except where it can't be used?

A: To get from level 70 to level 99 takes 12,960,804 experience. To get that much slayer experience, you must deal approximately that much damage to NPCs. The number of cannonballs you will need for this depends on your average damage per cannonball. Your average damage in turn depends on your range level, your equipment, and the monsters you are fighting. If we estimate an average damage of 200 for example it will get 20 slayer exp, then you will need about 648,040 cannonballs.


text:
Q: Remove section numbers latex I have a problem with section numbering in latex. I want to remove the section numbers from headings and contents but I want the numbers to be there for lemmas, theorems etc. I want it to look like:
 Section Whatever
   Some unimportant text.

 Section Whatever else
   Another unimportant text.
   Lemma 2.1
   Theorem 2.2

 Section Whatever again
   Theorem 3.1

How can I do it? I tried
 \renewcommand\thesection{}

but it removes the numbers even from lemmas and theorems. Thank you very much :)

A: Under the default article class we can merely remove the formatting applied to the section counter by adding
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother

to the preamble. This will remove all sectional title numbering (\sections, \subsections, \subsubsections, ...), yet keep them where they are references or whenever \thesection is used.

\documentclass{article}

\newtheorem{theorem}{Theorem}[section]% Theorems numbered by section
\newtheorem{lemma}[theorem]{Lemma}% Lemma uses theorem's counter

\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother

\begin{document}

\section{Section whatever}
Some uninportant text.

\section{Section whatever else}
Another uninportant text.

\begin{lemma}
Some lemma.
\end{lemma}

\begin{theorem}
Some theorem.
\end{theorem}

\section{Section whatever again}
\begin{theorem}
Another theorem.
\end{theorem}

\end{document}


text:
Q: Get Directory from User I'm looking for a function to get a directory path from the user; I need to solicit a place to put things.  I tried using GetOpenFileName() with .dir as a filter but no joy.  I found something called GetDirectoryViaBrowse() that sounds like it might do what I want but it's part of some wizard making package and my Visual Studio knows nothing about it.  I'd like some simple non .NET widget.
Is there such a thing?

A: You are looking for the Win32 Shell API: SHBrowseForFolder

A: you can use
mkdir("your path") this function is in  library.
here is a sample code:
#include <direct.h>
#include <iostream>
#include <cstring>
using namespace std;
int main()
  {
    char folder[50];
    char path[]="c:/";
    cin>>folder;
    strcat(path,folder);
    mkdir(path);
    cout<<"Your folder has been created in drive C.";
    return 0;
    }


text:
Q: How to install applications to a WebSphere 7.0 cluster using wsadmin? I want to deploy to all four processes on a Websphere cluster with two nodes. Is there a way of doing this with one Jython command or do I have to call 'AdminControl.invoke' on each one?

A: Easiest way to install an application using wsadmin is with AdminApp and not AdminControl.
I suggest you download wsadminlib.py (Got the link from here)
it has a lot of functions, one of them is installApplication which works also with cluster.
Edit:
Lately I found out about AdminApplication which is a script library included in WAS 7 (/opt/IBM/WebSphere/AppServer/scriptLibraries/application/V70)
The docuemntation is not great in the info center but its a .py file you can look inside to see what it does.
It is imported automatically to wsadmin and you can use it without any imports or other configuration.
Worth a check.

A: @aviram-segal is right, wsadminlib is really helpful for this.
I use the following syntax:
    arg = ["-reloadEnabled", "-reloadInterval '0'", "-cell "+self.cellName, "-node "+self.nodeName, "-server '"+ self.serverName+"'", "-appname "+ name, '-MapWebModToVH',[['.*', '.*', self.virtualHost]]]
    AdminApp.install(path, arg)

Where path is the location of your EAR/WAR file.
You can find documentation here


text:
Q: Integrating phoneGap with native iOS app i'm trying to create an app which uses the combination of native functionality and the phoneGap framework. The native app has a button, upon the click of which the phoneGap ui has to be added to the view. Is there any way to achieve this? Are there any tutorials for the same?

A: Yes, this is possible. Although you might be getting yourself into some headaches. My app kind of goes the other way around, it's mostly phonegap, but occasionally i'll pop open a view that is native. Here is the link to code that shows an excellent example of how to switch between the iOS and phonegap worlds.
new updated recommended article (see update below)
These files represent a standard plugin used in phonegap. In this particular plugin, a native view is opened on top of a phonegap view. Notice you have a custom xib and everything. This plugin can be modified to display any xib with any functionality you could think of.
If you implement this plugin you will easily see how to jump back and forth. I've successfully heavily modified these classes to add LOTS of native capabilities to my phonegap project. Also you should probably check out the official phonegap guide to phonegap plugins. Here
Important Edit
Was informed original linkwas broken (not terribly surprised as this answer is very old and i've long since moved away from Phonegap) so I replaced the original link with an article that shows how to do these plugins well. In the article it explains the link is broken and gives several links where these older files are maintained, but in fact those are broken as well. Here is a branch of one of them I found that still hosts the original files on an "archive" branch. But I haven't investigated whether these files are wildly different from my original work. Good luck!

A: That's not how Phonegap is meant to be used.
To achieve what you are asking for you just need to create a Phonegap app and add the extra native functionality by writing a Phonegap plugin in Objective-C. You may add as much native code as you want.

A: I'm actually wanting to do the same thing as the original poster. Theoretically it would be comparatively easy, but non-trival to do. I'd love it if there was a PhoneGapView that one could integrate into an existing project. Bonus points if said PhoneGapView could be integrated in Interface Builder as a re-sizeable and re-positional object, basically think of it as an Object that extends UIWebView.
This is wishful thinking on my part seeing as this is how the higher-ups want my project.


text:
Q: Is it bad practice to write to files in your application's .app folder? Is it bad practice to write to files in your application's .app folder on MacOS? I want the user to be able to delete the app and configs via drag and drop from Applications folder.

A: Yes it is bad practice, for a number of reasons:

*

*macOS is a multi-user OS, and in general each user should have their own preferences, settings, etc.

*Users generally don't (and shouldn't) have file permissions to modify things in /Applications. If an admin user manually installed an app via drag-and-drop, they will have write access to it, but this can't be counted on (especially since, as I said, it's a multi-user OS and a different user may've installed it).

*If your app is code-signed, changes in the app container will break the signature and the app will refuse to open (it's considered damaged). Even it you don't sign it, the OS may apply an ad-hoc signature to it (for various reasons), and modifications will break that.


text:
Q: Changing static value permanently I have a Windows Communication Foundation (WCF) service running. When a service is called, sometimes the service has to start again and populate all the static values because I guess the webserver shuts down the service after period of inactivity. If it is called constantly, it stays active and all the values are populated. I have a static integer in that class that gets used by the service calls and I have that at 30 for example, but I sometimes set that static value using service call so that the new value is 20, but since the service gets deconstructed by the web server after a period of inactivity, the value is again initialized to 30. Is there a way to permanently set the 30 value to 20 when the WCF service gets constructed (static constructors) get called? Is there any better way to do this? I have 2-3 of these values that I want to change permanently whenever I want through a web service call.

A: Even without the restart, if you are only storing this value in memory it's not stored "permanently".  A database or similar would be great, but if you are not using a database for anything already, using one to store a single value seems like overkill.  What about writing to a file?

A: I would suggest using the built in Settings static class
Settings.Default["StaticValue"] = "30";
Settings.Default.Save();

http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx


text:
Q: SQL query for retrieving the time gap between the timestamp values i have two tables in oracle i need to write a SQL query for the following problem,
Note: client working hours are from morning 9 a.m. to 6 p.m
tab1 contains issue created and resolved time stamp,
In tab1 an issue was raised on 24th dec 2017 at 6:00 p.m (at office closing time) and it was resolved on 26th dec 2017 at 10 a.m. (just one hour after office opens)
i want to calculate the time between the issue created and resolved, in this case the time between these two is "one hour" because 25-dec-2017 is holiday
(holiday list is available in holiday table)
condition 1: if holiday dates are existed between the dates should be ignored
condition 2: if the weekend (saturday and sunday) are existed between these two dates (created and resolved) then it should be ignored.
Can anyone help me on this?
tab1 and tab2:

A: You can do this using a correlated subquery to find the number of holidays (weekends must be included in the holidays table) and use TIMESTAMP operations to achieve your result. This works for PostgreSQL, but should be easily adaptable for Oracle:
SELECT issue_created_date, issue_resolved_date, ((days_in_bet - downtime_days) * INTERVAL '24 HOUR') + hours AS total_hours
FROM
(
SELECT issue_created_date, eod_timestamp, issue_resolved_date, sod_timestamp, downtime_days,
       CASE WHEN DATE_TRUNC('DAY', issue_created_date) <> DATE_TRUNC('DAY', issue_resolved_date) THEN DATE(sod_timestamp) - DATE(eod_timestamp) - 1 ELSE 0 END AS days_in_bet,
       CASE WHEN DATE_TRUNC('DAY', issue_created_date) = DATE_TRUNC('DAY', issue_resolved_date) THEN issue_resolved_date - issue_created_date
        ELSE (eod_timestamp - issue_created_date) + (issue_resolved_date - sod_timestamp) END AS hours
FROM
(
    SELECT issue_created_date, DATE_TRUNC('DAY',issue_created_date) + INTERVAL '18 HOUR' AS eod_timestamp,
                                                                                issue_resolved_date, DATE_TRUNC('DAY',issue_resolved_date) + INTERVAL '9 HOUR' AS sod_timestamp,
                                                                                (SELECT COUNT(1) FROM tab2 h WHERE h.holiday BETWEEN i.issue_created_date AND i.issue_resolved_date) AS downtime_days
    FROM tab1 i
) a1
) a2

Note that an important assumption this query makes is that issues can be created AND resolved only on working days.
Output:
issue_created_date    |  issue_resolved_date  | response_time_hours
"2017-12-24 18:00:00"   "2017-12-26 10:00:00"   "01:00:00"
"2017-12-26 13:00:00"   "2017-12-26 18:00:00"   "05:00:00"
"2017-12-27 08:00:00"   "2017-12-27 10:00:00"   "02:00:00"
"2017-12-27 14:00:00"   "2017-12-28 09:30:00"   "04:30:00"


text:
Q: The import org.omg cannot be resolved I'm following this tutorial on how to set up corba, but I can't use the packages they are talking about, and no where on the internet can give an adequate explanation of how to get them.
I want the following imports to not give me an error.
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

Downloading JacORB just gives me a github file the also has imports of the package 'org.omg'
Somebody said use this findjar site, I have no idea what the things are on that site

A: Be sure to download the CORBA API from a reliable source:

*

*Glassfish

*JOnAS
Add a folder to your project called lib and drag the jar file into lib
Right Click the jar file and select Build Path -> Add to Build Path
Then go to project -> properties -> libraries and move the jar to your CLASSPATH


text:
Q: Internal Server Error - PHP - cPanel I have a PHP site hosted with cPanel.
Yesterday, I changed certain directory listings (using Index Manager). I initially changed the settings from "Default System Setting" to "No Indexing" on all the directories and afterwards I have started getting following error :
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to     complete your request.

Please contact the server administrator, webmaster@***.*** and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

I have then reverted all the settings back to their original but still getting the same error.
Following error is shown in Error Log -
[Tue Dec 04 01:20:54 2012] [alert] [client 119.226.234.18] /home/***/public_html/.htaccess: ErrorDocument takes two arguments, ErrorDocument Apache configuration directive

I don't understand how to resolve this!! Please help!!

A: It's an error in your htaccess.
Open .htaccess in a texteditor. The line with ErrorDocument should look like this:
ErrorDocument 404     /404.html

A: I was also facing same issue.
By changing the folder permission that I was trying to access to 755 in file manager resolved the issue.

A: Try to check this error log:
/usr/local/apache/logs/error_log


text:
Q: rewrite path to get parameter I need any call to a html-file to be changed to a php and the full path and file should be passed on as a get-parameter.
for example
http://www.domain.com/any/path/file.html

should become
http://www.domain.com/index.php?path=any-path-file.html

I want to route every call to a html-file through the php file. The rewriting should ignore any other files.
In addition: would it be possible to add other parameters again?
/file.html?foo=bar
becomes
/index.php?path=file.html&foo=bar

thanks in advance
Stil

A: I don't think its possible to do exactly what you are trying to do, but I think we can get so close it wont matter.
The following rewrite
RewriteCond %{REQUEST_URI} \.html$
RewriteRule (.*) /index.php?path=$1&%{QUERY_STRING} [L]

will take any request that ends with .html and rewrite it to index.php, adding the complete path as a query string. It will also append any existing query string on the original request to the new request. This doesn't do quite what you asked for as the path variable will look like path=any/path/file.html, not path=any-path-file.html as you asked for. But this is nothing which can't just be sorted out in the first few lines of of index.php with
    if( isset($_GET['path']) ) {
        $_GET['path'] = str_replace("/","-",$_GET['path']);
    }


text:
Q: Can't see Textbox text in DataGrid I am trying to make a DataGrid in WPF that will display the different properties of the items in a given collection. So far, everything works perfectly, except for one. Here is an image of my DataGrid, which is fully populated just as intended:

And you may already see my problem. Each and every item has a value associated with it, which is properly binded. However, I cannot see the value for any of the items unless I specifically click on that cell. For example:

I want the values to be visible at all times, just like the Name and Default Value Columns, but it is very important that the value, and only the value, is editable from the DataGrid at runtime. Here is the XAML I have in place for the datagrid:
<DataGrid Margin="20" AutoGenerateColumns="False" ItemsSource="{Binding ConfigurationParameterCollection}" Name="MasterListBox" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="MasterListBox_SelectionChanged" AlternationCount="2" DockPanel.Dock="Top" HorizontalAlignment="Center" Width="1000" >
        <DataGrid.Columns>

            <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>

            <!-- Begin Problem Area-->

            <DataGridTemplateColumn Header="Value">
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>

            <!-- End Problem Area-->

            <DataGridTextColumn  Header="Default Value" Binding="{Binding DefaultValue}"/>

        </DataGrid.Columns>
    </DataGrid>

Don't worry about the name of the DataGrid, it used to be a ListBox and I just never bothered to change the name. Everything links up perfectly, I just can't figure out why the TextBox text is not visible.
Any help you can give is much appreciated.
EDIT
I know that I can achieve this with using CellTemplate instead of CellEditingTemplate, but the latter has the feature of only editing on two clicks, but selecting the row otherwise. I want to have this feature, so If there is a way to do that with CellTemplate please let me know. With CellTemplate, I see the boxes at all times:

I want it to be like in the second picture, where the rest of the column appears in style with the datagrid, while the cell I am editing looks like a text box.

A: Change
    DataGridTemplateColumn.CellEditingTemplate
To
    DataGridTemplateColumn.CellTemplate

You can specify a display template, and an edit template ...
        <DataGridTemplateColumn Header="Value">
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Value, Mode=TwoWay}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>


text:
Q: ios single AVAudioPlayer I'm working on an ios app with uitabviewcontroller that plays some music. I don't want each tab viewcontroller to create it's own audio player. I want to have one single audio player and have all the viewcontrollers share it.
so I have created a class called player, which would initiate avaudioplayer with the song url and plays the song,
#import <AVFoundation/AVFoundation.h>

@interface player : NSObject {

    AVAudioPlayer *theMainAudio;

}

-(void)playSong:(NSString *)songName;

@end

I want to create only one instance of this class and all my viewcontrollers share it. I've tried creating it in my delegate,
@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

     UIWindow *window;
     UITabBarController *tabBarController;
     player *theMainPlayer;

 }

 @property (nonatomic, retain) IBOutlet UIWindow *window;
 @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
 @property (nonatomic, retain) player *theMainPlayer;

 @end

in .m file,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

     //some other stuff here....

     theMainPlayer = [[player alloc]init];

     return YES;
}

and then I called it in my viewcontrollers,
player myPlayer = ((AppDelegate *)[UIApplication sharedApplication].delegate).theMainPlayer;

but this didn't work.
can anyone tell me what's wrong with what I've done or if there is any other way to do what I want to do, which is to create a player object and share it among all of my viewcontrollers.
Thanks

A: create a singleton, in your player.m
#import "player.h"

@implementation player

static player *sharedInstance = nil;

+ (player *)sharedInstance {
    if (sharedInstance == nil) {
        sharedInstance = [[super allocWithZone:NULL] init];
    }

    return sharedInstance;
}

- (id)init
{
    self = [super init];

    if (self) {
        // Work your initialising here as you normally would
    }

    return self;
}

-(void)playSong:(NSString *)songName
{
    // do your stuff here
}

to use this class, just import the player.h
[[player sharedInstance] playSong:@"something"];

A: How did it go wrong? To me it seems the last line would cause compile error. You should add asterisk for class declaration :
player * myPlayer = ((AppDelegate *)[UIApplication sharedApplication].delegate).theMainPlayer;

Other than that, I didn't catch anything.
But I prefer using Singleton pattern for cases like this.
Reference :
http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Singleton.html
http://www.galloway.me.uk/tutorials/singleton-classes/


text:
Q: Plot iteratively single variable from multiple dataframe using matplotlib i am trying to plot age of all participants from multiple dataframes. I want to plot age from all dataframes into one plot. so the final plot should contain datapoints plotting each age.
Following is piece of code i am trying but it gives be blank plots.
import pandas as pd
import glob
import matplotlib.pyplot as plt
%matplotlib inline

filelist = glob.glob('/Users/kadb/Desktop/participants_tsv_files/*.tsv')
# fig = plt.figure()
ax = fig.add_subplot(111)
# ax.xaxis.set_ticks(df.index)
# ax.xaxis.set_ticklabels(df['g'])
plt.figure()
for file in filelist:
    df = pd.read_table(file)
    if 'age' in df.columns:
        df['age'] = pd.to_numeric(df['age'])
#         df['age'] = df['age'].astype(str).convert_objects(convert_numeric=True)
#         plt.plot(df['age'], 3)
        for index, row in df.iterrows():
            if type(row['age']) is int:
                if row['age'] >= 0:
                    age = row['age']
                    plt.plot(age,10)

example tsv file:
participant_id  gender  age physioSampling  restAcquisiotion
sub-01  M   26  50  after_cuedSGT
sub-02  M   21  50  after_cuedSGT
sub-03  M   22  50  after_cuedSGT
sub-04  M   23  50  after_cuedSGT
sub-05  M   21  50  before_cuedSGT
sub-06  M   19  50  before_cuedSGT
sub-07  F   18  50  before_cuedSGT
sub-08  F   21  50  before_cuedSGT
sub-09  M   20  40-60   before_cuedSGT
sub-10  F   21  50  before_cuedSGT
sub-11  F   20  50  before_cuedSGT
sub-12  M   21  50  before_cuedSGT
sub-13  F   31  50-60   before_cuedSGT

A: I guess the file cannot be read in correctly. Try using
pd.read_table(f, delim_whitespace=True)

You're creating the subplot before creating the figure. This needs to be reversed.
Next, what if type(row['age']) is not int?
If you can make sure that row['age'] contains ints, the next problem would be that you're trying to plot a single point as a line plot.
Use
plt.plot(age,10, marker="o")

such that the point has a marker attached to it, which can be shown.
In total it seems the code can be made much more compact; so the following should give you what you need.
u = u"""participant_id  gender  age physioSampling  restAcquisiotion
sub-01  M   26  50  after_cuedSGT
sub-02  M   21  50  after_cuedSGT
sub-03  M   22  50  after_cuedSGT
sub-04  M   23  50  after_cuedSGT
sub-05  M   21  50  before_cuedSGT
sub-06  M   19  50  before_cuedSGT
sub-07  F   18  50  before_cuedSGT
sub-08  F   21  50  before_cuedSGT
sub-09  M   20  40-60   before_cuedSGT
sub-10  F   21  50  before_cuedSGT
sub-11  F   20  50  before_cuedSGT
sub-12  M   21  50  before_cuedSGT
sub-13  F   31  50-60   before_cuedSGT"""

import io
import pandas as pd
import glob
import matplotlib.pyplot as plt

filelist = [io.StringIO(u)]

fig, ax = plt.subplots()

for f in filelist:
    df = pd.read_table(f, delim_whitespace=True)
    if 'age' in df.columns:
        #df = df[df["age"] != "n/a"] # remove n/a values or
        df = df[~df["age"].isin(["n/a"])]
        plt.plot(df['age'], [3]*len(df), marker="o", ls="")

plt.show()


text:
Q: Does Google spanner supports merge statements Does google cloud Spanner supports Merge statements like Oracle?
For example I have SQL' like below. Will it work ? I am getting INVALID ARGUMENT while running the snippet.
merge P1 c
using (select sumery.RunId from PS sumery where sumery.RunId=1010192) s
on (c.LastRunId=s.RunId)
when MATCHED THEN
udpate c.ProcessTypeCd ='Update'
WHEN  NOT  MATCHED THEN
INSERT INTO P1
(ProcessName, ActiveF, InProgressF)
VALUES('12', 'Y', 'N');

A: No, Cloud Spanner only supports INSERT, UPDATE and DELETE DML statements. It does however support InsertOrUpdate mutations which has the same semantics as a MERGE statement.
Your question does not include any information how and/or with which programming language you are connecting to Cloud Spanner, but all the client libraries and the JDBC driver for Cloud Spanner support writing mutations. A sample for writing with mutations can be found here: https://cloud.google.com/spanner/docs/samples/spanner-insert-data


text:
Q: C Programming turning array into an image I am using C to run a phase retrieval algorithm on images.
I am using ImageJ to convert the .png into a text image that I then read into my code and run the code.
At the end I have printed the output to a text array, and then have to read it from imageJ as a text image.
I was wondering if there is a way to get an image straight from c?

A: You could try to use OpenCv, an Open source library of programming functions for computer vision tasks.
It could read and write on diferent image file formats using imread and imwrite functions, as you could see on this example from OpenCv's documentation web site:
#include <cv.h>
#include <highgui.h>

using namespace cv;

int main( int argc, char** argv )
{
 char* imageName = argv[1];

 Mat image;
 image = imread( imageName, 1 );

 if( argc != 2 || !image.data )
 {
   printf( " No image data \n " );
   return -1;
 }

 Mat gray_image;
 cvtColor( image, gray_image, CV_BGR2GRAY );

 imwrite( "../../images/Gray_Image.jpg", gray_image );

 namedWindow( imageName, CV_WINDOW_AUTOSIZE );
 namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );

 imshow( imageName, image );
 imshow( "Gray image", gray_image );

 waitKey(0);

 return 0;
}

Hope it helps!


text:
Q: jQuery dialog box does not close Here is my jquery for dialog
</script>

and here is my delete view
@using (Html.BeginForm()) {

Are you sure you want to delete?

       @Html.HiddenFor(model=>model.UId)

   Name:
    @Html.DisplayFor(model =>model.FName)
    @Html.DisplayFor(model => model.LName)

    PAddress:
    @Html.DisplayFor(model => model.PAddress)

     <input type="submit" value="Yes"/>
    <button  class="close">No</button>

}

the problem is when I call the close class from the button the dialog does not close.but when I remove preventDefault the dialog closed. any help please why the dialog box is not closing.

A: $(".close").live("click", function (e) {
    e.preventDefault();
    $('#yourdivId').closest(".dialog").dialog("close");
});

try this...

A: can you please try this
$(".close").live("click", function (e) {
                e.preventDefault();
                $(this).closest(".dialog").dialog("close");
            });

put this code in
$(document).ready(function () {

This may work for you...

A: Here you need not to user preventDefault() function. preventDefault() is used to prevent unwanted default action of an event.
As an example, when you click a link, it will redirect you to another page. If you want that link to do something else, you need to prevent default and write your action.
Since this button doesn't have a default action (defined with "type" attribute), you need not to use preventDefault().

A: first of all you put $.ajaxSetup({ cache: false }); inside document ready function.

A: You can change your delete view like this.

@using (Html.BeginForm()) {

Are you sure you want to delete?

       @Html.HiddenFor(model=>model.UId)

   Name:
    @Html.DisplayFor(model =>model.FName)
    @Html.DisplayFor(model => model.LName)

    PAddress:
    @Html.DisplayFor(model => model.PAddress)

     <input type="submit" value="Yes"/>
}
<button  class="close">No</button>

A:  $(".ui-dialog").hide();
    $(".ui-widget-overlay").hide();


text:
Q: How to use texture compression in openGL? I'm making an image viewer using openGL and I've run into a situation where I need to load very large (>50MB) images to be viewed.  I'm loading the images as textures and displaying them to a GL_QUAD which has been working great for smaller images, but on the large images the loading fails and I get a blank rectangle.  So far I've implemented a very ugly hack that uses another program to convert the images to smaller, lower resolution versions which can be loaded, but I'm looking for a more elegant solution.  I've found that openGL has a texture compression feature but I can't get it to work. When I call
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_ARB, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());

I get the compiler error "GL_COMPRESSED_RGBA_ARB undeclared".  What am I doing wrong?  Is there a library I'm missing?  And more generally, is this a viable solution to my problem?
I'm using Qt Creator on a Windows Vista machine, with a NVIDIA Quadro FX 1700 graphics card.

A: On my own GFX card the maximum resolution for an opengl texture is 8192x8192, if your image is bigger then 50MB, it is propably a very very high resolution...
Check http://www.opengl.org/resources/faq/technical/texture.htm , it describes how you can find the maximum texture size.

A: First, I'd have to ask what resolution are these large images? Secondly, to use a define such as GL_COMPRESSED_RGBA_ARB, you would need to download and use something like GLEW which is more modernized in the GL api than the standard MS-Dev install.


text:
Q: My first scrapy xpath selector I am very new at this and have been trying to get my head around my first selector. Can somebody help me? I am trying to extract data from this page:

http://groceries.asda.com/asda-webstore/landing/home.shtml?cmpid=ahc--ghs-d1--asdacom-dsk-_-hp#/shelf/1215337195041/1/so_false

all the info under div class = listing clearfix shelfListing but I can't seem to figure out how to format response.xpath().
I have managed to launch the scrapy console but no matter what I type in response.xpath() I can't seem to select the right node. I know it works because when I type
>>>response.xpath('//div[@class="container"]')

I get a response. Yet, I don't know how to navigate to the listsing cleardix shelflisting. I am hoping that once I get this bit I can continue working my way through the spider.
PS I wonder if it is not possible to scan this site - is it possible for the owners to block spiders?

A: The content inside the div with listings class (and id) is loaded via an XHR request asynchronously. In other words, the html code that Scrapy gets doesn't contain it:
$ scrapy shell http://groceries.asda.com/asda-webstore/landing/home.shtml?cmpid=ahc--ghs-d1--asdacom-dsk-_-hp#/shelf/1215337195041/1/so_false
>>> response.xpath('//div[@id="listings"]')
[]

Using browser developer tools, you can see the request going to http://groceries.asda.com/api/items/viewitemlist url with a bunch of GET parameters.
One option would be to simulate that request and parse the resulting JSON:

How to do it is actually a part of a different question.

Here's one possible solution using selenium package:
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('http://groceries.asda.com/asda-webstore/landing/home.shtml?cmpid=ahc--ghs-d1--asdacom-dsk-_-hp#/shelf/1215337195041/1/so_false')

div = driver.find_element_by_id('listings')
for item in driver.find_elements_by_xpath('//div[@id="listings"]//a[@title]'):
    print item.text.strip()

driver.close()

Prints:
Kellogg's Coco Pops
Kelloggs Rice Krispies
Kellogg's Coco Pops Croco Copters
...


text:
Q: Extract HTML table written using unordered list into Google sheets I am trying to covert the HTML table into Google sheet table using 'IMPORTXML' but I am not able to construct the query.
Using =IMPORTXML(A1,"//div[@class='dailynav']"), imports all the data in just one cell. I tried using 'table' but I think that does not work with  tables. Please help me in constructing the formula.
Webpage: https://www.hdfcpension.com/about-hdfc-pmc/nav/
Relevant HTML code:

HDFC Pension - Daily NAV

Scheme NameNAV as on 02/05/2013

HDFC Pension Fund Scheme C -Tier I13.724

HDFC Pension Fund Scheme E -Tier I 11.9621

HDFC Pension Fund Scheme G -Tier I13.1091

HDFC Pension Fund Scheme C -Tier II15.8436

HDFC Pension Fund Scheme E -Tier I13.4959

HDFC Pension Fund Scheme G -Tier I14.0168

A: use:
=IMPORTXML("https://www.hdfcpension.com/about-hdfc-pmc/nav/",
 "//div[@class='dailynav']/ul/li/p")


text:
Q: Is there a feasible way to Implement expand_grid() in PANDAS for 200+ categories? The following example from the web for implementing the function expand_grid() contains three variables: height (2 categories), weight (3 categories), sex (2 categories), for a total of 2 * 3 * 2 = 12 categories.
df={'height': [60, 70],
'weight': [100, 140, 180],
  'sex': ['Male', 'Female']}

Running expand_grid on the above object
expand_grid(df)

produces the following outcome:
       sex  weight  height
0     Male     100      60
1     Male     100      70
2     Male     140      60
3     Male     140      70
4     Male     180      60
5     Male     180      70
6   Female     100      60
7   Female     100      70
8   Female     140      60
9   Female     140      70
10  Female     180      60
11  Female     180      70

I would like to do the same for a dataset with the following columns (categories):
Race (9), Marital_Status (3), Sex (2), Age (2), Hispanic (2).
That's 9*3*2*2*2 = 216 categories.
I would like something like the following:
Race  Marital_Status Sex Age Hispanic
0 White Married Male Under_18 Hispanic
1 White Married Male Under_18 Non-Hispanic
2 White Married Male Over_18 Hispanic
3 White Married Male Over_18 Non-Hispanic
4 White Married Male Over_18 Hispanic
5 White Married Female Under_18 Hispanic
.
.
.
216 Asian Single Female Over_18 Non-Hispanic

When I try to run expand_grid(), the system runs out of memory.
I was told that if there is a way that Python recognizes the data type (e.g. list, vector, etc.) before hand, that would be faster and computationally less expensive. Is there a feasible way to implement this?
Thanks much!

A: PSL itertools package can do the job.
import itertools
import pandas as pd

cat = {
    'C1': ['A', 'B', 'C'],
    'C2': ['A', 'B'],
    'C3': ['A', 'B', 'C', 'D']
}

order = cat.keys()
pd.DataFrame(itertools.product(*[cat[k] for k in order]), columns=order)

It creates a DataFrame with all possibles combinations (Cartesian Product) of category modalities:
   C1 C2 C3
0   A  A  A
1   A  A  B
2   A  A  C
[...]
22  C  B  C
23  C  B  D


text:
Q: spark - Exception in thread "main" java.sql.SQLException: No suitable driver SOLVED:
prop.setProperty("driver", "oracle.jdbc.driver.OracleDriver") this line must be added to the connection properties.
I'm trying to lunch a spark job in local. I created a jar with dependencies by maven.
This is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.agildata</groupId>
    <artifactId>spark-rdd-dataframe-dataset</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>

    <properties>
        <exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
        <spark.version>1.6.0</spark.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>${spark.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_2.11</artifactId>
            <version>${spark.version}</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0.2</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <!-- get all project dependencies -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!-- MainClass in mainfest make a executable jar -->
                    <archive>
                        <manifest>
                            <mainClass>example.dataframe.ScalaDataFrameExample</mainClass>
                        </manifest>
                    </archive>

                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

I run the mvn package command and the build is succesfull. After i try to run the job like this way: GMAC:bin gabor_dev$ sh spark-submit --class example.dataframe.ScalaDataFrameExample  --master spark://QGMAC.local:7077 /Users/gabor_dev/IdeaProjects/dataframe/target/spark-rdd-dataframe-dataset-1.0-jar-with-dependencies.jar but it throws this: Exception in thread "main" java.sql.SQLException: No suitable driver
Full error message:
16/07/08 13:09:22 INFO BlockManagerMaster: Registered BlockManager
Exception in thread "main" java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:315)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$2.apply(JdbcUtils.scala:50)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$2.apply(JdbcUtils.scala:50)
    at scala.Option.getOrElse(Option.scala:120)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.createConnectionFactory(JdbcUtils.scala:49)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:120)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation.<init>(JDBCRelation.scala:91)
    at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:222)
    at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:146)
    at example.dataframe.ScalaDataFrameExample$.main(ScalaDataFrameExample.scala:30)
    at example.dataframe.ScalaDataFrameExample.main(ScalaDataFrameExample.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
16/07/08 13:09:22 INFO SparkContext: Invoking stop() from shutdown hook

Interest thing that if i build this way inside the IntelliJ IDEA nested console: mvn package exec:java -Dexec.mainClass=example.dataframe.ScalaDataFrameExample it's running, and there is no error.
This is the relevant scala code part:
val sc = new SparkContext(conf)

    val sqlContext = new SQLContext(sc)

    val url="jdbc:oracle:thin:@xxx.xxx.xx:1526:SIDNAME"

    val prop = new java.util.Properties

      prop.setProperty("user" , "usertst")
      prop.setProperty("password" , "usertst")

      val people = sqlContext.read.jdbc(url,"table_name",prop)

      people.show()

I checked my jar file, and it containst all dependencies. Can anybody help me how to solve this. Thank you!

A: So, the missing driver is the JDBC one and you have to add it to the SparkSQL configuration. You either do it in the application submit, as specified by this answer, or you do it through your Properties object, as you did, with this line:
prop.setProperty("driver", "oracle.jdbc.driver.OracleDriver")

A: Here is how you will connect to postgresql using spark.
SparkSession sparkSession = SparkSession.builder().
            appName("dky").
            master("local[*]").
            getOrCreate();

    Logger.getLogger("org.apache").setLevel(Level.WARN);

    Properties properties = new Properties();
    properties.put("user", "your user name");
    properties.put("password", "your password");

    Dataset<Row> jdbcDF = sparkSession.read().option("driver", "org.postgresql.Driver")
            .jdbc("jdbc:postgresql://localhost:5432/postgres", "your table name along with schema name", properties);
    jdbcDF.show();


text:
Q: ServiceStack - Error trying to resolve Service {X} or one of its autowired dependencies I am using servicestack and having problems with auto wiring.

Error trying to resolve Service '{Service}' or one of its autowired dependencies (see inner exception for details)

I don't need help figuring how exactly what the problem is. What I actually want is a way to see the inner exception. The inner exception should tell me the except problem without me having to figure it out but it not displayed in either the exception returned, or in the logs.
Setting DebugMode doesn't help either, it just includes the stack track of the topmost exception.
So basically, how do I stop servicestack from hiding the inner exception details?

A: I ran into this same issue and it ended up being that there was an exception being thrown inside of the constructor that I had created for the particular endpoint class. Example...
public class PartnerService : Service
{

    private PartnerManagementService _partnerManagementService;

    public PartnerService()
    {
        var configuration = new Configuration();
        _partnerManagementService = new PartnerManagementService(configuration);
    }

    public object Get(PartnerGet partner)
    {

        try
        {
            var partners = _partnerManagementService.getPartners();

            if (!partners.Any())
            {
                return new HttpError(HttpStatusCode.NotFound, "Partners Could not be found");
            }

            return partners;
        }
        catch (Exception e)
        {

            return new HttpError(HttpStatusCode.InternalServerError, e);
        }
    }

If it so happens that an exception is thrown inside of the constructor, ServiceStack will not be able to resolve the service or one of its dependencies, in this case that dependency being the constructor for the class.
If you put a try/catch in the constructor for the class you could get an exception that actually makes sense.

A: ServiceStack should already return the inner Exception, i.e. here's the source of the error:
private Exception CreateResolveException<TService>(Exception ex)
{
    var errMsg = "Error trying to resolve Service '{0}' or one of its autowired dependencies (see inner exception for details).".Fmt(typeof(TService).FullName);
    return new Exception(errMsg, ex);
}

Basically there was a problem with your IOC configuration and that one of the dependencies caused an error.
You can change ServiceStack to serialize the Inner Exception with:
SetConfig(new EndpointHostConfig {
    ReturnsInnerException = true,
});

But this already defaults to true.
So the exception should already contain the Inner Exception, are you referring to what Exception gets serialized or the exception thrown in code?

A: One option could be to grab the actual source code from Github and add it as a project to your solution, as opposed to using a compiled DLL, then you could step through the actual code and see exactly where the exception is raised and why.

A: I have exactly the same exception.
In my case, it happens once migrated to ServiceStack v4. With v3, all works perfectly.
IoC configuration
public class AppHost : AppHostBase
{
    public AppHost() : base("Northwind web services", typeof(CustomersService).Assembly)
    { }

    public override void Configure( Container container )
    {
        SetConfig(new HostConfig
        {
            DebugMode = true,
            ReturnsInnerException = true,
        });

        var dbFactory = new OrmLiteConnectionFactory("~/Northwind.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider);

        container.Register(dbFactory);

        // Dependencies
        container.RegisterAs<CustomerEntityRepository, ICustomerEntityRepository>();

        container.RegisterAutoWired<CustomersService>();

    }
}

Base class
public abstract class Repository<TEntity> : IRepository<TEntity> where TEntity : IEntity, new()
{

    protected IDbConnectionFactory dbFactory { get; set; }

    public Repository( IDbConnectionFactory factory )
    {
        dbFactory = factory;
    }
}

Inherited class
public class CustomerEntityRepository : Repository<CustomerEntity>, ICustomerEntityRepository
    {
        public CustomerEntityRepository( IDbConnectionFactory dbFactory )
            : base(dbFactory)
        {
        }
    }
}

Only solution I've found is:
container.RegisterAs<ICustomerEntityRepository>(c => new CustomerEntityRepository(dbFactury));

Here's full exception message returned http://pastebin.com/jJntNN5p


text:
Q: How can I retrieve the name of the printer chosen in Acrobat? I want to get the name of the printer chosen in Acrobat PrintDialog using SendMessage Windows API.
This is sample code.
static string GetWindowText( hwnd_printDialog_in_Acrobat )
{
    int comboBoxCount = 0;
    int HWND_PRINTER_NAME = 1 ;

    List<IntPtr> ChildPtrList = GetChildWindows(hwnd_printDialog_in_Acrobat);
    for( i=0 ;  i < ChildPtrList.Size(); i++)   {
        GetClassName( ChildPtrList[i], sClass, 100);
        if (sClass.ToString() == "ComboBox") {
            comboBoxCount++;
            if (comboBoxCount == HWND_PRINTER_NAME )   {
                 hwnd = ChildPtrList[i];
                 break;
            }
        }
    }
    ChildPtrList.Clear();

    int sSize ;
    sSize = SendMessageW( hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero )+1;
    StringBuilder  sbTitle = new StringBuilder( sSize );
    SendMessageW( hwn, WM_GETTEXT, (IntPtr)sSize, sbTitle);
    return (sbTitle.ToString());
}

The return value of sSize is 4;
The value of sbTitle.ToString() is "?-" etc.
The expected resu
What is wrong?

A: Here are my current guesses to your problem:

*

*HWND_PRINTER_NAME  is not 1

*The class name you are looking for is not "ComboBox"

*Problem in the code not listed:

*
*

*Grabbing the wrong parent window or treating the handle incorrectly

*
*

*SendMessageW DllImport is wrong, or parameters are treated incorrectly

You do have some bugs in the code listed so, my code isn't exactly the same, but here is the code I used to try to figure your problem.  I could not get it to behave the way you describe.  My code simply never finds a Child Window with the Class name "ComboBox".
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace PrinterChoosenInAcrobat
{
class Program
{
    public const uint WM_GETTEXTLENGTH = 0x000E;
    private const uint WM_GETTEXT = 0x000D;

    // External OS calls
    [DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
    public static extern bool SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
        StringBuilder lParam);

    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wparam,
        IntPtr lparam);

    [DllImport("User32.dll")]
    public static extern Int32 FindWindow(String lpClassName, String lpWindowName);

    [DllImport("user32.dll")]
    static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,
    int nMaxCount);

    static void Main(string[] args)
    {
        try
        {
            IntPtr windowHandle = (IntPtr)FindWindow("AcrobatSDIWindow", null);
            string text = GetWindowText(windowHandle);

            Console.WriteLine(text);

        }
        catch (Exception ex)
        {
            Console.Out.WriteLine(ex.Message);
        }

        // Don't close before I get to read the results
        Console.WriteLine();
        Console.WriteLine("Press Enter to quit.");
        Console.ReadLine();
    }

    static string GetWindowText(IntPtr hwnd_printDialog_in_Acrobat)
    {
        int comboBoxCount = 0;
        int HWND_PRINTER_NAME = 1;

        List<IntPtr> ChildPtrList = GetChildWindows(hwnd_printDialog_in_Acrobat);
        IntPtr hwnd = IntPtr.Zero;
        for (int i = 0; i < ChildPtrList.Count; i++)
        {
            StringBuilder sClass = new StringBuilder();
            GetClassName(ChildPtrList[i], sClass, 100);
            if (sClass.ToString() == "ComboBox")
            {
                comboBoxCount++;
                if (comboBoxCount == HWND_PRINTER_NAME)
                {
                    hwnd = ChildPtrList[i];
                    break;
                }
            }
        }
        ChildPtrList.Clear();

        int sSize;
        sSize = (int)SendMessage(hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1;

        StringBuilder sbTitle = new StringBuilder(sSize);
        SendMessage(hwnd, WM_GETTEXT, (IntPtr)sSize, sbTitle);
        return (sbTitle.ToString());
    }

    #region Code from http://pinvoke.net/default.aspx/user32/EnumChildWindows.html
    [DllImport("user32")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);

    /// <summary>
    /// Returns a list of child windows
    /// </summary>
    /// <param name="parent">Parent of the windows to return</param>
    /// <returns>List of child windows</returns>
    public static List<IntPtr> GetChildWindows(IntPtr parent)
    {
        List<IntPtr> result = new List<IntPtr>();
        GCHandle listHandle = GCHandle.Alloc(result);
        try
        {
            EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
            EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
        }
        finally
        {
            if (listHandle.IsAllocated)
                listHandle.Free();
        }
        return result;
    }

    /// <summary>
    /// Callback method to be used when enumerating windows.
    /// </summary>
    /// <param name="handle">Handle of the next window</param>
    /// <param name="pointer">Pointer to a GCHandle that holds a reference to the list to fill</param>
    /// <returns>True to continue the enumeration, false to bail</returns>
    private static bool EnumWindow(IntPtr handle, IntPtr pointer)
    {
        GCHandle gch = GCHandle.FromIntPtr(pointer);
        List<IntPtr> list = gch.Target as List<IntPtr>;
        if (list == null)
        {
            throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
        }
        list.Add(handle);
        //  You can modify this to check to see if you want to cancel the operation, then return a null here
        return true;
    }

    /// <summary>
    /// Delegate for the EnumChildWindows method
    /// </summary>
    /// <param name="hWnd">Window handle</param>
    /// <param name="parameter">Caller-defined variable; we use it for a pointer to our list</param>
    /// <returns>True to continue enumerating, false to bail.</returns>
    public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
    #endregion

}
}


text:
Q: Why can't get string with PIL and pytesseract? It is a simple Optical Character Recognition (OCR) program in Python 3 to get string, I have uploaded the target gif file here, please download it and save it as /tmp/target.gif.

try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('/tmp/target.gif')))

I paste all the error info here, please fix it to get the characters from image.
/usr/lib/python3/dist-packages/PIL/Image.py:925: UserWarning: Couldn't allocate palette entry for transparency
  "for transparency")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 309, in image_to_string
    }[output_type]()
  File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 308, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 208, in run_and_get_output
    temp_name, input_filename = save_image(image)
  File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 136, in save_image
    image.save(input_file_name, format=img_extension, **image.info)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1728, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python3/dist-packages/PIL/GifImagePlugin.py", line 407, in _save
    _get_local_header(fp, im, (0, 0), flags)
  File "/usr/lib/python3/dist-packages/PIL/GifImagePlugin.py", line 441, in _get_local_header
    transparency = int(transparency)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'

I convert it with convert command in bash.
convert  "/tmp/target.gif"   "/tmp/target.jpg"

I show  /tmp/target.gif and /tmp/target.jpg here.

Then execute the above python code again.
try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('/tmp/target.jpg')))

Nothing can i get with the pytesseract.image_to_string(Image.open('/tmp/target.jpg')),i get blank character.

For Trenton_M's code:
>>> img1 = remove_noise_and_smooth(r'/tmp/target.jpg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in remove_noise_and_smooth
AttributeError: 'NoneType' object has no attribute 'astype'
Thalish Sajeed

For Thalish Sajeed's code:

Omit the error info caused by print(pytesseract.image_to_string(Image.open(filename))).
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> import pytesseract
>>> import matplotlib.pyplot as plt
>>> import cv2
>>> import numpy as np
>>>
>>>
>>> def display_image(filename, length_box=60, width_box=30):
...     if type(filename) == np.ndarray:
...         image = filename
...     else:
...         image = cv2.imread(filename)
...     plt.figure(figsize=(length_box, width_box))
...     plt.imshow(image, cmap="gray")
...
>>>
>>> filename = r"/tmp/target.jpg"
>>> display_image(filename)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 7, in display_image
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 2699, in imshow
    None else {}), **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/__init__.py", line 1810, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_axes.py", line 5494, in imshow
    im.set_data(X)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/image.py", line 634, in set_data
    raise TypeError("Image data cannot be converted to float")
TypeError: Image data cannot be converted to float
>>>

@Thalish Sajeed,Why i got 9244K instead of 0244k with your code?
Here is my tested sample file.

The extracted string.

@Trenton_M,correct a little typo and loss in your code,and delete the line plt.show() as your suggestion.
>>> import cv2,pytesseract
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>>
>>> def image_smoothening(img):
...     ret1, th1 = cv2.threshold(img, 88, 255, cv2.THRESH_BINARY)
...     ret2, th2 = cv2.threshold(th1, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
...     blur = cv2.GaussianBlur(th2, (5, 5), 0)
...     ret3, th3 = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
...     return th3
...
>>>
>>> def remove_noise_and_smooth(file_name):
...     img = cv2.imread(file_name, 0)
...     filtered = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 41)
...     kernel = np.ones((1, 1), np.uint8)
...     opening = cv2.morphologyEx(filtered, cv2.MORPH_OPEN, kernel)
...     closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
...     img = image_smoothening(img)
...     or_image = cv2.bitwise_or(img, closing)
...     return or_image
...
>>>
>>> cv2_thresh_list = [cv2.THRESH_BINARY, cv2.THRESH_TRUNC, cv2.THRESH_TOZERO]
>>> fn = r'/tmp/target.jpg'
>>> img1 = remove_noise_and_smooth(fn)
>>> img2 = cv2.imread(fn, 0)
>>> for i, img in enumerate([img1, img2]):
...     img_type = {0: 'Preprocessed Images\n',
...                 1: '\nUnprocessed Images\n'}
...     print(img_type[i])
...     for item in cv2_thresh_list:
...         print('Thresh: {}'.format(str(item)))
...         _, thresh = cv2.threshold(img, 127, 255, item)
...         plt.imshow(thresh, 'gray')
...         f_name = '{0}.jpg'.format(str(item))
...         plt.savefig(f_name)
...         print('OCR Result: {}\n'.format(pytesseract.image_to_string(f_name)))

...
Preprocessed Images
In my console ,all the output info are as following:
Thresh: 0
<matplotlib.image.AxesImage object at 0x7fbc2519a6d8>
OCR Result: 10
15
20

Edfifi
10
2 o 30 40 so
so

Thresh: 2
<matplotlib.image.AxesImage object at 0x7fbc255e7eb8>
OCR Result: 10
15
20
Edfifi
10
2 o 30 40 so
so
Thresh: 3
<matplotlib.image.AxesImage object at 0x7fbc25452fd0>
OCR Result: 10
15
20
Edfifi
10
2 o 30 40 so
so
Unprocessed Images
Thresh: 0
<matplotlib.image.AxesImage object at 0x7fbc25464c88>
OCR Result: 10
15
20
Thresh: 2
<matplotlib.image.AxesImage object at 0x7fbc254520f0>
OCR Result: 10
15
2o
2o
30 40 50
Thresh: 3
<matplotlib.image.AxesImage object at 0x7fbc1e1968d0>
OCR Result: 10
15
20

Where is the string 0244R?

A: Let's start with the JPG image, because pytesseract has issues operating on GIF image formats. reference
filename = "/tmp/target.jpg"
image = cv2.imread(filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret, threshold = cv2.threshold(gray,55, 255, cv2.THRESH_BINARY)
print(pytesseract.image_to_string(threshold))

Let's try to breakdown the issues here.
Your image is too noisy for tesseract engine to identify the letters, We use some simple image processing techniques such as grayscaling and thresholding to remove some noise from the image.
Then when we send it to the OCR engine, we see that the letters are captured more accurately.
You can find my notebook where I tested this out if you follow this github link
Edit -
I have updated the notebook with some additional image cleaning techniques.
The source image is too noisy for tesseract to work directly out of the box on the image. You need to use image cleaning techniques.
You can vary the thresholding parameters or swap out gaussian blur for some other technique until you get your desired results.
If you are looking to run OCR on noisy images - please check out commercial OCR providers such as google-cloud-vision. They provide 1000 OCR calls free per month.

A: First: make certain you've installed the Tesseract program (not just the python package)
Jupyter Notebook of Solution: Only the image passed through remove_noise_and_smooth is successfully translated with OCR.
When attempting to convert image.gif, TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple' is generated.
Rename image.gif to image.jpg, the TypeError is generated
Open image.gif and 'save as' image.jpg, the output is blank, which means the text wasn't recognized.

from PIL import Image
import pytesseract

# If you don't have tesseract executable in your PATH, include the following:
# your path may be different than mine
pytesseract.pytesseract.tesseract_cmd = "C:/Program Files (x86)/Tesseract-OCR/tesseract.exe"

imgo = Image.open('0244R_clean.jpg')

print(pytesseract.image_to_string(imgo))

*

*No text is recognized from the original image, so it may require post-processing to clean prior to OCR

*I created a clean image, which pytesseract extracts the text from without issue.  The image is included below, so you can test it with your own code to verify functionality.

Add Post-Processing
Improve Accuracy of OCR using Image Preprocessing
OpenCV
import cv2
import numpy as np
import matplotlib.pyplot as plt

def image_smoothening(img):
    ret1, th1 = cv2.threshold(img, 88, 255, cv2.THRESH_BINARY)
    ret2, th2 = cv2.threshold(th1, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    blur = cv2.GaussianBlur(th2, (5, 5), 0)
    ret3, th3 = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    return th3

def remove_noise_and_smooth(file_name):
    img = cv2.imread(file_name, 0)
    filtered = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 41)
    kernel = np.ones((1, 1), np.uint8)
    opening = cv2.morphologyEx(filtered, cv2.MORPH_OPEN, kernel)
    closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
    img = image_smoothening(img)
    or_image = cv2.bitwise_or(img, closing)
    return or_image

cv2_thresh_list = [cv2.THRESH_BINARY, cv2.THRESH_TRUNC, cv2.THRESH_TOZERO]

fn = r'/tmp/target.jpg'
img1 = remove_noise_and_smooth(fn)
img2 = cv2.imread(fn, 0)
for i, img in enumerate([img1, img2]):
    img_type = {0: 'Preprocessed Images\n',
                1: '\nUnprocessed Images\n'}
    print(img_type[i])
    for item in cv2_thresh_list:
        print('Thresh: {}'.format(str(item)))
        _, thresh = cv2.threshold(img, 127, 255, item)
        plt.imshow(thresh, 'gray')
        f_name = '{}_{}.jpg'.format(i, str(item))
        plt.savefig(f_name)
        print('OCR Result: {}\n'.format(pytesseract.image_to_string(f_name)))

img1 will generate the following new images:

img2 will generate these new images:


text:
Q: What's the difference between SubscribeOn and ObserveOn I just discovered SubscribeOn, which makes me wonder if I should be using that instead of ObserveOn. Google took me here and here, but neither have helped me grok the difference: it seems incredibly subtle.
(In my context, I've got events 'coming up' on a non-gui thread, and I need to switch over to a gui thread before using the event data to update controls).

A: It helped me to understand this by thinking of SubscribeOn as setting the thread being "passed up" the chain and ObserveOn as setting the thread "passed down" the chain.

The code below uses named threads which you can play with.
Thread.CurrentThread.Name = "Main";

IScheduler thread1 = new NewThreadScheduler(x => new Thread(x) { Name = "Thread1" });
IScheduler thread2 = new NewThreadScheduler(x => new Thread(x) { Name = "Thread2" });

Observable.Create<int>(o =>
{
    Console.WriteLine("Subscribing on " + Thread.CurrentThread.Name);
    o.OnNext(1);
    return Disposable.Create(() => {});
})
.SubscribeOn(thread1)
.ObserveOn(thread2)
.Subscribe(x => Console.WriteLine("Observing '" + x + "' on " + Thread.CurrentThread.Name));

The output of the above is:
Subscribing on Thread1
 Observing 1 on Thread2
It's also interesting to see that when you comment out the SubscribeOn line, the output is:
Subscribing on Main
 Observing 1 on Thread2
Because by default the subscription "passes up" whichever thread was running (Main here). Then the ObserveOn "passes down" Thread2.
If you instead comment out the ObserveOn line, the output is:
Subscribing on Thread1
 Observing 1 on Thread1
Because we "pass up" the subscription on Thread1, and by default this same thread is "passed down" and used to run the observation.
In a GUI context, to keep things responsive you want the least amount of work done on the GUI thread but you need the subscription done on the GUI thread (to synchronise UI updates). So you want to .ObserveOn the GUI thread.

A: I had a similar problem a while back and asked this question about it. I think the responses (including the comments) there will answer your question. To summarize:

*

*If you want to update controls on a gui thread, use ObserveOn. If you reference System.Reactive.Windows.Forms.dll you get the .ObserveOn(form) which is handy.

*SubscribeOn controls the thread on which the actual call to subscribe happens. The problem solved here is that WinForms and WPF will throw exceptions if you add event handlers from multiple different threads.

Also, this post was very helpful in figuring out the relationship between ObserveOn and SubscribeOn.

A: The differences basically is that subscribeOn force the whole pipeline to be processed by another thread, but with observerOn only the steps in your pipeline define after observerOn will run in another thread only after you set it will be executed in another thread.
    Observable.just(1)
              .map ---> executed in io thread
              .filter ---> executed in io thread
              .subscribeOn(Scheduers.io)
              .subscribe()

All the steps of the pipeline will be executed in another thread.
 Observable.just(1)
              .map ---> executed in Main thread
              .filter ---> executed in Main thread
              .observerOn(Scheduers.io)
              .map ---> executed in New thread
              .filter ---> executed in New thread
              .subscribe()


text:
Q: How to display difference between two points from two different glyphs in Bokeh using HoverTool? I have two lines in a plot and I want to displace the difference of each pair of points on hover using HoverTool.
I tried '@y' - '@yhat', float('@y') - float('@yhat'), @y - @yhat, but nothing worked.

A: This could be arranged with a JS callback on the HoverTool like this (Bokeh v1.1.0):
from bokeh.plotting import figure, show
from bokeh.models import CustomJS, HoverTool, ColumnDataSource

p = figure()
l1 = p.line([1, 2, 3, 4, 5], [14, 16, 11, 12, 17], color = 'green')
l2 = p.line([1, 2, 3, 4, 5], [15, 10, 19, 18, 13], color = 'red')

code = '''  var index = cb_data.index['0d'].indices[0];
            if (index != null){
                v1 = String(l1.data_source.data['y'][index]);
                v2 = String(l2.data_source.data['y'][index]);
                diff = String(v1 - v2);
                hover.tooltips = [["x", "@x"], ["y1", v1], ["y2", v2], ["diff", diff]];
            } '''
hover = HoverTool(mode = 'vline', line_policy = 'prev', point_policy = 'snap_to_data', renderers = [l1])
hover.callback = CustomJS(args = dict(l1 = l1, l2 = l2, hover = hover), code = code)
p.add_tools(hover)

show(p)

Result:


text: Q: Sharepoint 2013 Timer Service extremely high CPU usage We are running a sharepoint 2013 on our server and it uses extreme high cpu every now and then. The only way to get rid of it so far is by restarting the service. However this is of course not feasable. can anyone help me figure out what i can do to fix this...


text:
Q: What is -lnuma and what program uses it for compilation? I am compiling a message passing program using openmpi with mpicxx on a Linux desktop. My makefile does the following:
mpicxx -c readinp.cpp
mpicxx -o exp_fit driver.cpp readinp.o

at which point i get the following error:
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: cannot find -lnuma

My questions are:
what is -lnuma? what is using it? how should i go about linking to it?

A: Thanks Jonathan Dursi!
On Ubuntu, the package name is libnuma-dev.
apt-get install libnuma-dev

A: The build script can't find the numa library - NUMA (Non Uniform Memory Access). The -l option tells the linker to link the library, but your system ether doesn't have the right one installed or your search path for the linker is incomplete/wrong.
Try querying your package-manager (apt or rpm) for a package libnuma.

A: OpenMPI, and I think mpich2, uses libnuma (`a simple programming interface to the NUMA (Non Uniform Memory Access) policy supported by the Linux kernel') for memory affinity -- to ensure that the memory for a particular MPI task stays close to the core that the task is running on, as vs. being kept in cache on another socket entirely.    This is important for performance on multicore nodes.
You may need to use YaST to install libnuma-devel if your linker can't find the library.

A: I got the same error working on a remote server, which had the NUMA library installed. In particular, the file /usr/lib64/libnuma.so.1 existed. It appears that the linker only looked for the file under the name libnuma.so. Creating the symlink
ln -s /usr/lib64/libnuma.so.1 /usr/lib64/libnuma.so

as described here might have worked, but in my case I did not have permission to create files in /usr/lib64. I got around this by creating the symlink in some other location of which I have write permission:
ln -s /usr/lib64/libnuma.so.1 /some/path/libnuma.so

and then add this path to the compilation flags. In your case this would be
mpicxx -L/some/path -o exp_fit driver.cpp readinp.o

In my case of a larger build process (compiling fftw), I added the path to the LDFLAGS environment variable,
export LDFLAGS="${LDFLAGS} -L/some/path"

which fixed the issue.


text:
Q: How to read and parse an XML file only once on first page load instead of on each page request I must not understand it well enough.
I have created a static class like this:
public static class oDs
{
    public static DataSet columnsxml
    {
        get
        {
            DataSet oDs = new DataSet();
            oDs.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/Columns.xml"));
            return oDs;
        }

    }
}

which is used in the Page_Load class like this:
foreach (DataRow row in oDs.columnsxml.Tables[0].AsEnumerable())
{
    MyCode()
}

My expectation was that since I made class oDs static, it wouldn't keep reading the XML file on every single page request, but that turns out to be false. If I make changes to the XML during runtime, the next page request will have the updated info. I am concerned about the performance impact of this.
Do I have to also do the MyCode() in the static class?
Edit: I am aware of Enterprise Library, but would prefer to do it without that caching.

A: Everything depends on your goal. If the content of the file is static, meaning it is not changed during your application lifecycle, then you can change your static class a little bit this way:
public static class oDs
{
    private static DataSet _oDs;

    public static DataSet columnsxml
    {
        get
        {
            if (_oDs == null)
            {
                _oDs = new DataSet();
                _oDs.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/Columns.xml"));
            }
            return _oDs;
        }

    }
}

Please, be aware that this code is not tread-safe, so you'll probably want to add a lock there.
The other choice would be to use the Application_Start event in Global.asax to load the file content upon application startup.


text:
Q: Adding reccuring events in google calendar with time I need to add recurring events with start time and end time. I used the code like
$recurrence = "DTSTART;VALUE=DATE:{$start}\r\n" .
            "DTEND;VALUE=DATE:{$start2}\r\n" .
            "RRULE:FREQ=WEEKLY;BYDAY={$dtString};UNTIL={$end}\r\n";

Where $start = '20120601', $end = '20120630', $dtString = 'Fr'
i need to add events which start from 08:00 to 09:00 which repeat every Friday. Please help me to find-out a solution
Regards,
NisanthKumar

A: Send you a page to help you.
https://developers.google.com/google-apps/calendar/recurringevents
Mauricio.


text:
Q: How to export property of a interface/Object like Javascript in TypeScript As we known, the commonJS module's exports is a JS Object commonly. We can access the specific method easily like const { methodA } = require('module').
How can we impl the .d.ts(types declaration file), allowing the typescript user to enjoy the similar import experience?
We hope to do like that:
// JavaScript
const sdk = require('module')
sdk.methodA(params)
// Or
const { methodA } = require('module')
methodA(params)

// Typescript also can be:
import sdk from 'module'
sdk.methodA(params)
// Or
import { methodA } from 'module'
methodA(params)

That is my current impl:
export * from './interface' // a .d.ts file that includes all interface, is it necessnary exported to users?
interface Instance {
  methodA: (params: anthorInterface) => Promise<ResponseInterface>
}
declare const sdk: Instance
export default sdk

But the syntax import { methodA } from 'method' doesn't work, though, the default behavior works fine.
Could you give me any suggestions? Thank you a lot.


text:
Q: spring:mvcUrl mapping wrong id I am trying to map productId to URL in my jsp page, but the value is wrong.
The URL is returning Título 1 but the response is returning the right value:
HTML Mapping
My jsp code:
    <%@ page language="java" contentType="text/html; charset=iso-8859-1" pageEncoding="iso-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <!DOCTYPE html>

    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
    <title>Insert title here</title>

            ${success}

                Id
                Titulo
                Valores

    <c:forEach items="${products}" var="product">

            ${product.id}
            ${product.title}

                <c:forEach items="${product.prices}" var="price">
                    [${price.value} - ${price.bookType}]
                </c:forEach>

    </c:forEach>

My Java Controller Code:
    @RequestMapping(method=RequestMethod.GET)
public ModelAndView list() {
    ModelAndView modelAndView = new ModelAndView("products/list");
    modelAndView.addObject("products", productDAO.list());
    return modelAndView;
}

My Java DAO Code:
    public List<Product> list() {
    return manager.createQuery("select distinct(p) from Product p join fetch p.prices", Product.class).getResultList();
}

A: Unfortunately I cannot see your method 'show'.
I guess you have a misprint in the path:
@RequestMapping("/show{/id}")
//--------------------^^  WRONG
public String show(@PathVariable("id") long id) {
    ...
}

instead
@RequestMapping("/show/{id}")
//--------------------^^  RIGHT


text:
Q: How to ensure Reactive Stream completes with Spring WebFlux and WebSockets I have written a test client and server for Spring WebFlux in Kotlin. The client sends a number to the server (e.g. 4) and gets back that many numbers (e.g. 0, 1, 2 and 3). Here is the server implementation:
class NumbersWebSocketHandler : WebSocketHandler {
    override fun handle(session: WebSocketSession): Mono<Void> {
        var index = 0
        var count = 1
        val publisher = Flux.generate<Int> { sink ->
            if (index < count) {
                sink.next(index)
                index++
            } else {
                sink.complete()
            }
        }.map(Int::toString)
            .map(session::textMessage)
            .delayElements(Duration.ofMillis(500))

        return session.receive()
            .map(WebSocketMessage::getPayloadAsText)
            .doOnNext {
                println("About to send $it numbers")
                count = it.toInt()
            }
            .then()
            .and(session.send(publisher))
            .then()
    }
}

And here is the client:
fun main(args: Array<String>) {
    val uri = URI("ws://localhost:8080/numbers")
    val client = ReactorNettyWebSocketClient()

    println("How many numbers would you like?")
    val input = Flux.just(readLine())

    client.execute(uri) { session ->
        session.send(input.map(session::textMessage))
            .then(
                session.receive()
                    .map(WebSocketMessage::getPayloadAsText)
                    .map { it.toInt() }
                    .reduce { a,b ->
                        println("Reduce called with $a and $b")
                        a + b
                    }
                    .doOnNext(::println)
                    .then()
            )
            .then()
    }.block()
}

The client successfully receives the numbers and reduce is invoked as below:

Reduce called with 0 and 1
Reduce called with 1 and 2
Reduce called with 3 and 3

However the call to doOnNext is never reached - presumably because the client is unaware that the last item has been sent. My question is what code do I need to add, on either client or server, for the total to be printed?
UPDATE: Closing the session on the server side does not help. I have tried:
.delayElements(Duration.ofMillis(500))
.doOnComplete { session.close() }

And also:
.delayElements(Duration.ofMillis(500))
.doFinally { session.close() }

But neither have any affect on the behaviour of the client. Neither does trying to close the session explicitly after the call to 'send':
.and(session.send(publisher))
.then()
.and { session.close() }
.then()

A: The Mono<Void> returned from a WebSocketHandler indicates when handling is complete, that in turn indicates how long the WebSocket connection should remain open. The problem is that on both sides the Mono<Void> returned will never complete.
The client uses reduce which waits for the end of input from the server side, but the server uses receive() + doOnNext + then() which waits to receive messages forever. So client and server both wait for each other. Adding take on the client side helps to break the stalemate:
client.execute(uri, session -> session
        .send(input.map(session::textMessage))
        .then(session.receive()
                .map(WebSocketMessage::getPayloadAsText)
                .map(Integer::valueOf)
                .take(3)
                .reduce((a,b) -> {
                    logger.debug("Reduce called with " + a + " and " + b);
                    return a + b;
                })
                .doOnNext(logger::debug)
        )
        .then()
).block();

The second issue is that the server is incorrectly composed. The sending is triggered in parallel with receiving via .and. Instead the sending stream should depend on receiving the count first:
session.receive()
        .map(WebSocketMessage::getPayloadAsText)
        .flatMap(s -> {
            logger.debug("About to send " + s + " numbers");
            count.set(Integer.parseInt(s));
            return session.send(publisher);
        })
        .then()

A: As can be seen from the marble diagram for reduce, it expects the upstream publisher to send an onComplete event to emit an event itself. I am not sure but I think that's emitted only when the connection is terminated gracefully. That's why the doOnNext is never executed.
Instead of reduce I think you should use the subscribe() instead, and define your own Subscriber instance where you could keep the state.
EDIT: You can't use a subscribe method here. Though it should work like this if the connection is closed on server:
.map(Int::toString)
        .map(session::textMessage)
        .delayElements(Duration.ofMillis(500))
        .then(session::close)