remove "-" of the file names in emacs dired mode - emacs

I want to remove "-" of the file names in editable dired mode
below is the text
-rw-r--r--+ 1 dayua mkpasswd 663 Nov 14 18:11 Add-Binary.py
-rwxr-xr-x+ 1 dayua mkpasswd 799 Nov 14 18:11 add-two-link-list.py
-rw-r--r--+ 1 dayua mkpasswd 571 Nov 14 18:11 Anagrams.py
-rwxr-xr-x+ 1 dayua mkpasswd 1041 Nov 14 18:11 Balanced-Binary-Tree.py
-rwxr-xr-x+ 1 dayua mkpasswd 1241 Nov 14 18:11 Best-profit-III.aux.py
-rwxr-xr-x+ 1 dayua mkpasswd 830 Nov 14 18:11 Best-Time-to-Buy-and-Sell-Stock-II.py
-rwxr-xr-x+ 1 dayua mkpasswd 1605 Nov 14 18:11 Best-Time-to-Buy-and-Sell-Stock-III.py
-rw-r--r--+ 1 dayua mkpasswd 5323 Nov 20 14:48 Binary-Search-Best-Practice.py
please give some suggestions.

Short answer: after entering dired editable mode (aka wdired) go to the beginning of the buffer and do M-% - RET RET !
M-% is the shortcut for query-replace; it will prompt what you want to be replaced (-) and by what (empty string), then it will put you in interactive mode, where key ! tell it to replace all occurrences.
wdired will deal properly (innore when replacing) the "-" characters at the permissions part for the dired listing.

My first instinct, especially if this will only be a one-time update, is to record a keyboard macro.
C-x ( ; to begin macro
C-e ; to end of line
M-<space> ; mark beginning of region
C-r : ; search backward to time delimiter (:)
M-x replace-string - <blank> ; replace - with nothing
C-a ; beginning of line
C-n ; next line
C-x ) ; end macro
Then it's merely a matter of repeating the macro until completed
C-x e
If you have a lot of lines, you can prefix the macro call with the number of times to repeat (50 in this example)
<ESC> 50 C-x e
I'd be very interested in learning of any regex solutions to this problem!

Related

How to convert alphabets to numerical values with spaces and return it back to alphabets?

Want to convert the alphabet to numerical values and transform it back to alphabets using some mathematical techniques like fast Fourier transform in MATLAB.
Example:
The following is the text saved in "text2figure.txt" file
Hi how r u am fine take care of your health
thank u very much
am 2.0
Reading it in MATLAB:
data=fopen('text2figure.txt','r')
d=fscanf(data,'%s')
temp = fileread( 'text2figure.txt' )
temp = regexprep( temp, ' {6}', ' NaN' )
c=cellstr(temp(:))'
Now I wish to convert cell array with spaces to numerical values/integers:
coding = 'abcdefghijklmnñopqrstuvwxyz .,;'
str = temp %// example text
[~, result] = ismember(str, coding)
y=result
result =
Columns 1 through 18
0 9 28 8 16 24 28 19 28 22 28 1 13 28 6 9 14 5
Columns 19 through 36
28 21 1 11 5 28 3 1 19 5 28 16 6 28 26 16 22 19
Columns 37 through 54
28 8 5 1 12 21 8 28 0 0 21 8 1 14 11 28 22 28
Columns 55 through 71
23 5 19 26 28 13 22 3 8 0 0 1 13 28 0 29 0
Now I wish to convert the numerical values back to alphabets:
Hi how r u am fine take care of your health
thank u very much
am 2.0
How to write a MATLAB code to return the numerical values in the variable result to alphabets?
Most of the code in the question doesn't have any useful effects. These three lines are the ones that lead to result:
str = fileread('test2figure.txt');
coding = 'abcdefghijklmnñopqrstuvwxyz .,;';
[~, result] = ismember(str, coding);
ismember returns, in the second output argument, the indices into coding for each element of str. Thus, result are indices that we can use to index into coding:
out = coding(result);
However, this does not work because some elements of str do not occur in coding, and for those elements ismember returns 0, which is not a valid index. We can replace the zeros with a new character:
coding = ['*',coding];
out = coding(result+1);
Basically, we're shifting each code by one, adding a new code for 1.
One of the characters we're missing here is the newline character. Thus the three lines have become one line. You can add a code for the newline character by adding it to the coding table:
str = fileread('test2figure.txt');
coding = ['abcdefghijklmnñopqrstuvwxyz .,;',char(10)]; % char(10) is the newline character
[~, result] = ismember(str, coding);
coding = ['*',coding];
out = coding(result+1);
All of this is easier to achieve just using the ASCII code table:
str = fileread('test2figure.txt');
result = double(str);
out = char(result);

Arrays in J: indexing from one into another

Using J I am trying to do something similar to the following example shown on page 128 of Mastering Dyalog APL by Bernard Legrand (2009). I have not been able to find a direct conversion of this code into J, which is what I want.
Here's the example:
BHCodes ← 83 12 12 83 43 66 50 81 12 83 14 66 etc...
BHAmounts ← 609 727 458 469 463 219 431 602 519 317 663 631...
13.3.2 - First Question
We would like to focus on some selected countries (14, 43, 50, 37, and 66) and
calculate the total amount of their sales. Let’s first identify which
items of BHCodes are relevant:
Selected ← 14 43 50 37 66
BHCodes ∊ Selected
0 0 0 0 1 1 1 0 0 0 1 1 0 1 0 ⇦ Identifies sales in the selected countries only.
Then we can apply this filter to the amounts, and add them up:
(BHCodes ∊ Selected) / BHAmounts
463 219 431 663 631 421
+/ (BHCodes ∊ Selected) / BHAmounts
2828
+/ (BHCodes e. Selected) # BHAmounts
For your purposes here, APL's ∊ is J's e. (Member (In)) and APL's / is J's # (Copy).
Notes:
APL's ∊ and J's e. are not completely equivalent as APL's ∊ looks for every element in its left argument among the elements of its right argument, while J's e. looks for every major cell. of its left argument in the major cells of its right argument.
APL's / and J's # are not completely equivalent as APL's / operates along the trailing axis while J's # operates along the leading axis. APL does have ⌿ though, which operates along the leading axis. There are more nuances, but they are not relevant here.

Touchscreen on Raspberry Pi emits click not touch

i folowed this link to calibrate touchscreen: http://www.circuitbasics.com/raspberry-pi-touchscreen-calibration-screen-rotation/.
ls -la /dev/input/
total 0
drwxr-xr-x 4 root root 240 Jul 12 18:38 .
drwxr-xr-x 15 root root 3460 Jul 12 18:38 ..
drwxr-xr-x 2 root root 140 Jul 12 18:38 by-id
drwxr-xr-x 2 root root 140 Jul 12 18:38 by-path
crw-rw---- 1 root input 13, 64 Jul 12 18:38 event0
crw-rw---- 1 root input 13, 65 Jul 12 18:38 event1
crw-rw---- 1 root input 13, 66 Jul 12 18:38 event2
crw-rw---- 1 root input 13, 67 Jul 12 18:38 event3
crw-rw---- 1 root input 13, 68 Jul 12 18:38 event4
crw-rw---- 1 root input 13, 63 Jul 12 18:38 mice
crw-rw---- 1 root input 13, 32 Jul 12 18:38 mouse0
crw-rw---- 1 root input 13, 33 Jul 12 18:38 mouse1
root#raspberrypi:/sys/devices/virtual/input# cat input4/uevent
PRODUCT=0/0/0/0
NAME="FT5406 memory based driver"
PROP=2
EV=b
KEY=400 0 0 0 0 0 0 0 0 0 0
ABS=2608000 3
MODALIAS=input:b0000v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw
root#raspberrypi:~# cat /etc/ts.conf
# Uncomment if you wish to use the linux input layer event interface
module_raw input
# Uncomment if you're using a Sharp Zaurus SL-5500/SL-5000d
# module_raw collie
# Uncomment if you're using a Sharp Zaurus SL-C700/C750/C760/C860
# module_raw corgi
# Uncomment if you're using a device with a UCB1200/1300/1400 TS interface
# module_raw ucb1x00
# Uncomment if you're using an HP iPaq h3600 or similar
# module_raw h3600
# Uncomment if you're using a Hitachi Webpad
# module_raw mk712
# Uncomment if you're using an IBM Arctic II
# module_raw arctic2
module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear
I only get response when configuring X with xinput_calibrator. When i enter this command
sudo TSLIB_FBDEVICE=/dev/fb0 TSLIB_TSDEVICE=/dev/input/event1 ts_calibrate
I get optput
xres = 800, yres = 480
selected device is not a touchscreen I understand
Can someone please help me,
Thanks in advance.
I don't have a solution for this, but I believe that it is related to the problem of touches being treated as mouseovers. This bug has been reported several times, but never actually fixed
https://gitlab.gnome.org/GNOME/gtk/-/issues/945
https://bugzilla.gnome.org/show_bug.cgi?id=789041
https://bugs.launchpad.net/ubuntu-mate/+bug/1792787
A bugzilla.gnome.org user named niteshgupta16 created a script that solves this problem, but it was uploaded to pasting/sharing service called hastebin at https://www.hastebin.com/uwuviteyeb.py.
Hastebin deletes files that have not been accessed within 30 days. Since hastebin is a javascript-obfuscated service, this file is not available on archive.org.
I am unable to find an email for niteshgupta16 in order to ask him if he still has uwuviteyeb.py.

TimeGrouper, pandas

I use TimeGrouper from pandas.tseries.resample to sum monthly return to 6M as follows:
6m_return = monthly_return.groupby(TimeGrouper(freq='6M')).aggregate(numpy.sum)
where monthly_return is like:
2008-07-01 0.003626
2008-08-01 0.001373
2008-09-01 0.040192
2008-10-01 0.027794
2008-11-01 0.012590
2008-12-01 0.026394
2009-01-01 0.008564
2009-02-01 0.007714
2009-03-01 -0.019727
2009-04-01 0.008888
2009-05-01 0.039801
2009-06-01 0.010042
2009-07-01 0.020971
2009-08-01 0.011926
2009-09-01 0.024998
2009-10-01 0.005213
2009-11-01 0.016804
2009-12-01 0.020724
2010-01-01 0.006322
2010-02-01 0.008971
2010-03-01 0.003911
2010-04-01 0.013928
2010-05-01 0.004640
2010-06-01 0.000744
2010-07-01 0.004697
2010-08-01 0.002553
2010-09-01 0.002770
2010-10-01 0.002834
2010-11-01 0.002157
2010-12-01 0.001034
The 6m_return is like:
2008-07-31 0.003626
2009-01-31 0.116907
2009-07-31 0.067688
2010-01-31 0.085986
2010-07-31 0.036890
2011-01-31 0.015283
However I want to get the 6m_return starting 6m from 7/2008 like the following:
2008-12-31 ...
2009-06-31 ...
2009-12-31 ...
2010-06-31 ...
2010-12-31 ...
Tried the different input options (i.e. loffset) in TimeGrouper but doesn't work.
Any suggestion will be really appreciated!
The problem can be solved by adding closed = 'left'
df.groupby(pd.TimeGrouper('6M', closed = 'left')).aggregate(numpy.sum)
TimeGrouper that is suggested in other answers is deprecated and will be removed from Pandas. It is replaced with Grouper. So a solution to your question using Grouper is:
df.groupby(pd.Grouper(freq='6M', closed='left')).aggregate(numpy.sum)
This is a workaround for what seems a bug, but give it a try and see if it works for you.
In [121]: ts = pandas.date_range('7/1/2008', periods=30, freq='MS')
In [122]: df = pandas.DataFrame(pandas.Series(range(len(ts)), index=ts))
In [124]: df[0] += 1
In [125]: df
Out[125]:
0
2008-07-01 1
2008-08-01 2
2008-09-01 3
2008-10-01 4
2008-11-01 5
2008-12-01 6
2009-01-01 7
2009-02-01 8
2009-03-01 9
2009-04-01 10
2009-05-01 11
2009-06-01 12
2009-07-01 13
2009-08-01 14
2009-09-01 15
2009-10-01 16
2009-11-01 17
2009-12-01 18
2010-01-01 19
2010-02-01 20
2010-03-01 21
2010-04-01 22
2010-05-01 23
2010-06-01 24
2010-07-01 25
2010-08-01 26
2010-09-01 27
2010-10-01 28
2010-11-01 29
2010-12-01 30
I've used integers to help confirm that the sums are correct. The workaround that seems to work is to add a month to the front of the dataframe to trick the TimeGrouper into doing what you need.
In [127]: df2 = pandas.DataFrame([0], index = [df.index.shift(-1, freq='MS')[0]])
In [129]: df2.append(df).groupby(pandas.TimeGrouper(freq='6M')).aggregate(numpy.sum)[1:]
Out[129]:
0
2008-12-31 21
2009-06-30 57
2009-12-31 93
2010-06-30 129
2010-12-31 165
Note the final [1:] is there to trim off the first group.

Executing shell commands from Scala REPL

An interesting feature of Scala REPL is if you drop any jar in your %SCALA_HOME%\lib directory, it is available for import from the REPL. I have several jars there, and I often need to find out which ones are available to be included. So I always have to open another command window and find out which jars exist in that directory. It would be great if the REPL allowed me to execute system commands such as dir or ls or at least list all the jars in the above lib directory. What is the easiest way (if any) to invoke shell commands in REPL ?
In REPL the :sh command allow you to introduce shell command:
Windows version:
scala> :sh cmd /C dir
res0: scala.tools.nsc.interpreter.ProcessResult = `cmd /C dir` (28 lines, exit 0)
scala> res0 foreach println
(unfortunately, there is no way to avoid the call to cmd \C before the shell command)
Unix-like version:
scala> :sh ls
res0: scala.tools.nsc.interpreter.ProcessResult = `cmd /C dir` (28 lines, exit 0)
scala> res0 foreach println
Update: Inspired by Daniel's answer, a little trick for windows user:
scala> implicit def stringToDosProcess(s: String) =
scala.sys.process.stringToProcess("cmd /C "+ s)
stringToDosProcess: (s: String)scala.sys.process.ProcessBuilder
scala> "dir".!
Alternative: use Scala's sys.process library:
scala> import sys.process._
import sys.process._
scala> "ls /home/dcs/scala-2.9.1.final".!
bin
doc
lib
man
meta
misc
src
res1: Int = 0
UPDATE
The means for extracting :sh output has changed over the years.
Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_91).
Type in expressions for evaluation. Or try :help.
scala> :sh date
res0: scala.tools.nsc.interpreter.ProcessResult = `date` (1 lines, exit 0)
scala> res0 foreach println
<console>:13: error: value foreach is not a member of scala.tools.nsc.interpreter.ProcessResult
res0 foreach println
^
scala> res0.show
<console>:13: error: value show is not a member of scala.tools.nsc.interpreter.ProcessResult
res0.show
^
scala> res0.lines
res3: List[String] = List(Sat Sep 17 19:29:26 PDT 2016)
Here is a little-known trick of REPL:
Welcome to Scala version 2.10.0-20120323-101508-45eebcf98d (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> /home/dcs/scala-2.9.1.final/<TAB>
/home/dcs/scala-2.9.1.final/misc /home/dcs/scala-2.9.1.final/bin /home/dcs/scala-2.9.1.final/man /home/dcs/scala-2.9.1.final/src /home/dcs/scala-2.9.1.final/lib
/home/dcs/scala-2.9.1.final/meta /home/dcs/scala-2.9.1.final/doc
scala> /home/dcs/scala-2.9.1.final/lib/<TAB>
/home/dcs/scala-2.9.1.final/lib/scala-dbc.jar /home/dcs/scala-2.9.1.final/lib/scala-swing.jar /home/dcs/scala-2.9.1.final/lib/jline.jar
/home/dcs/scala-2.9.1.final/lib/scala-library.jar /home/dcs/scala-2.9.1.final/lib/scala-compiler.jar /home/dcs/scala-2.9.1.final/lib/scalap.jar
scala> /home/dcs/scala-2.9.1.final/lib/scala-library.jar
res0: scala.tools.nsc.io.File = /home/dcs/scala-2.9.1.final/lib/scala-library.jar
Where <TAB> is I pressing tab.
UPDATE 2018/01/15
Example: you like to see the files in the current working directory:
scala> :sh ls -l
res3: scala.tools.nsc.interpreter.ProcessResult = `ls -l` (13 lines, exit 0)
But you can't do this:
scala> res3.foreach {println}
<console>:40: error: value foreach is not a member of scala.tools.nsc.interpreter.ProcessResult
res3.foreach {println}
^
First you have to assign the lines to another type that supports iteration:
scala> res3.lines
res7: List[String] = List(total 960, -rw-r--r--# 1 dave staff 11325 Jan 3 15:01 LICENSE, -rw-r--r--# 1 dave staff 8859 Jan 3 15:01 README.rst, drwxr-xr-x# 3 dave staff 96 Jan 3 15:03 assembly, drwxr-xr-x# 20 dave staff 640 Jan 3 15:01 bin, drwxr-xr-x# 13 dave staff 416 Jan 3 15:01 doc, drwxr-xr-x# 7 dave staff 224 Jan 3 15:01 docker, drwxr-xr-x# 6 dave staff 192 Jan 3 15:03 examples, -rw-r--r--# 1 dave staff 826 Jan 3 15:01 gradle.properties, -rw-r--r--# 1 dave staff 128 Jan 3 15:04 h2o_drivers.txt, drwxr-xr-x 3 dave staff 96 Jan 16 00:54 h2ologs, drwxr-xr-x# 5 dave staff 160 Jan 3 15:04 py, -rw-r--r--# 1 dave staff 455890 Sep 19 04:18 rsparkling.tar.gz)
Then iterate, and voila!
scala> res7.foreach {println}
total 960
-rw-r--r--# 1 dave staff 11325 Jan 3 15:01 LICENSE
-rw-r--r--# 1 dave staff 8859 Jan 3 15:01 README.rst
drwxr-xr-x# 3 dave staff 96 Jan 3 15:03 assembly
drwxr-xr-x# 20 dave staff 640 Jan 3 15:01 bin
drwxr-xr-x# 13 dave staff 416 Jan 3 15:01 doc
drwxr-xr-x# 7 dave staff 224 Jan 3 15:01 docker
drwxr-xr-x# 6 dave staff 192 Jan 3 15:03 examples
-rw-r--r--# 1 dave staff 826 Jan 3 15:01 gradle.properties
-rw-r--r--# 1 dave staff 128 Jan 3 15:04 h2o_drivers.txt
drwxr-xr-x 3 dave staff 96 Jan 16 00:54 h2ologs
drwxr-xr-x# 5 dave staff 160 Jan 3 15:04 py
-rw-r--r--# 1 dave staff 455890 Sep 19 04:18 rsparkling.tar.gz