I'm trying to save a python file that I loaded into my IPython notebook with the %loadpy magic. When I try and save the file with %save settings.py I get the following error:
File `settings.py` exists. Use `%save -f 'settings.py' -f` to force overwrite
Then when I use %save -f 'settings.py' -f I get the error:
'-f' was not found in history, as a file, url, nor in the user namespace.
%save -f 'settings.py' yeilds the error '' was not found in history, as a file, url, nor in the user namespace. as well.
Any idea how to correctly save a .py file so that it overwrites the previous version? Thanks!
In [13]: %save -f settings.py 1-10 # saves lines 1 to 10 to settings.py
In [14]: %save? # Gives you the help on the save command
Usage:
%save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
n1-n2, n3-n4 are ranges of lines that you want to save. n5, n6 are individual line numbers that you want to save. Add -f option to force save.
Related
I am trying to concatenate two video files using ffmpeg, and I am receiving an error.
ffmpeg -f concat -safe 0 -i list.txt -c copy concat.mp4
And the error output I receive is....
[concat # 0x7ff922000000] Line 1: unknown keyword '43.mp4'
list.txt: Invalid data found when processing input
It looks like that the file names in the list have to be specially formatted to look like:
file '/path/to/file1.wav'
with a word file included. I spent a lot of time trying to guess why ffmpeg encountered an error trying to read the file names. It didn't matter if they were in the list or in the command line. So only after I utilized a command
for f in *.wav; do echo "file '$f'" >> mylist.txt; done
to make list from ffmpeg's manual I had success. The only difference was an additional word file.
Here you can read it yourself: https://trac.ffmpeg.org/wiki/Concatenate#demuxer
I'm trying to use MATLAB to write a text file in a folder other than "current folder" in UBUNTU. This folder is located in home directory so there would be no permission problem. I'm using the code that is shown below:
folder = '~/newFolder';
s1=fopen(folder,'newText.txt','w');
fprintf(s1,'hi')
fclose(s1);
But when I run the program, it shows invalid permission error. It would worth to mention that I've no problem when I try to write the text in the current folder. I also tried chmod 0777 -R ~/newFolder to modify the permission with no success.
What shall I do?
Thanks
If you take a look at to the fopen in Matlab documentation, you see that the second input argument in permission (that is related to the own function NOT your OS):
fileID = fopen(filename)
fileID = fopen(filename,permission)
But you are passing the filename as a second parameters.
you need to concatenate filepath and filename :
s1=fopen(strcat(folder, 'newText.txt'),'w');
I am using PDFtk (Version 2.02, UNIX) for merging PDF and facing below problems in the output PDF:
Initial View of the PDF is changed (should open with Bookmarks Panel and Page)
Bookmarks doesn’t point to the exact linked section as in the separate PDFs (shows fit page of the section)
Original metadata is lost (should retain first PDF's metadata)
Please suggest any workaround for the above points.
Regards,
Umesh
It's a little late to answer, but I came across this question while looking for a solution to the same problem. After taking a look at the man of pdftk I found a solution and I made a little script:
#!/usr/bin/env bash
# pdfcat
array=( $# )
len=${#array[#]}
merged=${array[$len-1]}
pdf2merge=${array[#]:0:$len-1}
pdftk $1 dump_data output metadata
pdftk $pdf2merge cat output $merged
pdftk $merged update_info metadata output out
mv out $merged
rm metadata
exiftool $merged
The script save the metadata of the first PDF file (first argument) and write it to a file called metadata. Then it uses the cat command of pdftk to merge all the files (the output file is the last argument). Finally it loads metadata's content to the metadata of the resulting file before erasing metadata. The last line uses exiftoolto print the metadata of the resulting file in order to check if everything went well.
You can save this script to your home/username/bin directory, make it executable with:
$ chmod u+x scriptname
and then you can use it to merge files with the following syntax:
$ scriptname 1.pdf 2.pdf 3.pdf output.pdf
The resulting output.pdf will have the same metadata as the original 1.pdf file.
I'm using wget in a cron job to fetch a .jpg file into a web server folder once per minute (with same filename each time, overwriting). This folder is "live" in that the web server also serves that image from there. However if someone web-browses to that page during the time the image is being fetched, it is considered a jpg with errors and says so in the browser. So what I need to do is, similar to when Firefox is downloading a file, wget should write to a temporary file, either in /var or in the destination folder but with a temporary name, until it has the whole thing, then rename in an atomic (or at least negligible-duration) step.
I've read the wget man page and there doesn't seem to be a command line option for this. Have I missed it? Or do I need to do two commands in my cron job, a wget and a move?
There is no way to do this purely with GNU Wget.
wget's job is to download files and it does that. A simple one line script can achieve what you're looking for:
$ wget -O myfile.jpg.tmp example.com/myfile.jpg && mv myfile.jpg{.tmp,}
Since mv is atomic, atleast on Linux, you get the atomic update of a ready file.
Just wanted to share my solution:
alias wget='func(){ (wget --tries=0 --retry-connrefused --timeout=30 -O download_pkg.tmp "$1" && mv download_pkg.tmp "${1##*/}") || rm download_pkg.tmp; unset -f func; }; func
it creates a function that receives a parameter "url" to download the file to a temporary name. If it is successful, it is renamed to the correct filename extracted from parameter $1 with ${1##*/}. and if it fails, deletes the temp file. If the operation is aborted, the temp file will be replace on the next run. after all, unset -f removes the function definition as the alias is executed.
I am trying to build the following services:
Change type of image, result in the same folder (image.jpg => image.jpg + image.png)
Change size of image, result in the same folder (image.jpg => image.jpg + image-800x600.jpg)
I am stuck on part where the original image is duplicated in the same folder, under a different name (the copy finder item workflow requires a hard coded destination or other option I am not familiar with).
Maybe I could use a shell script to perform the duplicating part. I know how to get the file paths passed to the run shell script workflow, but I can't figure out how to send valid paths out to the next task (change type or resize).
MAC OS version is Mountain lion 10.8.2.
You can duplicate the files before you scale them:
on run {input}
set newFiles to {}
repeat with aFile in input
tell application "Finder" to set myFile to duplicate aFile
set end of newFiles to myFile as alias
end repeat
delay 1
return newFiles
end run
You can add another AppleScript at the end to deal with the files names:
on run {input}
repeat with myFile in input
tell application "System Events" to set oldName to myFile's name
set newName to do shell script "echo " & quoted form of oldName & " | sed -E 's/ ?copy ?[0-9?]*//'"
tell application "System Events" to set myFile's name to newName
end repeat
end run