#StackBounty: #javascript #android #ios #react-native react-native `keyboardShouldPersistPanGesture` event that prevents the keyboard f…

Bounty: 50

I am building a keyboard accessory component where there will be a scroll through option above the keyboard, very similar to Twitter’s keyboard. My view hiearchy is:

<InputAccessoryView>
    <View style={myStyle}>
        <ScrollView horizontal={true} keyboardShouldPersistTaps={'always'}
           {[...Array(n).keys()].map(uid => this.renderBubble(uid) })}
        </ScrollView>
   </View>
</InputAccessoryView>

By putting keyboardShouldPersistTaps as always, I can make sure the press event does not dismiss the keyboard. However when I scroll through the items in ScrollView, the keyboard dismisses if I scroll too quickly, the keyboard does not dismiss if I scroll slowly. The docs here: https://facebook.github.io/react-native/docs/gesture-responder-system and here: https://facebook.github.io/react-native/docs/scrollview#onmomentumscrollbegin do not give me a way to capture a long pan event. Is there an API to do this so I scroll through the ScrollView items as fast as I want, and the keyboard will not dismiss?


Get this bounty!!!

#StackBounty: #javascript #node.js #angular #typescript error on encoding large file on nodejs side after sending file from angular-side

Bounty: 50

I am getting the file on server side as console.log(body)

{ fieldname: 'image',
  originalname: '21329726_1866651723650020_188839340_o.jpg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  destination: './pics/',
  filename: '5146c9818ff517c426e34ad84ff3513f',
  path: 'pics/5146c9818ff517c426e34ad84ff3513f',
  size: 94093 
}

and then encoding by const base64Data = body.buffer.toString("base64")

but for small size file it works well ,But for large file it creates problem, It is not encoding properly.

I think the problem is due to, it starts encoding before it receives the full file.

Please give me some proper way to do this.

This is my github link click here


Get this bounty!!!

#StackBounty: #javascript #html #iframe #safari #contenteditable iframe Undo/Redo for execCommand using insertHTML (contenteditable)

Bounty: 100

So, currently I am working on a small button that asks the user to type the link for a video and then I am taking that link and making it into an iframe and inserting it into a contenteditable using document.execCommand("insertHTML", false, "'>"). This works great and the video gets embedded into the contenteditable.

The only problem is that if I do Command+Z or press undo in Safari, the iframe won’t get undone for some reason. It works in Firefox, Chrome, Edge, and Opera, but for some reason I think safari doesn’t understand how to undo it.

Is there any workaround for this other than implementing my own undo/redo stack? I just want to be able to get rid of the iframe when the user chooses to undo in safari as well and add it back when the user chooses to redo. Please help and thanks in advance.

EDIT:

Here’s a JS fiddle to demonstrate what I’m talking about. If you run this in any browser except Safari and press undo, it works. But not in Safari.
http://jsfiddle.net/qg41pd3k/9/


Get this bounty!!!

#StackBounty: #sharepoint-foundation #javascript #sharepoint-online #rest How to authenticate user in SharePoint Online using rest api

Bounty: 50

I have a website on SharePoint Online and a website on SharePoint On-premise. From my On-premise website i want to create a new list on my SharePoint Online site.

To authenticate I used the following codes:


    var soapRequest =
     '<?xml version="1.0" encoding="utf-8"?>
      <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
      <soap12:Body>  
         <Login xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <username>username@email.com</username>
            <password>userpassword</password>
         </Login>
      </soap12:Body>
     </soap12:Envelope>';
 

And then:


    $.ajax({ 
          url: myUrl + "_vti_bin/authentication.asmx?op=Login",
          type: "GET",  
          contentType: "text/xml",  
          dataType: "json", 
          data: soapRequest, 
          success: function (a) {
               console.log(a);
          },
          error: function (a) {
              console.log(a);
          }
    });

As result I get:

XMLHttpRequest cannot load https://myUrl/_vti_bin/authenti…in3!%22%3C/password%3E%3C/Login%3E%3C/soap12:Body%3E%3C/soap12:Envelope%3E. The request was redirected tohttps://myUrl/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E‘, which is disallowed for cross-origin requests that require preflight.

What can I do to avoid the error?

Thank you very much.


Get this bounty!!!

#StackBounty: #javascript #jquery #stackexchange #userscript Tampermonkey script to beautify related tags in Stack Exchange

Bounty: 50

I’ve got the following code which is ran inside tampermonkey (It’s a userscript), but there is a variable that is being declared, used, then overwritten by the next line. I’m looking for a way to shorten this code, or possibly remove the line if I can get the same results another way.

$(function() {
        /***** RELATED TAGS *****/
        var oldtags = main_content.find('div#related-tags, .module.js-gps-related-tags');
        var vctags = genSBWidget('Related Tags', '<svg aria-hidden="true" class="svg-icon" width="18" height="18" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"></path></svg>', 'relatedtags');

        oldtags.before(vctags).children('h4, a').remove().parent();

        vctags = main_content.find('div#visualcrumbs-relatedtags'); //THIS LINE

        vctags.prepend(oldtags.children()).children().wrapAll('
').each(function() { $(this).toggleClass('dno js-hidden js-tag grid--cell').children().slice(1).remove(); }); });

genSBWidget simply generates some HTML, not sure if this is really relevant but I’ll post the function anyways:

function genSBWidget(title, icon, innerid) {
        var widget = '
        
'+ icon +' ' + title + '
</div> '; return widget; }

Side not: This script just takes “Related tags” in the right sidebar of stackoverflow and puts it into one of the new style boxes in the sidebar, and gives it the same styling as Watched Tags.

My actual userscript works on more than just related tags, it converts everything in the sidebar into this new style box, what I’m hoping to do from this question is learn some new methods of doing what I’m trying to do with related tags, so I can expand this accross my entire script.

Here is a minimal example of the script:

// ==UserScript==
// @name         Related Tags Beautifier
// @namespace    https://github.com/GrumpyCrouton/Userscripts
// @version      1.0
// @description  Customizes StackExchange to your liking.
// @author       GrumpyCrouton
// @match          *://*.stackoverflow.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var $ = window.jQuery;

    /***** GLOBAL SITE CHANGES *****/
    var main_content = $('body div.container').find('div#content');

    $(function() {
        /***** RELATED TAGS *****/
        var oldtags = main_content.find('div#related-tags, .module.js-gps-related-tags');
        var vctags = genSBWidget('Related Tags', '<svg aria-hidden="true" class="svg-icon" width="18" height="18" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"></path></svg>', 'relatedtags');

        oldtags.before(vctags).children('h4, a').remove().parent();
        vctags = main_content.find('div#visualcrumbs-relatedtags');
        vctags.prepend(oldtags.children()).children().wrapAll('
').each(function() { $(this).toggleClass('dno js-hidden js-tag grid--cell').children().slice(1).remove(); }); }); function genSBWidget(title, icon, innerid) { var widget = '
'+ icon +' ' + title + '
</div> '; return widget; } })();


Get this bounty!!!

#StackBounty: #javascript #r #web-scraping #rvest #rselenium scraping asp javascript paginated tables behind search with R

Bounty: 500

i’m trying to pull the content on https://www.askebsa.dol.gov/epds/default.asp with either rvest or RSelenium but not finding guidance when the javascript page begins with a search box? it’d be great to just get all of this content into a simple CSV file.

after that, pulling the data from individual filings like https://www.askebsa.dol.gov/mewaview/View/Index/6219 seems possible.. but i’d also appreciate a clean recommendation to do that. thanks


Get this bounty!!!

#StackBounty: #javascript #google-chrome-extension #proxy Changing credentials to a proxy server on fly

Bounty: 50

I’m developing an extension for chrome. The extension allow to pick any proxy server from a list each proxy is required authorization. There is an issue when a user would like to connect to the same proxy server twice but with different credentials for example if a user was successfully logged it in the first time the chome remebers it and when the user whould try to connect with another credentails the chrome whould use credentilas that was inputed in the first login.

var authCredentials = {
  username: 'Jack',
  password: 'PassForJack'
}

var auth = function () {
    return {
       authCredentials
    };
};


chrome.webRequest.onAuthRequired.addListener(auth, {
   urls: ["<all_urls>"]
 }, ["blocking"]);

// set a new proxy server for the first login
chrome.proxy.settings.set({
  value: {
      mode: 'fixed_servers',
      rules: {
        singleProxy: {
            host: 'some-proxy-server.com',
            port: 8000
        }
    }
  },
  scope: 'regular'
});


// change credentails 
authCredentials = {
  username: 'Bob',
  password: 'PassForBob'
};

// remove proxy configuration
chrome.proxy.settings.set({
  value: {
    mode: 'direct'
  },
  scope: 'regular'
});

// remove onAuthListener
chrome.webRequest.onAuthRequired.removeListener(auth)
chrome.webRequest.onAuthRequired.hasListener(auth) // returns false

chrome.webRequest.onAuthRequired.addListener(auth, {
   urls: ["<all_urls>"]
 }, ["blocking"]);

// lets re connect 
chrome.proxy.settings.set({
  value: {
    mode: 'fixed_servers',
    rules: {
        singleProxy: {
            host: 'some-proxy-server.com',
            port: 8000
        }
    }
  },
  scope: 'regular'
});

// that doesn't help the user would be loged as "Jack" but has to be as "Bob"


Get this bounty!!!

#StackBounty: #javascript #angular #typescript #asp.net-core #apollo Unexpected token { syntax error

Bounty: 50

(Complete ASP.Net Core + Angular Universal code at https://github.com/jonasarcangel/ModuleIssue)

I’m getting the following error from my prerendered SPA using Angular Universal when using “dotnet run” and navigating to any route. It does not happen when I run in ClientApp folder using “npm run build:ssr && npm run start”.

Request starting HTTP/1.1 GET https://localhost:5001/account/login  
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
    Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: /Workspace/ModuleIssue/ClientApp/node_modules/apollo-angular/ApolloModule.js:1
    (function (exports, require, module, __filename, __dirname) { import { NgModule } from '@angular/core';
                                                                         ^
SyntaxError: Unexpected token {
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
Current directory is: /Workspace/ModuleIssue

   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.InvokeExportAsync[T](NodeInvocationInfo invocationInfo, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.InvokeExportAsync[T](CancellationToken cancellationToken, String moduleName, String exportNameOrNull, Object[] args)
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.InvokeExportWithPossibleRetryAsync[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.InvokeExportWithPossibleRetryAsync[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Builder.SpaPrerenderingExtensions.<>c__DisplayClass0_0.<<UseSpaPrerendering>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

This is what I have for tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom",
      "esnext"
    ]
  }
}

This is what I have in package.json:

{
  "name": "ModuleIssue",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server",
    "build:client-and-server-bundles": "ng build --prod && ng run ModuleIssue:server",
    "webpack:server": "webpack --config webpack.server.config.js --progress --colors",
    "ssr": "npm run build:universal && npm run generate:prerender && npm run server",
    "ssr:debug": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true  && ng run ModuleIssue:server:dev && webpack && node server.js",
    "ssr:cw": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true --watch",
    "ssr:sw": "ng run MyProject:server:dev --watch",
    "ssr:webpack": "webpack --watch",
    "ssr:server": "nodemon server.js",
    "build:server": "ng run ModuleIssue:server:production",
    "build:prod": "ng build --prod",
    "build:universal": "ng build --prod && ng run ModuleIssue:server:production && webpack --config webpack.server.config.js --progress --colors",
    "server": "node server.js",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:prerender": "npm run build:universal && npm run generate:prerender",
    "generate:prerender": "node prerender.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/platform-server": "^6.0.0",
    "@angular/router": "^6.0.0",
    "@ng-bootstrap/ng-bootstrap": "^2.2.2",
    "@nguniversal/express-engine": "^6.0.0",
    "@nguniversal/module-map-ngfactory-loader": "^6.0.0",
    "apollo-angular": "^1.1.2",
    "apollo-angular-link-http": "^1.1.1",
    "apollo-cache-inmemory": "^1.2.7",
    "apollo-client": "^2.3.8",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.0.0",
    "core-js": "^2.4.1",
    "graphql": "^0.11.0",
    "graphql-tag": "^2.9.2",
    "primeicons": "^1.0.0-beta.10",
    "primeng": "^6.1.0",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.0.0-rc.0",
    "ts-loader": "^4.4.2",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.6.0",
    "@angular/cli": "^6.0.0",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/language-service": "^6.0.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~8.0.30",
    "codelyzer": "^4.0.2",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.9.2",
    "uglifyjs-webpack-plugin": "^1.2.7"
  }
}


Get this bounty!!!

#StackBounty: #javascript #performance #comparative-review #combinatorics n choose k combination in JavaScript

Bounty: 50

I was asked to solve a problem for $binom{n}{k}$. I did the following implementation and am wondering if there’s any feedback.

Input:

n = Integer

k = Integer

Output:

result = Array of arrays of integers

Constraints:

Time: $O(binom{n}{k})$

Space: $O(binom{n}{k})$

The order of the output array DOES NOT MATTER.

n and k are both positive.

Resources:

N Choose K

Combinations

function combinations(n, k) {
    let result= [];

  function recurse(start, combos) {
    if(combos.length === k) {
      return result.push(combos.slice());
    }
        // Check if you can actually create a combo of valid length
        // given current start number
        // For example: 5 choose 4 can't begin with [3] since it would never have 4 numbers
    if(combos.length + (n - start + 1) < k){
      return;
    }
    recurse(start + 1, combos);
    combos.push(start);
    recurse(start + 1, combos);
    combos.pop();
  }

  recurse(1, []);
  return result;
}

I was wondering if there’s a reason why the time gets optimized using a backtracking solution.

// function combinations(n, k) {
//   let result = []
//   function combine(combo, currentNumber){
//     if(combo.length === k) {
//       result.push(combo);
//       return;
//     }
//     if(currentNumber > n) {
//       return;
//     }

//     let newCombo1 = combo.slice();
//     let newCombo2 = combo.slice();
//     newCombo2.push(currentNumber);

//     combine(newCombo2, currentNumber + 1);  
//     combine(newCombo1, currentNumber + 1);


//   }
//   combine([], 1);
//   return result;
// }

// speed: 1120.756 ms

//backtracking method
function combinations(n, k) {
  let result = []
  let stack = []
  function combine(currentNumber){
    if(stack.length === k) {
      let newCombo = stack.slice()
      result.push(newCombo);
      return;
    }
    if(currentNumber > n) {
      return;
    }

    stack.push(currentNumber)
    combine(currentNumber + 1);  
    stack.pop();
    combine(currentNumber + 1);
  }
  combine(1);
  return result;
}

console.time("Naive Combinations")
console.log(combinations(20, 10))
console.timeEnd("Naive Combinations")

// speed: 320.756 ms


Get this bounty!!!

#StackBounty: #javascript #node.js #session How to make session last maximum of 30 days using client-sessions duration and activeDuration

Bounty: 50

According to https://github.com/mozilla/node-client-sessions#usage

var sessions = require("client-sessions");
app.use(sessions({
  cookieName: 'mySession', // cookie name dictates the key name added to the request object
  secret: 'blargadeeblargblarg', // should be a large unguessable string
  duration: 24 * 60 * 60 * 1000, // how long the session will stay valid in ms
  activeDuration: 1000 * 60 * 5 // if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
}));

I want my users’ sessions to be active for a maximum of 30 days. If I set duration to 30 days and activeDuration to 30 days, I think I’ll end up with 60 day long sessions.

If I set duration to 15 days and activeDuration to 15 days, won’t a user who logs in and then does nothing at all be logged out in 15 days (not that I expect that kind of user behavior, but is my assumption correct?)

All I want is for every time a user comes to the site to get 30 days before they need to re-login. How do I get that behavior?


Get this bounty!!!