Emacs: run shell command with regex and Lisp function to start gud

I am tring to write some Emacs Lisp function to be able to simply compile and debug Java classes within Spacemacs using its Java layer (don’t want to go into complex packages like jdee). The compile function is defined beblow and works as expected

(defun my-java-compile (command)
  (interactive (list (read-string
                      "Command: "
                      (concat
                           "javac"
                       " -d "
                       java-dest-path
                       " -cp "
                       java-class-path
                       " "
                       (file-name-nondirectory buffer-file-name)))))
  (unless (file-exists-p java-dest-path)
    (make-directory java-dest-path))
  (compilation-start command nil)
  )

The java-dest-path and java-class-path are local variables set in the .dir-locals.el in the root directory of the project.

The debug function is defined as:

;; get fully qualified class name
(defun get-fqcn ()
  (setq get-package-name-command
        (concat
         "gsed -n 's/^packages+([^;s]+);s*$/1/p' "
         buffer-file-name))
  (setq fqpn (shell-command-to-string get-package-name-command))
  (if (equal "" fqpn) (file-name-base buffer-file-name)
    (concat fqpn "." (file-name-base buffer-file-name)))
  )

(defun my-jdb (command)
  (interactive (list (read-string
            "Command: "
            (concat
              "jdb"
              " -classpath "
              java-class-path
              " "
              (get-fqcn)))))
  (helm-M-x nil jdb command)
  )  

I still trying to make it work. Here are the two issues:

  1. when running shell-command-to-string function, the gsed -n
    's/^packages+([^;s]+);s*$/1/p' java_file
    returns an empty
    string "", while it returns the fully qualified package name as
    expected when running in a terminal. If I change the it to gsed -n '/^package/p', the emacs function return the package line OK. So
    it seems shell-command-to-string could not handle the regular
    expression in gsed. Any work around?
  2. I could not find the function to trigger the gud or jdb . What would be the gud equivalent of compilation-start function?

RobotC startMotor command useless?

I learned recently that robotc has a command called startMotor. it has two parameters, a motor and a speed, and it sets the motor to the speed.

But the same thing can be accomplished in one line like this:

motor[desiredMotor] = desiredSpeed;

the above line is perfectly readable, and doesn’t push a whole new frame to the call stack. Why would anybody choose to use startMotor in this case?

Error when sending second start command to Cylon.js to blink LED

Using Node.js, express and cylon.js, I’m getting a post request and blinking an LED using a raspberry Pi. I receive the first post request fine, the code runs and the LED blinks. However on the second post request I receive an error:

events.js:146
      throw err;
      ^

Error: Uncaught, unspecified "error" event. (Error occurred while writing value 1 to pin 23)
    at DigitalPin.emit (events.js:144:17)
    at DigitalPin. (/home/pi/tech-corner/devTracker/node_modules/cylon/lib/io/digital-pin.js:70:12)
    at fs.js:1134:21
    at FSReqWrap.oncomplete (fs.js:82:15)

Note that in the code below I’m using pin: 16. So I’m confused as to why it’s trying to write to pin 23.

var express = require('express')
var bodyParser = require('body-parser')
var app = express()
var Cylon = require('cylon')

var pi = Cylon.robot({
  connections: {
    raspi: { adaptor: 'raspi' }
  },

  devices: {
    led: { driver: 'led', pin: 16 }
  },

  work: function (my) {
    after((1).second(), function () {
      console.log('Post request recieved! Toggle the LED')
      my.led.toggle()
    })

    after((2).second(), function () {
      my.led.toggle()
    })

    after((5).seconds(), function () {
      console.log('I'm shutting down now.')
      pi.halt()
    })
  }
})

app.set('port', process.env.PORT || 1337 - 1)

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

app.post('/', function (req, res) {
  console.log(req.body.user_name)

  pi.start()

  res.end('Hello')
})

app.listen(app.get('port'), function () {
  console.log('Node app is running at http://localhost:' + app.get('port'))
})

Any help greatly appreciated. I assume my raspberryPi set-up is fine since it works on the first hook.

EDIT: Incase anyone comes across this and has a similar problem. I decided to go with pigpio which was a lot easier.

Spatialite: command not found on CentOS 7

I’ve installed Spatialite on CentOS 7 using this procedure:

1) SQLite installation

wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar -xzf sqlite-autoconf-3240000.tar.gz
cd sqlite-autoconf-3240000
./configure
make
sudo make install
sudo ldconfig
cd ..

2) Proj installation

wget http://download.osgeo.org/proj/proj-5.1.0.tar.gz
tar -xzf proj-5.1.0.tar.gz
cd proj-5.1.0
./configure
make
sudo make install
cd ..

3) Geos installation

wget http://download.osgeo.org/geos/geos-3.7.0.tar.bz2
tar -xjf geos-3.7.0.tar.bz2
cd geos-3.7.0
./configure
make
sudo make install
sudo ldconfig
cd ..

4) Freexl installation

wget http://www.gaia-gis.it/gaia-sins/freexl-sources/freexl-1.0.5.tar.gz
tar -xzf freexl-1.0.5.tar.gz
cd freexl-1.0.5
./configure
make
sudo make install
sudo ldconfig
cd ..

5) Spatialite installation

wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.3.0a.tar.gz
tar -xzf libspatialite-4.3.0a.tar.gz
cd libspatialite-4.3.0a
./configure --enable-geocallbacks
make
sudo make install
sudo ldconfig
cd ..

Then I’ve created the directory /var/www/sqlite3_ext and copied in the mod_spatialite.so file

sudo mkdir /var/www/sqlite3_ext
sudo cp /usr/local/lib/mod_spatialite.so /var/www/sqlite3_ext

Modified /etc/php.ini from

default php.ini:
[sqlite3]
;sqlite3.extension_dir =

to

updated php.ini:
[sqlite3]
sqlite3.extension_dir = /var/www/sqlite3_ext

And finally restart apache

sudo systemctl restart httpd

Testing my PHP binding all works fine (using the test code published here http://www.gaia-gis.it/gaia-sins/spatialite-cookbook/html/php.html).

But if I try to get the spatialite command from command line I obtain

Spatialite: command not found

Probably something is missing in my Spatialite installation but I don’t know what … any suggestions will be appreciated.

Drush command results in segmentation fault

Every drush command including drush help and drush status errors out with a Segmentation fault. This is happening only when Memcache API and Integration is enabled. Any fix for the issue or Memcache API and Integration will not work with drush. Please note, the Drupal application has no issues when accessed through the web.

Linux: Amazon Linux

PHP Version: PHP 7.1.23 (cli) (built: Oct 16 2018 23:39:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.23, Copyright (c) 1999-2018, by Zend Technologies

Drush version: 9.5.2

Drupal version: 8.6.2

PECL Memcache: 3.0.9

PECL Memcached: 1.0.16 (libmemcached)

Memcache API and Integration version: 8.x-2.0

Memcache Configuration (settings.php)

// Memcache Configuration
$settings['memcache']['servers'] = [
    ':11211' => 'default',
];
$settings['memcache']['key_prefix'] = 'dr8';
if (isset($settings['memcache']['servers'])) {
  // Memcache settings
  $settings['cache']['bins']['bootstrap'] = 'cache.backend.memcache';
  $settings['cache']['bins']['discovery'] = 'cache.backend.memcache';
  $settings['cache']['bins']['config'] = 'cache.backend.memcache';
  $settings['cache']['bins']['render'] = 'cache.backend.memcache';
  $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.memcache';
  // Use memcache as the default bin
  $settings['cache']['default'] = 'cache.backend.memcache';
}

Ref:
https://www.drupal.org/project/memcache

Setting and getting Windows environment variables from the command prompt?

I want to set an environment variable from the command prompt and then be able to access it globally (for instance, I should see it by going to System -> Environment Variables).

When I use the set command, it isn’t accessible in a new cmd session.

set NEWVAR=SOMETHING
echo %NEWVAR%

Related questions:

  • Is there any command line tool that can be used to edit environment variables in Windows?
  • Setting multiple environment variables in a shell spawned via windows batch script

golf-me: your new command-line code-golf companion!




Golf-me is a quick and dirty terminal application you can use to pick out a programming puzzle from Stack Exchange’s Programming Puzzles & Code Golf site.

Screenshots

Screenshot 1

Screenshot 2

About

I built golf-me because I wanted a quick command-line way to select a challenge that I felt like doing.

License

MIT.

Download

golf-me is available on npm: npm install golf-me

Platform

golf-me was developed on Ubuntu Linux, but it should work on other *nix platforms and Windows.

Contact

My name is John. You can connect with me on github @microwaveabletoaster, twitter @drdikeman, and of course on here @microwaveabletoaster.

Code

golf-me is written primarily in CoffeeScript using node. You can find the source code on Github.

split multiple panes and ssh into server, run command, launch logs

I am running Ubuntu 18.04.1 and am trying to achieve the following.

I open my terminal and boot up tmux. I then run my bash script to split the window into 4 different panes. i then select each individual pane and ssh into a server, cd into a directory, launch a program, then tail the logs for said program.

Here’s an example of what my bash script looks like.

tmux rename-window ‘Logs’;

tmux split-window -h;

tmux split-window -v ;

tmux select-pane -t 0;

tmux split-window -v ;

tmux select-pane -t 0 ;

tmux send-keys ‘ssh user@server.com’ enter ;

tmux send-keys ‘p@sw0rd’ enter ;

tmux send-keys ‘cd dir/’ enter ;

tmux send-keys ‘./program/’ enter ;

tmux send-keys ‘tail -f logs/program.log’ enter ;

again, i do this for each pane. When the script ends. The panes are successfully split and all 4 panes show the following.

bashFolder:$ ./tmuxBash (this line is only shown on the original pane)

ssh user@server.com

p@sw0rd

cd dir/

tail -f logs/program.log

me@laptopname:~home/bashFolder$ ssh user@server.com

user@server.com’s password:

then all 4 panes are still expecting the password i tried to send after the initial ssh call.

This bash was working on a windows machine running linux through a VM (vagrant). I am not sure if I broke the script before I moved onto a linux box.

I appreciate any help, and my apologies for the format, this is my first post.