Hard link to a file not working as expected on OS X - json

I've a file in a folder and I don't know anything about this file (how it's generated and updated) because it comes from an application running on my system of which I don't have the source code.
The file format is clearly json and I successfully created an hard link to it (using the shell command ln file hardLinkToFile) and placed it on another directory.
At this point I check the "2" files and they are exactly the same as expected, but when I perform an action in the application that cause an update of the original file the hard link doesn't get updated.
Any idea on how I can solve this problem?
UPDATE: As pointed out by both Vlad Lazarenko and mvds the file probably get deleted and a new one is created, is there something I can do to obtain a solution equivalent to the hard-link one I thought initially about?

If a hard link is not getting updated, it means that application is removing the old file and creates a new one. Thus, you still have a hard copy of the previous file, but new file has a totally different inode, though path is still the same. You can verify it simply by changing the content of that file yourself - the link should get updated.

I am getting the same behavior in TextEdit, but not in TextMate. I would suspect this is due to the revision control built in to OS X Lions document architecture. TextEdit uses versioning, while TextMate does not. Most likely this function replaces the file instead of changing it, as described by #Vlad Lazarenko.

#Vlad and Francesco. It's really in this way. I verified that vi leaves the inode unchanged and the src and dest file are both changed, while e.g. the kate editor doesn't and I was getting mad to understand why the changes I made in the src file weren't also in the dest file.
You can easily check this with the command ls -li srcfile destfile before editing one of them with each editor I mentioned.
By the way it's not nice that the hard link are application dependent

I guess it is a bit too late...
Anyways, accidentally I found that, if you change the default app for the file, the hard link gets separated from original file. Even if you click on change all and do not relate to that specific file.

Related

How to set silent_functions(1) as default in Octave? [duplicate]

I'm new to octave, and want to run a few commands on startup automatically every time it opens.
I typed "help startup" and saw "Octave uses the file ".octaverc". I did a bit of searching online at https://www.math.utah.edu/docs/info/octave_4.html, and saw the .octaverc file should be in the following path:
OCTAVE_HOME/lib/octave/VERSION/startup/octaverc
PROBLEM:
In that directory I don't have a startup folder, only "oct" and "site". I do see hidden files, which was my first thought since the file begins with "." character. So I then used Agent Ransack in the directory, and still nothing came up.
QUESTION:
1) Do I have to make the startup folder and octaverc file myself?
2) If so, does one, both or none have to be hidden?
3) Can it be a txt file, or does it have a special extension?
4) Do I just type the commands straight into the file or is there special formatting?
NOTE:
In case I'm going about this the wrong way, there are the operations I'd like to have run on startup:
PS1('>> '), addpath('D:\Users\Me\Desktop'), clc
Thanks ahead of time for the help!!
Possible locations (and their differences) for octaverc files are specified in the documentation.
In short, these are, from more general to specific:
octave-home/share/octave/site/m/startup/octaverc (most generic, for entire system)
octave-home/share/octave/version/m/startup/octaverc (to cover for more than one octave versions installed on the system, possibly requiring different startup scripts)
~/.octaverc (where ~ is unix-speak for a user's home directory -- covering for user-specific startup files)
.octaverc files in any directory, creating specific startup conditions for specific directories
octaverc files are effectively simple script files that are executed from most generic to most specific each time octave starts. Therefore, in the presence of conflicting commands, the more specific file can effectively be used to override the more generic behaviour.
Octave also supports (but does not recommend) the use of the startup.m file, for matlab compatibility.
You might also want to check out pathdef and savepath as well.
As a more general tip, if you ever want to search for a specific keyword from the documentation (e.g. octaverc), you can type this kind of search query in duckduckgo (or google):
octaverc site:https://octave.org/doc/interpreter/
(or just download the documentation as pdf and search the pdf)
Found the solution, the file was in the following path:
OCTAVE_HOME/share/octave/site/m/startup
to find out where OCTAVE_HOME is for you, just type "OCTAVE_HOME" into your Octave command line window.
ANSWERS:
1) You do not have to make a startup octaverc file yourself
2) The file is actually not hidden, so it should be easy to find given you're looking in the right place.
3) The file doesn't have an extension. It's just octaverc.
4) Under the last line of the existing file, you can just append commands as you would type them at the Octave command line window.
the last(7.3.0) octave version placed HERE:/ does not find the THERE:/openEMS/matlab directory even it is already loaded with octaverc or addpath. It keeps looking into the work dir where openEMS is not placed and does not recognize, for instance, the 'physical_constants.m' file.

Batch file doesn't work properly unless I'm watching it

I've searched for a solution to my issue, but it's strange and I can't exactly figure out where it's going wrong.
I have a batch file that seems pretty straightforward. In a directory that has two files, it's supposed to delete one, copy the other, then rename it to what the file just deleted was named. Everything seems to work properly except for the renaming. It almost appears that the script runs twice, but I can't find any actual evidence of this. Please see below:
SET filepath="\\server-name\directory with a space\"
SET oldFile=filename.csv
SET curFile=filename_*.csv
REM ===Delete current filename.csv===
IF EXIST %filepath%%oldFile% DEL %filepath%%oldFile%
REM ===Copy all versions of .csv files that begin with filename_ to the Archive folder===
IF EXIST %filepath%%curFile% COPY /y %filepath%%curFile% %filepath%%Archive
REM ===Rename the .csv file beginning with filename_ to filename.csv===
IF EXIST %filepath%%curFile% RENAME %filepath%%curFile% %oldFile%
If I run this manually, it appears to work fine. However, when I let it be called from a Scheduled Task, it appears to run twice... that is, it deletes the filename.csv, copies the filename_*.csv to the correct place, but then seems to delete the second file rather than rename it.
As I said, I'm really unclear on what is actually being done. I've tried logging the results in an output file, but there isn't anything helpful within.
Can anyone see anything I'm missing?
Thanks in advance.
Examine
IF EXIST %filepath%%curFile% COPY /y %filepath%%curFile% %filepath%%Archive
Note that archive appears to have a leading % - is this meant to be a directory "archive" or is archive set to something you're not showing us and therefore it should be ...%filepath%%Archive%
The consequence of the (?missing/stray %) is that the file would be copied to a file named archive or to a directory named archive if that directory already exists.
Personally, I'd use
SET "filepath=\\server-name\directory with a space"
where the quotes delimit the string to be assigned (so no stray trailing spaces are assigned to the variable) and then construct the source/destination names using "%var1%\%var2%" which ensures no double-" appear and the directory is obvious (but this is a matter of style).
It is a best practice to quote paths. In this case, where a space is involved, it is a requirement. It is easier to omit quoting from the varaiable definition and provide them where needed when the variable is used.
SET filepath=\\server-name\sharename\directory with a space\
IF EXIST "%filepath%%oldFile%" DEL "%filepath%%oldFile%"
In my experience, it is best to leave the directory at the end of a path without the trailing backslash. Also, a UNC path should have a sharename.
SET "filepath=\\server-name\sharename\directory with a space"
IF EXIST "%filepath%\%oldFile%" (DEL "%filepath%\%oldFile%")
I've finally discovered the solution to this. Turns out there was a copy of the task running on an older server that our new environment had been migrated from. It was running at the exact same time as the one on the new server, which is why it would run perfectly fine any way I tried to run it before or after the time the task was set to run. Disabling the old version of the task resolved the issue.
Thank you to those who provided feedback and suggestions on my commands!

Files not under caret on new computer

I opened my project on another computer, and the files where I'd been using a file watcher were expanded, like before they used to be nested like home.scss is now after I run the watcher once on that file.
Is there a way to automatically make all the files be nested?
Because when adding new files and folder with git, it would be quite troublesome to go into each and every file in order to make them become nested.
Like I have some minified JavaScript files that used to be nested, but now is expanded for some reason.
Hope you understand. Thank you.
Edit: Nested***
Is there a way to automatically make all the files go under a caret like that?
Unfortunately not. Such nesting information (to "go under a caret" as you are saying) is taken from "Output path to refresh" field of the corresponding File Watcher.
You have to run file watcher for such files at least once in order to see files nested like you have it on your another computer.
Here is how you can run File Watchers manually without the need to modify those files (so no extra history will appear in your git (or whatever VCS you may be using there)).
https://stackoverflow.com/a/20012655/783119
P.S.
In PhpStorm 2016.3 (the next version that will be released in 1.5-2 months or so) such nesting will be done automatically (the most common combinations) so there will be no need to have File Watchers for providing such info.
If you wish -- you can try EAP build right now (EAP means Early Access Program .. which is sort of Alpha/Beta builds (simply speaking).. and therefore some bugs for new functionality might be present and performance may not be optimal).

Unreadable Notebook NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)

Getting this very strange error when I am trying to load my ipython notebook. Never had it before, and I cannot to my recollection, remember having done anything silly with ipython:
Unreadable Notebook: /path/to/notebooks/results.ipynb NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)
which is followed by
400 GET /api/contents/results.ipynb?type=notebook&_=1440010858974 (127.0.0.1) 36.17ms referer=http://localhost:8888/notebooks/results.ipynb
Save yourself a headache. Open your .ipynb in any online JSON validator and it will tell you which lines have issues. I used this one.
In my case, I am using GitHub to save and share my ipython files with my teammate. When there is a conflict in the code, I had to delete those lines indicating the changes in the conflicting code such as:
>>>>>>>>head
=============
and It works for me.
This happened to me as well. I opened my data.ipynb file using notepad and found out it was blank.
I managed to recover my file by going into the hidden ipynb_checkpoints folder and copying data_checkpoint.ipynb out into my working directory.
In my Mac OS terminal
cd .ipynb_checkpoints
cp data-checkpoint.ipynb \..
Thankfully the codes were preserved. Hope this helps!
I just had the same issue after upgrading from IPython 0.13 (ish) to Jupyter 4.
The problem in my case were a few rogue trailing commas in the JSON, for example the comma following "outputs" in:
...
"language": "python",
"metadata": {},
"outputs": [],
},
After removing the commas, Jupyter/IPython could again read the notebook (and upgraded it to version 4). I hope this helps.
The easiest way to recover corrupted Jupyter notebook files, whether it contains text or not (size = 0KB), is to go to the project folder and display the hidden files. Once the hidden files are displayed, you will see a folder named '.ipynb_checkpoints'. Simply open this folder and take the file you want!
Visual studio code procedure
This is my procedure that usually avoids me groping in the dark.
I installed a json parser validator like this one.
Open the file and save a copy as .json file.
Open the json and look for the errors.
Save it back to the .ipynb extension.
Usually, I manage to fix the errors quickly.
Jupyter autosaves in a specific way. It means You have accidentally closed the notebook before properly saving it.
You need to look for three things -
Search for <<<<<<< and delete those lines.
Search for ====== and replace those lines with ,.
Search for >>>>>>> and delete those lines.
It will work fine after this.
this can be changed to reformat your ipynb file to readable in jupyter notebook. check your other ipynb files(open in notepad) which are working fine with your jupyter notebook, check and compare at the end of the files in notepad. there you can reformat the file which is not working.
I had this issue from accidentally saving as .txt from github and solved by deleting .txt (leaving .ipynb instead of .ipynb.txt when downloading)
Yes, the best solution for me was I saved my notebook in HTML format, then opened it in Notepad ++ , delete the long repeated lines of output which were causing my notebook to grow to 45MB, once that cleared, Saved the file back into (.ipynb) format , and was able to opened it with no JSON error.
Hope that worked for others as well!
Got this error after conflicts while pushing my code to Github. The code present on the repo was old, and my changes were stashed. Notebook wasn't opening in either Jupyter and github repo. Following above comments, I searched for the part in my code which was giving JSON error,i.e. '<<<<<<<<<<<', '=======' and '>>>>>>>>>>' characters using an online json parser. Then I opened my .ipynb notebook in notepad++ and manually replaced these characters with blank string ''. After this, the notebook opened on my local Jupyter, and I also pushed the changes to Github.
I have changed by ipynb file encoding from UTF-8-BOM to UTF-8, and then it worked.
My native language is not English, but because this problem helped me a part, I came to feedback my solution.
The following is translated with translation software:
Fundamentally, the file format is messed up due to wrong closing. When opening, the correctness of the json format will be checked first, and an error will be returned if it is found to be wrong.
The mess in my file format is not <<<<< or ====== but the lack of commas.
Either way, it's best to use a piece of software to detect errors in the json syntax, and then manually fix it yourself.
The json website detection provided by the highest praise is available, but the detection errors are not complete, and may need to be detected-modified-detected-modified.
Also use vscode to open the file, vscode will prompt the location of the json syntax error, which is also incomplete and needs to be checked and modified multiple times.
The error location provided is more difficult to find. I use nodepad++, and the lower right corner can display how many characters are selected (standard, including line breaks). Then select from the first character until the destination position.
Although it's a bit stupid, the main reason is that I didn't find the relevant positioning method.
Clear all outputs.
Then copy the notebook.
If you use Jupyter-Notebook in VS code, just save it in VS code, close the file and try to open it again by accessing the browser.
on ubuntu 20.04, I have file String.ipynb. I had same problem because I coded ơ [ echo 'hello' >> String.ipynb ]. deleting 'hello' in String.ipynb -> I could open my notebook like normal.
how did I delete? [ nano String.ipynb ] * move to last line (hello) * -> delete it.
I hope my answer help you :D
you will see this error may be because, you were getting merge conflict in .ipynb file. because of that git adds >>>>>>>> HEAD thing in .ipynb file which makes is unreadable.
To overcome this issue open .ipynb file in vim editor and then remove the incoming changes or your changes as per your use case.
vim <your-.ipynb-file-path>
To remove incoming changes remove content between these lines<<<<<<<<<< HEAD ==============. Note:- remove this line as well >>>>>>>>>>>> this line.
to remove your changes remove content between these lines ============== >>>>>>>>>>>. Note:- remove this line as well a <<<<<<<<<< HEAD
I had the same issue after git merge while using VS Code and Jupyter extension.
VS Code would not open the notebook after the merge conflicts were highlighted in the notebook JSON by git (e.g. <<<<<). One way around it was to highlight the changes and accept one by one using the file viewer in the VSCode git interface.
Alternative that worked for me was to rename the file to .json so that it would open and then search for each instance of <<<<< and accept the incoming change.

Verify a Tif with ApprovalTests

I have been asked to update a system where header information gets injected into a tif via a 3rd party console application. I don't need to worry about that bit.
The part I have been asked to look at it the merge process that generates the header information.
The current file generated by the process is assumed as correct, before I make any changes, so I want to add this as an approved result, from that I can then check that the changes I make will alter the file as expected.
I thought this would be a good opportunity to look at using ApprovalTests
The problem I have is that for what ever reason the links to the videos are considered corruptible (Possibly show me kittens jumping into boxes or something, which will stop me working, which ironically means I slow down my work done because I cannot see any help videos).
What I have been looking at is the Approvals.Verify and Approvals.VerifyFile extensions.
But what appears to be happening is confusing me.
using VerifyFile creates a received file, but the contents of the file are just a line the name of the file I have asked it to verify.
using Verify(new FileInfo("FileNameHere")) does not appear to generate the received file that I need to flag as approved, but the test does return saying that it cannot find the approved tif file.
I am probably using VerifyFile completely wrong and might be looking at using Verify wrong as well.
useful info?
Might be useful to know, that as this is a legacy application, running as a windows service, I have wrapped the service in a harness that allows me to call the routines, so the files are physically being written elsewhere on the machine outside of my control (well there is a config, but the return of the service I call generates a file in a fixed location if it is successful). I have tried copying that into the Unit Test project, but that doesn't appear to help.
Verify(File) and VerifyFile(string) are both meant to verify an existing file. As such they merely setting the received file to the file you pass in. You will still need to move/approval/create the approved file.
Here is the pseudo code and process.
[UseReporter(typeof(DiffReporter), typeof(ClipboardReporter)]
public void TestTiff()
{
string tif = YourProcessToCreateTifFile();
Approvals.VerifyFile(tif);
}
[Note: if you don't have an image diff installed, like TortoiseDiff, you might want to use the FileLauncherReporter]
Run this, once you get the result, move the file over by pasting your clipboard into a cmd window.
It will move the temporary tif to your test directory with the name ClassName.TestTiff.approved.tif
After that the test should pass until something changes.
Happy Testing!