Lone Learner

1

votes
1

answer
60

views

How to expose a web server with REST API and HTML/JavaScript applications from an existing Python application?

I have an existing Python application that crawls the Internet continuously. It uses the requests package to make HTTP requests to various Internet websites such as GitHub, Twitter, etc. and downloads the available data on to a filesystem. It also makes HTTP requests to the REST APIs of GitHub repos...
Lone Learner
1

votes
7

answer
108

views

How to align discs (bullets) of UL with the left edge of an enclosing DIV?

A regular list This is a regular list that serves as the basis of my question. div { background: lightgreen; width: 15em; margin-left: auto; margin-right: auto; font-size: 2em; } Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in pretium mauris. Aliquam ultrices ipsum sit...
Lone Learner
1

votes
2

answer
130

views

The `include` statement in a registered autoloader function runs in the context of which script?

Directory structure [email protected]:~$ tree ~/bin /home/learner/bin └── php ├── Body │   ├── Brain.php │   └── Cell │   └── Neuron.php └── main.php 3 directories, 3 files First code example ~/bin/php/main.php:
Lone Learner
1

votes
3

answer
73

views

Are decorators always invoked in the order they are encountered while reading the source code from top to bottom?

I am trying to understand if decorators are always invoked in the order they are encountered while reading the source code from top to bottom? Here is some sample code I wrote: def log(func): print(func) return func class A: @log def __init__(self): print('__init__') @log def foo(self): print('foo')...
Lone Learner
1

votes
1

answer
75

views

How can I find out which shell commands are available in a POSIX compliant Linux system and which ones are not?

While writing a shell script, I want to try to keep my script as much POSIX-compatible as possible, i.e. any POSIX shell should be able to run it successfully. While writing scripts, sometimes I have to decide whether I should use the printf, getopt, etc. commands or not. I don't know how to take su...
Lone Learner
1

votes
2

answer
31

views

Which line continuations are valid and which ones are invalid in shell scripting for POSIX shell?

In the following example, although I have split the line if true && true into two lines, it works fine and produces the output hi. if true && true then echo hi fi But in the following example, where the redirection operator and the filename has been split into two different lines, I get an error. wc...
Lone Learner
1

votes
1

answer
174

views

POSIX compliant way to find out if a process with a certain PID is alive

I learnt from https://serverfault.com/q/366474 that the following code is a POSIX-compliant way of testing whether a process with PID = $pid is alive. It uses the kill -0 command. # First code sample pid=100 if kill -0 '$pid' 2> /dev/null then echo PID '$pid' is alive. else echo PID '$pid' not found...
Lone Learner
1

votes
1

answer
145

views

Why is the overridden `add` method that JFrame defines is not mentioned in the API documentation of JFrame?

Quoting http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html : As a conveniance add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write: frame.add(child); And the child will be added to the contentPane. Quoting...
Lone Learner
1

votes
1

answer
261

views

Why can't I import a public key certificate into Firefox that is generated using keytool in a certain way?

I am trying to generate a certificate for CA2 such that: There is a root CA called CA0. There is an intermediate CA called CA1. There is another intermediate CA called CA2. CA0 signs the certificate of CA1. CA1 signs the certificate of CA2. I generate CA2 using various methods using keytool. Method...
Lone Learner
1

votes
1

answer
44

views

Is there a best practice on maintaining thirdparty javascript libraries in Git repo for a Java project (not Node project)?

I am working on a server side Java project. The Java code is merely 4 KB in size. However, the thirdparty JavaScript libraries (chartjs, angular, jquery, d3, etc.) consume a whopping 50 MB. Right now, the Java code as well as all the thirdparty JavaScript libraries are committed to my git repository...
Lone Learner
1

votes
1

answer
201

views

Why does login shell launched by tmux modify the PATH in an unexpected manner?

On my macOS Sierra 10.12.6, I have my ~/.bash_profile as shown below. macbookpro:~ lone$ echo $TERM_PROGRAM Apple_Terminal macbookpro:~ lone$ cat ~/.bash_profile echo 1: PATH: $PATH PATH=BEG:$PATH:END echo 2: PATH: $PATH I do not have ~/.bashrc or ~/.profile. macbookpro:~ lone$ ls -ld ~/.bash* -rw--...
Lone Learner
1

votes
1

answer
117

views

Why does Elasticsearch allow me to index documents in a single node cluster that fails to meet quorum requirements?

From https://www.elastic.co/guide/en/elasticsearch/guide/2.x/distrib-write.html: Note that the number_of_replicas is the number of replicas specified in the index settings, not the number of replicas that are currently active. If you have specified that an index should have three replicas, a quorum...
Lone Learner
1

votes
1

answer
48

views

Why does DIV not occupy entire width of screen on mobile Chrome when another DIV has 100% width?

Here is my HTML code. Test body { margin: 0; } .a { background: orange; border: 2px solid black; } .b { padding: 0 2em; width: 100%; background: lightblue; border: 2px solid black; } Foo Bar Here is the output I see when I view the page with an Android mobile device with Chrome browser. The issue he...
Lone Learner
1

votes
1

answer
83

views

How do I prevent Git from auto-detecting user.email?

I don't have any global user.email or global user.name setup on purpose. I like to set my user.email and user.name per repo by using the git config user.email and git config user.name commands. On macOS with git version 2.17.0, if I forget to set user.email or user.name for a repo on my Mac, when I...
Lone Learner
1

votes
1

answer
367

views

How to load local JavaScript file with JSDOM?

I am unable to use JSDOM (version 13.0.0) to load scripts from the local filesystem with a relative path. I have taken a look at the following questions but they do not answer my question: jsdom can't load local html and javascript (I have already followed the runScripts and resources suggestion the...
Lone Learner
1

votes
1

answer
0

views

BSD sed ignores the leading spaces in the text for a\ command

Leading spaces are preserved in echo command. Take this script for example: echo 'abc def' Output: $ sh foo.sh abc def But leading space in sed text for a\ command is not preserved with the BSD sed that comes with macOS. Take this script: echo abc | sed '/abc/a\ def ' Output with BSD sed on macOS:...
Lone Learner
1

votes
3

answer
965

views

Hide variables within an anonymous JavaScript function but access them using `this`

I'll use the following JavaScript code to demonstrate what I am trying to do. var App = function() { var url var width var height function init() { url = window.location.href width = document.body.clientWidth height = document.body.clientHeight } function run() { init() alert(url + ' - ' + width + '...
Lone Learner
1

votes
1

answer
206

views

What does importing a subdirectory mean in Python 3.4?

I thought a package should always contain __init__.py file. But this seems to work for me. C:\Windows>python Python 3.4.0b3 (v3.4.0b3:a97ce3ecc96a, Jan 26 2014, 17:50:55) [MSC v.1600 64 bit (AMD64)] on win32 Type 'help', 'copyright', 'credits' or 'license' for more information. >>> import System32 >...
Lone Learner
1

votes
1

answer
36

views

Modifying a variable more than once in a statement and order of evaluation of function arguments in JavaScript

How do we reason about these JavaScript statements and explain their output? i = 1; i = i++; console.log(i); // Outputs 1 in Firefox i = 1; x = i++ + i++; console.log(i, x); // Outputs 3 3 in Firefox i = 1; console.log(i, i++); // Outputs 1 1 in Firefox In C, the equivalent...
Lone Learner
1

votes
1

answer
65

views

Grammar for parsing PHP like language such that it can handle the PHP begin and end tokens (“<?” and “?>”) in the grammar

I am trying to understand how one can define a PHP-like grammar. In PHP, one can get out of PHP mode into HTML mode and then back into PHP mode. For the sake of asking this question, I am defining my PHP-like language to be ridiculously simple. This language will be referred to as 'PHP-like' in the...
Lone Learner
1

votes
1

answer
34

views

Numerical sort in shell when each line does not begin with number

I have this file. $ cat foo.txt foo 1 foo 12 foo 110 foo 15 foo 120 I want to sort this file numerically. But I am unable to do so with the sort -n command. $ sort -n foo.txt foo 1 foo 110 foo 12 foo 120 foo 15 The output I expect is this. foo 1 foo 12 foo 15 foo 110 foo 120 I have two questions. Wh...
Lone Learner
1

votes
1

answer
62

views

How to run JavaScript code as soon <body> element is defined?

Here is my code: Foo console.log('test') Foo I want to move the JavaScript in this code from into . Here is my incorrect attempt: Foo window.onload = function () { console.log('test') } Foo This of course does not do what I want. It runs the JavaScript only after the whole page has loaded. But I wa...
Lone Learner
4

votes
2

answer
65

views

How to keep newline intact in a sed command used in Makefile (POSIX)?

Note: This is not a duplicate of Is it possible to create a multi-line string variable in a Makefile and other such questions. This question requests POSIX compliant solutions that do not depend Bash-only or GNU Make-only features. The other question on Stack Overflow does not have this requirement....
Lone Learner
1

votes
1

answer
287

views

Why macro defined within a C function is not documented by Doxygen?

I have the following code in a file named foo.c. /** @file */ #include /** Prints hello */ #define hello() printf('hello, ') int main() { /** Prints world */ #define world() printf('world\n') hello(); world(); } I have a file named Doxyfile in the same directory. PROJECT_NAME = Foo JAVADOC_AUTOBRIE...
Lone Learner
1

votes
1

answer
363

views

How to make read buffer from standard input when run with --remote-tab-silent option?

The following command successfully launches vim that reads the edit buffer from standard input. echo hi | vim - But this one does not work. echo hi | vim --remote-tab-silent - When the above command is run, the following warning occurs and vim quits. Vim: Warning: Input is not from a terminal Vim: E...
Lone Learner
1

votes
2

answer
66

views

Why does sed 'w' editing command truncate the file instead of appending to it?

I wrote this shell script. echo a: foo > a.txt echo a: bar >> a.txt echo a: baz >> a.txt sed -i -e '/bar/{ w b.txt' -e 'd }' a.txt sed -i -e '/baz/{ w b.txt' -e 'd }' a.txt cat b.txt Here is the output I got. a: baz But I expected this output. a: bar a: baz I expected this output because http://pubs...
Lone Learner
1

votes
1

answer
59

views

Why does field splitting not occur after parameter expansion in an assignment statement in shell?

Consider the following two assignments. $ a='foo bar' $ b=$a $ b=foo bar bash: bar: command not found Why does the second assignment work fine? How is the second command any different from the third command? I was hoping the second assignment to fail because b=$a would expand to b=foo bar Since $...
Lone Learner
1

votes
2

answer
445

views

How to invoke a method with pointer receiver after type assertion?

I am learning interface, type conversions and methods with pointer receivers. The rules and terminology behind pointer receiver methods are confusing to me. Let me demonstrate my confusion with one program. This is my Go program. package main import 'fmt' type Employee struct { Name string } func (e...
Lone Learner
1

votes
2

answer
52

views

Which part of the HTML specification cause a URL within angle-brackets to be parsed as an <http:> element with attributes?

Here is my HTML code. Bar window.onload = function() { console.log(document.body.innerHTML) } I save this code in a file named bar.html and then open the page with Firefox or Chrome. This is the output I see in the console. Now I understand that my code was incorrect because it had a URL enclosed wi...
Lone Learner
0

votes
1

answer
116

views

In search of a unified theory for the interpretation of |, <Bar>, and \| in Vim

Here are a few experiments to demonstrate how |, , and \| behave in different scenarios in Vim commands. The code-blocks below show several Vim commands with each command (or set of commands) followed by a quick commentary on how the command behaves. Case 1: Shell commands :!uname | new /bin/bash: n...
Lone Learner
1

votes
3

answer
626

views

How to iterate over double-quoted strings in POSIX shell?

I am trying to check if all the non POSIX commands that my script depends on are present before my script proceeds with its main job. This will help me to ensure that my script does not generate errors later due to missing commands. I want to keep the list of all such non POSIX commands in a variabl...
Lone Learner
1

votes
1

answer
92

views

How do we create instances of a class in JavaScript using new operator and factory pattern?

I am trying to make a class (called Foo) like object in JavaScript that would let me create multiple instances of Foo. By multiple instances, I mean, each instance would maintain separate internal state. This is how I am achieving it. var Foo = function() { function init(a) { this.a = a } function s...
Lone Learner
1

votes
1

answer
78

views

What is the right way to test for equality between a Python variable and a callable? [duplicate]

This question already has an answer here: How does python compare functions? 2 answers What is the right way to compare if a variable contains a callable I want? Should I use the is operator or the == operator? In the following interactive session, I define two callables, f and g. I assign one to v...
Lone Learner
1

votes
1

answer
3.3k

views

What is the definition of a non-blank character in Vim?

Launch vim. In the empty buffer, insert two lines where the first line consists of 3 spaces and the second line consists of hello world. Here is an example file where the spaces are represented with dots. ... hello world Now press gg. The cursor moves to the third space of the first line. Quoting :h...
Lone Learner
1

votes
1

answer
834

views

Why doesn't the gdb -s option load the symbol file?

I am trying to create a core dump and analyze it with gdb. This is the code I wrote to create a core dump. #include void bar() { char *p = (char *) 123; std::cout
Lone Learner
1

votes
1

answer
180

views

Simplified visitor pattern

Here is a visitor pattern implemented in Java to evaluate an expression like (1 + 2) + 3. The code here is inspired by the code example at: https://en.wikipedia.org/wiki/Visitor_pattern#Sources. interface Node { public int accept(Visitor v); } class ConstantNode implements Node { public int constant...
Lone Learner
1

votes
1

answer
26

views

Why does field splitting of WORD not occur in `case WORD in` statement when WORD is a variable?

Shell script: #!/bin/sh a='foo bar' case $a in 'foo bar') echo case 1 ;; esac case foo bar in 'foo bar') echo case 2 ;; esac Executing this with bash leads to the following output and error. case 1 foo: line 10: syntax error near unexpected token `bar' foo: line 10: `case foo bar in' Executing...
Lone Learner
1

votes
2

answer
239

views

How to avoid duplication in Makefile targets with similar recipes?

I have a Makefile which has a lot of targets and the recipe for each target is quite similar. foo: gcc foo.c -o foo mv foo ~/bin bar: gcc bar.c -o bar mv bar ~/bin baz: gcc baz.c -o baz mv baz ~/bin I would like to avoid all this duplication. I would like to have something like below (this is not va...
Lone Learner
2

votes
1

answer
1.4k

views

Split strings but preserve delimiters in the array of splits

Given a string like the following in JavaScript var a = 'hello world\n\nbye world\n\nfoo\nbar\n\nfoo\nbaz\n\n'; I want to split it into an array like this ['hello world', '\n\n', 'bye world', '\n\n', 'foo\nbar', '\n\n', 'foo\nbaz', '\n\n']. If the input is var a = 'hello world\n\nbye world', the res...
Lone Learner
18

votes
1

answer
6.4k

views

How to express multiple types for a single parameter or a return value in docstrings that are processed by Sphinx?

Sometimes a function in Python may accept an argument of a flexible type. Or it may return a value of a flexible type. Now I can't remember a good example of such a function right now, therefore I am demonstrating what such a function may look like with a toy example below. I want to know how to wri...
Lone Learner

View additional