MrCholo

1

votes
2

answer
57

views

panic: Last argument needs to be of type http.HandlerFunc

I have this helper function, which is compiling fine: func Middleware(adapters ...interface{}) http.HandlerFunc { log.Info('length of adapters:', len(adapters)) if len(adapters) < 1 { panic('Adapters need to have length > 0.'); } h, ok := (adapters[len(adapters)-1]).(http.HandlerFunc) if ok == false...
MrCholo
1

votes
4

answer
50

views

How to cast the return value of a getter

I have a HashMap called map as a member, and I retrieve values from it using: public Object get(String s) { return this.map.get(s); } I think I can turn this into something using generics so we can cast the return value inline, something like this: public V get(String s) { return (V)this.map.get(s);...
MrCholo
1

votes
0

answer
458

views

Use env variable in background script of Chrome extension

Is there a way to use an env variable in a background script of a Chrome extension? I need to conditionally take an action depending on whether we are in development/production environment.
MrCholo
1

votes
0

answer
58

views

git config with branch name with forward slashes

I have a branch name with forward slashes: oleg/feature/foo if I try to run: git config --local branch.oleg/feature/foo.bar 5 I get this: error: invalid key: branch.oleg/feature/foo even though when I run git branch I see that oleg/feature/foo is listed...what to do?
MrCholo
1

votes
1

answer
30

views

Creating groups from list

I have this routine which will group an array, groups of x/chunkSize items. const createGroupedArray = function (arr, chunkSize) { if(!Number.isInteger(chunkSize)){ throw 'Chunk size must be an integer.'; } if(chunkSize < 1){ throw 'Chunk size must be greater than 0.'; } const groups = []; let i = 0...
MrCholo
1

votes
0

answer
36

views

bundle: cannot find package in current directory: no buildable Go source files in PWD

Using the go bundle too located here: https://godoc.org/golang.org/x/tools/cmd/bundle I try running: bundle -o bun ./builds/one and I get this error: bundle: cannot find package in current directory: no buildable Go source files in $PWD Why is the tool not understanding that I want to search for go...
MrCholo
1

votes
0

answer
19

views

Export import via namespace

Say I have this situation: import {ExpressRoute} from './expressjs/express-route' export namespace express { } is there a way to export the import from the namespace? something like this: export namespace express { export class Route = ExpressRoute; } alternatively, is there a way to import/export a...
MrCholo
1

votes
0

answer
12

views

Sourcing NPM dep differently depending on environment

A typically package.json file has a dependencies map: 'dependencies':{ 'foo': '1.2.3' } or it might have a URL pointing to a tarball: 'dependencies':{ 'foo': 'http://some-tarball-repo.com/foo.tgz' } my question is - is there a way to resolve a dependency differently, depending on environment? Someth...
MrCholo
1

votes
0

answer
37

views

Create synchronized block based on ownership beyond threads

I was expecting this to block forever: synchronized (this){ synchronized (this){ } } but it makes sense that it doesn't..looks like if the current thread owns the lock on this then the second call is a passthrough essentially. Is there a mechanism in Java that can create a critical section that's no...
MrCholo
1

votes
0

answer
75

views

Cannot format javadoc html with google-code-prettify lib

I tried to add styling to a block using: https://github.com/google/code-prettify But all I see is this: I am looking to get the default syntax highlighting. I put this at the top of the html file: and then I have a block that looks like so: /** * * new BeanTranslator.Builder() * .translate( *...
MrCholo
1

votes
1

answer
28

views

Debugging Backbone apps - seeing view name

For debugging purposes, I would like to see the name of the class of a Backbone view like so: var IndexView = Backbone.View.extend({ className:'IndexView', however, it doesn't seem like className is the right property for me to set. When I run: var view = new IndexView(); when I debug, className doe...
MrCholo
1

votes
1

answer
86

views

Creating JS library Warning instead of Error

I am creating my own JS library with NPM. I want to give the users of my library a warning but not an error, however, I want my users to have a stacktrace of the warning that I log inside my library. So to get the stacktrace, I use new Error().stack. The problem with this is (1) the word 'Error' app...
MrCholo
1

votes
1

answer
47

views

Prevent developers from unintentionally killing daemon / worker processes on local machine

A lot of newbs will kill all their node.js processes on their local machines with pkill -f node Or killall node Etc. I have a library that uses some daemon processes/workers running on the developer's machine and I will need to restart them if the development 'accidentally' kills (all) node.js proce...
MrCholo
1

votes
1

answer
1.4k

views

How to run Selenium tests with a standalone / containerized server

This question regards how to start a standalone Selenium server - currently it appears as though my junit test will start up the Selenium server for me, and I am looking to do that separately. // selenium test script using junit: package suman; import java.util.concurrent.TimeUnit; import org.junit...
MrCholo
1

votes
1

answer
32

views

Listen for EOF for deleted fifo / named pipe

I created this fifo / named pipe' my_named_pipe='$HOME/foobar' mkfifo '$my_named_pipe' while read line; do on_fifo_msg '$line'; done < ${my_named_pipe} & at some point later on, I delete this fifo from the filesystem - I assume the read loop ends because of EOF or whatever - but how can I listen for...
MrCholo
1

votes
1

answer
83

views

Get correct timestamp for 45 seconds ago

I am trying to get a valid MongoDB Timestamp, I have this: import {Timestamp} from 'bson'; const ts = Timestamp.fromInt(Date.now() - 45000); console.log(ts); that logs: Timestamp { _bsontype: 'Timestamp', low_: 853265937, high_: 0 } that doesn't seem right, what am I doing wrong? Note that a valid t...
MrCholo
1

votes
2

answer
41

views

mkfifo - create a file that never experiences EOF etc

I have this script: mkfifo foo exec 3foo cat &3 echo 'bar' >&3 echo 'baz' >&3 I am just trying to prepend a string to each line of every command's stdout/stderr. The problem is that the named pipe will experience EOF so the cat command will exit quickly. Is there some file I can use instead of a nam...
MrCholo
1

votes
1

answer
32

views

read large directory with nodejs

Say I have a large directory, perhaps 10,000,000+ items in the dir. if I use fs.readdir(dir, (err, items) => {}); it will load a lot into memory, because the items array will be 10 million items. Is there a way to read the directory 15000 items at a time or so, with some linux command and child pro...
MrCholo
1

votes
1

answer
71

views

Why is test() returning True when it should fail?

I have this code and I am wondering why it logs true: console.log(/[A-Za-z0-9-_:]/.test('zoom^Bar')); I would assume the caret character would make the regex fail, why is it passing? Just want to say this question is straightforward but might help others and the 'duplicate' question doesn't really l...
MrCholo
1

votes
3

answer
68

views

Running `git pull --rebase`, what does it rebase against?

I see a lot of examples of: git pull --rebase but I am left wondering what branch is merged into the current branch. Shouldn't it be git pull --rebase or git pull --rebase ?
MrCholo
1

votes
1

answer
164

views

Why toString() can be called on arguments but not directly

So I have this: 5.toString() I get this error: console.log(5.toString()); ^^ SyntaxError: Invalid or unexpected token at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._exten...
MrCholo
1

votes
1

answer
0

views

Package golang directory tree into a single file

Using Golang, if we have a folder tree like this: foo/ bar/ baz/ baz.go jazz/ jazz.go is there a way to package this folder into a single file for consumption by other go programs, but keep the namespacing, etc?
MrCholo
1

votes
1

answer
0

views

Angular Injected service is not being assigned to object instance

I am using Angular6 and I have this: 'use strict'; import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; import {MainService} from './services/main.service'; import {AppService} from '../../app.service'; @Component({ selector: 'app-main', templateUrl: './main.component.html', styleUrls...
MrCholo
1

votes
1

answer
0

views

Add data to the RoutingContext of Vert.x middleware

Say I have this middleware class: public class Middleware implements Handler { public void handle(RoutingContext ctx) { ctx.set('foo', 'bar'); // ctx.set is an imaginary method ctx.next(); } } the ctx.set() method is made-up - it doesn't exist on version 3.6.2. So how can we set arbitrary info on t...
MrCholo
1

votes
1

answer
149

views

Purpose of 'isUnique' field in Mongoose

I don't understand the purpose of fields like unique and required in Mongoose schemas. In the case of unique, it appears that you have to write your own methods to query MongoDB to see if the value already exists. I suppose with 'required' Mongoose just needs to check if that value was passed in the...
MrCholo
1

votes
1

answer
234

views

Node.js exports syntax with TypeScript

Is there a way to accomplish this Node.js/CommonJS syntax with TypeScript? const makeObservable = exports.makeObservable = function _makeObservable(fn: any, opts: any) {} Basically as you can see, would like to declare a local variable on the same line as exporting that variable. Is it possible in s...
MrCholo
1

votes
1

answer
76

views

JS-Beautify programmatic options API

I am currently using this package https://www.npmjs.com/package/js-beautify like this: import {js_beautify} from 'js-beautify'; const beautifiedCode = js_beautify(` const foo = 'bar'; console.log(foo); `) however, imagine if I want to format the above, so that the maximum number of blank lines is on...
MrCholo
1

votes
1

answer
35

views

Forcing parameter to function to be more generic using <any>

Whenever I try to do this, I can't get it to work, I have this code: router.events.subscribe(val => { console.log('router event:', val); localStorage.setItem(this.anyRouteKey, val.url); }); it's giving me this error: it turns out, the url property does exist, it's just an error in the typings. So I...
MrCholo
1

votes
2

answer
33

views

Write to stdin of process listening for messages

Say I start a process with: #!/usr/bin/env bash while read line; do echo 'stdin message: $line' done < '/dev/stdin' apparently this process is listening for data being to written to its stdin. How can another process write to it?
MrCholo
1

votes
2

answer
74

views

git log shows added / removed - is there a way to show modified lines

When we use the $ git log command, we can see how many lines added / removed for a file. My question is - is there a way to inspect which lines were modified (neither added nor removed)? Or can only git diff do that? Sort of a philosophical question, since a modified line could simply be considered...
MrCholo
1

votes
2

answer
63

views

Create a function that inherits from EventEmitter

Using TypeScript, is there a way to declare a function (not a class) that inherits from EventEmitter? Using vanilla JS this is possible, but not sure how to do it with TS. export const foo = function extends EventEmitter(){ // lol no return {}; // (I need to return something here) }; here is how y...
MrCholo
1

votes
1

answer
52

views

Store information in branch (metadata) about which point it diverged from “parent” branch

Say I have this: latest_commit=`git rev-parse HEAD` git checkout -b 'foo_$latest_commit' git reset --soft 'origin/dev' what I am doing is keeping track of where the 2nd branch diverged from the first. But instead of putting the commit id in the name of the 2nd branch, is there a way to store metadat...
MrCholo
1

votes
1

answer
30

views

git submodule - ignoring changes

I do this all the time: git add . git add -A git commit -am 'foobar' that adds everything so all of my changes are staged, but we have a git submodule in the config directory. What I have been doing is using several of these commands to 'get rid of changes to the config dir': git reset -- config git...
MrCholo
1

votes
1

answer
69

views

trying to read json file at url

I have this java file: package foo; import java.net.*; import java.io.*; import org.json.simple.*; class JsonObject { String foo; } public class Bar { public static void main(String[] args){ URL url = new URL('https://raw.githubusercontent.com/oresoftware/oredoc/master/test/builds/java/one/test.json...
MrCholo
1

votes
1

answer
23

views

Define property on object inline

I have this code right now and I am wondering if there is a way to do this inline: export const defaultArrayType = { 'string': defaultString, 'boolean': defaultBoolean, 'number': defaultNumber, 'object': defaultObject }; Object.defineProperty(defaultArrayType, 'undefined', { get() { throw new Error(...
MrCholo
1

votes
1

answer
34

views

How to install the go bundle tool [closed]

I am trying to figure out how to install this: https://godoc.org/golang.org/x/tools/cmd/bundle anybody know?
MrCholo
1

votes
1

answer
46

views

Using Vert.x handle errors thrown in request middleware

Say I have some middleware and an error is raised: public class JWTHandler implements Handler { public void handle(RoutingContext ctx) { throw new Error('How can I capture this error and send a response.') ctx.next(); } } How can I capture it using some error-handling middleware? Here is a global er...
MrCholo
0

votes
0

answer
4

views

Get list of posts for logged-in user

I am logged in with the Facebook JavaScript SDK, and I call: FB.api( '/me/feed?access_token=' + accessToken, { // 'with': 'location' limit:50 }, function (response) { console.log({feed:response}); } ); }); I am getting this response back: Does anyone know why I am getting no data? I know for a fact...
MrCholo
1

votes
4

answer
913

views

pyenv python2 version not working

I am seeing this in my terminal: gyp ERR! stack pyenv: python2: command not found gyp ERR! stack gyp ERR! stack The `python2' command exists in these Python versions: gyp ERR! stack 2.7.5 gyp ERR! stack 2.7.8 I am super confused what this means. How can I configure pyenv so that this works? I a...
MrCholo
1

votes
1

answer
24

views

Generate Javadocs for easy consumption on mobile phones

I generated some javadocs, looks pretty good, I can even include inline code samples/examples. However, doesn't look very good on mobile: Here are the plugin settings I am using: org.apache.maven.plugins maven-javadoc-plugin 3.0.1 attach-javadocs jar -html5 --allow-script-in-comments maybe there is...
MrCholo

View additional