MrCholo

0

votes
1

answer
17

views

tell Java to recognize type with if/else section

I have this section of code: var v = this.rhs; if(this.rhs instanceof String){ v = ((String)v).replace("'","''"); // escape single-quotes } else{ v = v.toString(); } if(v.contains(" ")){ v = String.join("","'",v,"'"); } Java complains and says: It can't deduce that it must be a String. Although typ...
MrCholo
2

votes
2

answer
19

views

Map collection using stream is yielding strange compilation error

I have this method: public void fields(TableField... s){ // compilation error on next line Collection fields = Arrays.asList(s).stream().map(v -> v.getValue()); this.fields.addAll(fields); } and TableField is simple just looks like: class TableField { public String getKey() { return this.key; } publ...
MrCholo
0

votes
1

answer
17

views

java.lang.IllegalArgumentException: Unrecognized field “loaf”

Here is my JUnit test: package general; import io.vertx.core.json.JsonObject; import io.vertx.ext.unit.TestContext; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; class Foo { String loaf = ""; static boolean dog() { return true; } } public cl...
MrCholo
2

votes
2

answer
43

views

Break out of synchronized block?

I have this: synchronized(c){ if (!items.hasNext() && (c.getFinishedCount() == c.getStartedCount())) { f.done(null, results); return; } if(c.isBelowCapacity()){ RunMap(items,m,results,c,s,f); } } but ultimately I don't need to be synchronized on c when I call RunMap() or f.done(), I just need to be...
MrCholo
13

votes
3

answer
845

views

How to concatenate lists into one list

I have a list of values, some of which could be lists/collections or single values. In JavaScript notation it might look like: const input = [1,2,[3,4], [5,6], 7]; and I want to get: const concatenated = [1,2,3,4,5,6,7]; So I have this Java code: ArrayList concatenated = new ArrayList(); for (T v :...
MrCholo
1

votes
1

answer
2.2k

views

Tell Puppeteer to open Chrome tab instead of window

If I have an existing Google Chrome window open, I'd like to tell puppeteer to open a new tab instead of opening a new window. Is there a way to do that? is there some option or flag I can pass to puppeteer to accomplish this? I have: const puppeteer = require('puppeteer'); (async function () { cons...
MrCholo
1

votes
2

answer
1.6k

views

String concatenation with null's and undefined's in JavaScript

I always thought that one of the advantages of using this formulation of console.log will save you from null pointer exceptions and the like: var c = undefined; console.log(c,"foo"); now we get "undefined 'foo'" however, there doesn't really seem to be much of an advantage, since using the + operat...
MrCholo
1

votes
0

answer
20

views

Pipe stdin to child process with node.js

Say I have a node.js script like so: import * as cp from 'child_process' process.stdin.resume().on('data', d => { if(d === 'shell'){ const k = cp.spawn('bash'); process.stdin.pipe(k.stdin); } }); this might work technically, but I am not sure if it makes sense. I believe it will pipe stdin of the pa...
MrCholo
1

votes
1

answer
25

views

Include dynamic JSON data in Angular7 app

I am using both ng serve --watch and ng build --watch. With ng build, it will use my index.html file, but with ng serve, it seems to ignore it. Right now, I am rendering some dynamic JSON in the index.html file like so: ApiApp const appData = JSON.parse(''); the above works with ng build but not ng...
MrCholo
11

votes
2

answer
5.6k

views

Check if object is an RxJS5 observable

I have this method: Queue.prototype.drain = function (obs, opts) {}; in the method, I would like to check if the user passed in an observable for the first argument or if they omitted the observable and just passed in an options object. So basically I need to do something like this: if(!Rx.Observabl...
MrCholo
0

votes
2

answer
25

views

does const create a local scope just like let? [duplicate]

This question already has an answer here: What is the difference between 'let' and 'const' ECMAScript 6? 6 answers Why JavaScript const works well with for in loop [duplicate] 3 answers Say I have this: for(const v of [1,2,3]){ console.log(v); } const v = 5; console.log(v); does that create a uniq...
MrCholo
2

votes
1

answer
809

views

JSON response and calling next() in Express

Is it possible, using Express 4, to send a JSON response to the front-end indicating that there was an error, as well as calling next(err) inside the Express middleware, so that the error can be handled by the server as well? Or are these calls completely mutually exclusive? My current assumption is...
MrCholo
2

votes
2

answer
51

views

Determining if delete actually removed an existing key in a map

I have a map called nearby func Delete(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) delete(nearby, params["id"]) } I want to find out if the delete() call actually found a key to delete, I tried reading the return value: func Delete(w http.ResponseWriter, r *http.Request) { params...
MrCholo
1

votes
0

answer
6

views

Install golang library within subdirectory of Github repo

Normally Golang projects on Github are consumed by go install when there is a src folder at the root of the project. Right now I have a Git repo structured like so: project/ lang/ typescript/ java/ golang/ src/ is there a way to use go install against this git repo? Something like this: go install '...
MrCholo
2

votes
1

answer
929

views

WebStorm - make node_modules “library root” but also exclude it from indexing

Is there a way to configure a WebStorm project that so node_modules is selected as library root but that it's also excluded from indexing? I swear I saw a project that indicated node_modules was both library root and excluded but I can't figure out how to set that up. Anybody know how?
MrCholo
1

votes
3

answer
3.9k

views

How to add elements to a vector of tuples

I just have this: std::vector ints; how can I add elements to this vector? using either ints.insert() or ints.push_back()? No idea how to do this, C/C++ newb.
MrCholo
5

votes
1

answer
58

views

Use process substitution - only send stderr to file

For some reason, it seems like stderr is being sent to stdout in the following bash script: exec > >( while read line; do echo " stdout: $line"; done ) exec 2> >( while read line; do echo " stderr: $line"; done ) echo "rolo" echo "cholo" >&2 if you run that, the output is so: stdout: rolo stdout: st...
MrCholo
7

votes
6

answer
280

views

Compress heredoc declaration to one line in bash?

I have this which works to declare a JSON string in a bash script: local my_var="foobar" local json=`cat
MrCholo
2

votes
6

answer
55

views

group array and get count

Say I have array like this: [ "foo", "bar", "foo" "bar", "bar", "bar", "zoom" ] I want to group it so I can get a count like so: { "foo": 2, "bar": 4, "zoom": 1 } is there a utility that can do this?
MrCholo
1

votes
2

answer
219

views

Promise.resolve() but for Observables (RxJS5)

Ok so just to learn RxJS better, decided to try my hand at creating a custom Rx operator. So here is a simple one that works fine: Rx.Observable.prototype.multiply = function (input) { const source = this; return Rx.Observable.create(function (obs) { return source.subscribe(function(val){ obs.next(i...
MrCholo
0

votes
1

answer
11

views

Return multiple middleware funcs from router.HandleFunc call

I am using gorilla/mux I have this: router.HandleFunc("/api/v1/register",h.makeRegisterNewUser(v)).Methods("POST") and h.makeRegisterNewUser looks like: func (h Handler) makeRegisterNewUser(v interface{}) http.HandlerFunc { type RespBody = ...; type ReqBody = ... return func(w http.ResponseWriter, r...
MrCholo
7

votes
2

answer
69

views

Why is my `find` command giving me errors relating to ignored directories?

I have this find command: find . -type f -not -path '**/.git/**' -not -path '**/node_modules/**' | xargs sed -i '' s/typescript-library-skeleton/xxx/g; for some reason it's giving me these warnings/errors: find: ./.git/objects/3c: No such file or directory find: ./.git/objects/3f: No such file or...
MrCholo
1

votes
1

answer
122

views

Static member of a struct in Golang

Say I have a struct: type DriverData struct { TypePath string = "Foo.Bar.DriverData" } I want to be able to reference TypePath without have to create an instance of the struct, something like: typePath:= DriverData.TypePath but that's not possible in Golang. So I was wondering - maybe there is a way...
MrCholo
3

votes
1

answer
782

views

Adding space between Flex rows

I have this html in an Angular 5 component: .row>div { flex-basis: calc(50% - 20px) !important; /* width less horizontal margins */ margin: 10px; } play_button Start Recording play_button Stop Recording Firefox Chrome Allow XPath it renders to this: I tried adding this CSS to increase the...
MrCholo
2

votes
1

answer
103

views

Express 4 router

At this point, I am pretty clear on how the Express 4 router works, but I am confused about how the primary router instance declared in the app.js file, like it is immediately below, interacts with other routers in the Express server. so you start off with this in your app.js file: var express = req...
MrCholo
1

votes
2

answer
100

views

What is the `>>>` operator in JavaScript?

I was looking at the polyfill for Array.prototype.map: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map if (!Array.prototype.map) { Array.prototype.map = function(callback/*, thisArg*/) { var T, A, k; if (this == null) { throw new TypeError('this is null or...
MrCholo
1

votes
1

answer
377

views

Use DevTools protocol to open new tab in window

I am using puppeteer to launch a new Chrome browser window: const util = require('util'); const puppeteer = require('puppeteer'); (async () => { const b = await puppeteer.launch({ headless: false, devtools: true, // open DevTools when window launches args: ['--remote-debugging-port=9222'] }); consol...
MrCholo
2

votes
2

answer
60

views

I deleted a branch with -d, how can I restore/recover it?

I deleted a branch with: git branch -d it said: git branch -d oleg/feature/1533692217 warning: deleting branch 'oleg/feature/1533692217' that has been merged to 'refs/remotes/origin/oleg/feature/1533692217', but not yet merged to HEAD. Deleted branch oleg/feature/1533692217 (was f7a4a13). I think I...
MrCholo
1

votes
6

answer
45

views

Slick way to create nested array types

I have something like this: const rhs = ['Foo.Bar', 'Two', 'Three']; and I want to get: Array I have this which works: const literalType = rhs.reduce((a,b) => { return [a,'') ); const finalVal = `Array`, But I am looking for something a little slicker than that. Does anyone have a good idea on how t...
MrCholo
2

votes
3

answer
50

views

Injecting a service using a method instead of the constructor

Say I have this service and component. I would like to use multiple instances of MySillyService. @Injectable() export class MySillyService { } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { vals: Array; const...
MrCholo
2

votes
2

answer
406

views

Express middleware cannot trap errors thrown by async/await, but why?

These two middleware functions behave differently and I cannot figure out why: Here, the error will get trapped by try/catch: router.get('/force_async_error/0', async function (req, res, next) { try{ await Promise.reject(new Error('my zoom 0')); } catch(err){ next(err); } }); But here, the error wi...
MrCholo
2

votes
1

answer
255

views

Observable.prototype.concatAll does not seem to yield expected result

With this code in mind: const Rx = require('rxjs'); var i = 3; const obs = Rx.Observable.interval(10) .map(() => i++) .map(function(val){ return Rx.Observable.create(obs => { obs.next(val) }); }) .take(10) .concatAll(); obs.subscribe(function(v){ console.log(v); }); I would have expected the logged...
MrCholo
8

votes
1

answer
1k

views

“Unsubscribe” function callback/hook in Observable “executor” function

I am confused about what the purpose of the "dispose" or "unsubscribe" function is for, which is (optionally) returned from an observable "executor" function, like so: const Rx = require('rxjs'); const obs = Rx.Observable.create(obs => { // we are in the Observable "executor" function obs.next(4); /...
MrCholo
2

votes
1

answer
56

views

Communicate directly between custom Chrome devtools panel and Chrome Extension content script

My question is: is there a way to communicate directly between my custom Chrome DevTools panel and my Chrome Extension's content script? Right now, it seems like I need to use the background script as a mediator between the content script and the devtools panel. I tried using a custom window event:...
MrCholo
2

votes
3

answer
75

views

Using functional for loop with non-Array iterator

Say we have this generator function (generator fn returns an iterator): function* foo(){ yield 1; yield 2; yield 3; } for (let i of foo()) { console.log(i); } we can iterate over the iterator using a for..of loop. My question is: is there a way to create a functional for-loop to iterate over an iter...
MrCholo
2

votes
2

answer
100

views

How to debug an arbitrary/random script with Visual Studio Code

I normally use Webstorm, but after several years of success with Webstorm I am having some weird issues, so I am trying out VSCode - I'd like to be able to debug a script - I have about 60 or 70 Node.js scripts that I run regularly. I don't want to set up a separate configuration for each one, if I...
MrCholo
2

votes
1

answer
34

views

Find most recent commit with certain filename

I don't think Git can do this, I feel like I have asked this question before... Is there a way to search commit history, to find the most recent commit that has a file with a certain name? We renamed or removed a file, and I am trying to recover it / find it. I get the feeling I will here an answer...
MrCholo
2

votes
1

answer
536

views

Transform JS objects to JSON using transform stream

Note there are many transform streams that do this: JSON -> JS but I am looking to create a Node.js transform stream that can do: JS -> JSON I have a readable stream: const readable = getReadableStream({objectMode:true}); the readable stream outputs Objects, not strings. I need to create a transform...
MrCholo
1

votes
1

answer
59

views

Give integers a default value if they are initialized as empty

I have this (it's a Node.js addon) void Method(const v8::FunctionCallbackInfo& args) { int count = args[2]->ToNumber()->NumberValue(); int priority = args[3]->ToNumber()->NumberValue(); int priority_search_cap = args[4]->ToNumber()->NumberValue(); cout
MrCholo
3

votes
2

answer
58

views

newline matching regex - is /[\r\n]/ the same as /[\n]/? [closed]

As far as matching a newline in a string - is /[\r\n]/ the same as /[\n]/ ? I was reading this blog post: https://davidwalsh.name/remove-multiple-new-lines and it says to use /[\r\n]/, but I am simply wondering if that always matches the same as /[\n]/, or if they are sort of a venn diagram where e...
MrCholo

View additional