dimanche 24 décembre 2017

Trouble with setting webpack

How to tune webpack so that pug file dont compile into HTML and parse src img? if i use:

{
    loader: 'html-loader'
},
{
    loader: 'pug-html-loader',
    options: {
        pretty: true,
        exports: false
    }
} 

this work but output HTML




Click all buttons containing certain text on page with JQuery

I'm making a chrome extension, and basically id like to be able to pass it a certain word - like "Dog" and then it will click on every instance of "Dog" on the page. It should have a small time limit between each click. How would I do this? Whenever I've attempted this before I haven't been able to get it to work.




Embed simple interactive data visualisation in website (Bokeh? Other platforms?)

I've built quite a few data visualisation tools using Python before, relying on the desktop-based GUI tools for user interaction (e.g. Qt), but am now trying to make something more widely accessible in the form of a website.

I'm afraid I have limited web development experience however, and wonder if anyone could recommend platforms / techniques to consider for this project please?

My target is a simple website with a drop-down menu. When the user makes a selection from the drop-down, the relevant data is loaded from a .txt file on the web server and plotted within the website. Having access to tools to zoom and a cursor to indicate the data at mouse position are valuable.

In the future I'd like to extend this to add more complicated features (e.g. user input box, with plotting code executed depending on the input), but for now, achieving the simple case above would be great.

I've found positive comments about Bokeh online, which looks good and seems to support Python code. However, while the examples show me how to plot a single case, I can't work out how to make a drop-down menu in a website that dynamically updates the plotted data.

I aim for the code to be fast, and potentially accesses by numerous web users. If other better options than Bokeh are available, I'm very open to any suggestions or thoughts.

Many thanks




Keep getting the same error code (bad request) when trying to retrieve a page using sockets

I was trying to get a web page using Socket and get request but I keep getting the same error - bad request, for any website or webpage i try to use it.

    Socket s = new Socket("horstmann.com", 80);

    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();

    Scanner reader = new Scanner(in);
    PrintWriter writer = new PrintWriter(out, false);

    String command = "GET / HTTP/1.0\n\n";
    //System.out.print(command);
    writer.print(command);
    writer.flush();

    while (reader.hasNextLine()) {
        System.out.println(reader.nextLine());
    }
    s.close();




samedi 23 décembre 2017

Spotify node web api - trouble with multiple users

I am working on an app that uses Spotify Node web API and having trouble when multiple users login into my application. I am successfully able to go through authentication flow and get the tokens and user ID after a user logs in. I am using the Authorization Code to authorize user (since I would like to get refresh tokens after expiration). However, the current problem is that getUserPlaylists function described here (FYI, if the first argument is undefined, it will return the playlists of the authenticated user) returns playlists of the most recently authenticated user instead of the user currently using the app.

Example 1: if user A logins in to the application, it will get its playlists fine. If user B logins in to the application, it also sees its own playlists. BUT, if user A refreshes the page, user A sees the playlists of the user B (instead of its own, user A playlists).

Example 2: user A logs in, user B can see user A's playlists just by going to the app/myplaylists route.

My guess is, the problem is with this section of the code

    spotifyApi.setAccessToken(access_token);
    spotifyApi.setRefreshToken(refresh_token);

The latest user tokens override whatever user was before it and hence the previous user is losing grants to do actions such as viewing its own playlists.

  • Expected behavior: user A sees own playlists after user B logs in after refreshing the page.
  • Actual behavior: user A sees user B's playlists after user B logged in and user A refreshes the page.

I am aware that I could use the tokens without using the Spotify Node API and just use the tokens to make request and it should probably be fine, however, it would be great to still be able to use the node API and still be able to handle multiple users.

Here is the portion of code that most likely has problems:

export const createAuthorizeURL = (
     scopes = SCOPE_LIST,
    state = 'spotify-auth'
) => {
    const authUrl = spotifyApi.createAuthorizeURL(scopes, state);

    return {
        authUrl,
        ...arguments
    };
};

export async function authorizationCodeGrant(code) {
    let params = {
    clientAppURL: `${APP_CLIENT_URL || DEV_HOST}/app`
};

    try {
        const payload = await spotifyApi.authorizationCodeGrant(code);
        const { body: { expires_in, access_token, refresh_token } } = payload;

        spotifyApi.setAccessToken(access_token);
        spotifyApi.setRefreshToken(refresh_token);

        params['accessToken'] = access_token;
        params['refreshToken'] = refresh_token;

        return params;
    } catch (error) {
        return error;
    }

    return params;
}

export async function getMyPlaylists(options = {}) {
    try {
        // if undefined, should return currently authenticated user
        return await spotifyApi.getUserPlaylists(undefined, options);
    } catch (error) {
         return error;
    }
}

Would appreciate any help on this. I am really excited about what I am making so it would mean a LOT if someone could help me find the issue...




Javascript add class to classList don't add. Used in Django web development framework

We have a form in which we want all input areas with faulty submitted data to gain red borders. This is done by setting the class of the input tag to "form-control-danger" in addition to the original class "form-control". The HTML/JS/Django code looks like this, and it is mostly correct. I have controlled that the scripts tags are only generated and run when faulty data is submitted.

<!-- Output all fields -->
 

As we feed the form faulty data this gives us this source code.

<div class="input-group form-group-no-border">
    <span class="input-group-addon">
        <i class="now-ui-icons



             ui-1_lock-circle-open
        "></i>
    </span>
    <input type="password" name="password2" value="iuhqeifuhweifuhweifuwefw" id="id_password2" required placeholder="Password again..." class="form-control" />

    <!-- Give input box red border if data is not valid -->

        <script>
            alert("Before");
            var element = document.getElementById("id_password2");
            element.classList.add("form-control-danger");
            alert("Done");
        </script>

</div>

Observe that the class of the input tag with id of "id_password2" is unchanged, despite the javascript seeming correct, my javascript skills could however be considered questionable. All help is appreciated.

Merry Christmas




How to fix webbrowser control MessageBox pop up

I was making a simple winform to log in to a website but when I do that a MessageBox appears. IDK what is the problem is there any way to fix that or just click on the ok button before it popups or something like that. Thank you. This is the error.