sandbox-exec file-write behaves unexpectedly - sandbox

I have a rules file like this
(version 1)
(deny default)
...
(allow file-write* (regex "/Users/thomas/Desktop"))
When I use it on app A, it works fine (the app can write to the desktop) but when used on app B, it doesn't work. So I made a test app (app C), a simple cocoa app that just writes a dummy string to a file, and it still doesn't work.
If I replace (allow file-write* (regex "/Users/thomas/Desktop")) with (allow file-write*) it works on app B and C too, so I know that's the only thing that's wrong.
So I really don't understand what's going on. How can it work for app A but not for B or C? Especially given that:
allowing all works (so I know the regex is the culprit)
app C is minimal and is not a blackbox
I tried tons of different variations: literal instead of regex, "^/Users/thomas/Desktop", "^/Users/thomas/Desktop/" , "^/Users/thomas/Desktop/*", ...

Related

Link two functions without a space between them

I am writing documentation for a library using haddock, and, for reasons that are not really necessary to explain, I need to include a little code block in my documentation that looks like:
z(<>)
Importantly there can be no space between z and (<>). It may be a bit esoteric but
z (<>)
would make my documentation incorrect, even if it is more stylistically correct.
Now I believe that hyperlinks to both z and (<>) would be helpful. Neither has a very informative name, so a link that helps people remember their definitions and purpose is nice.
So my code without the hyperlinks looks like:
#z(<>)#
And to add hyperlinks I just use single quotes:
#'z''(<>)'#
Except that doesn't work, haddock sees 'z'' and thinks that I mean to link z' (a function that does exist in my module), and then just leaves the rest alone. The rendered output looks like
z'(<>)'
Now as an experiment I deleted the definition of z', however the only difference this makes is that the link to z' goes away. The raw text remains the same. The next thing I tried was ditching #s altogether and did
'z''(<>)'
Which also created a hyperlink to z' and left the rest untouched, the same problem as earlier except now nothing is in a code block.
How can I make a code block that links two functions without a space between?
You can separate the two functions into different code blocks. If there is no space between the code blocks, it will appear no different than a single code block. So
#'z'##'(<>)'#
will render as desired.
You can also do it in one code block by moving the 's inside of the parentheses to only surround <>.
#'z'('<>')#
This will render slightly differently with the parentheses not being part of any hyperlink, however this may be desired.
Here is an alternative solution to add to the answer you already provided:
You can mix and match ' and `. These two will also be rendered correctly by haddock:
-- | #`z`'(<>)'#
-- | #'z'`(<>)`#
At the same time I've tried your solution #'z'##'(<>)'# and for some reason it did not render for me properly, but with haddock you never know.
Here are all of the ones that I've tried:
-- * #'z'##'(<>)'#
-- * #'z'('<>')#
-- * #'z'`(<>)`#
-- * #`z`'(<>)'#
With corresponding result:

Node.js cluster; jumbled console output ONLY when using colour

Нello! I'm running a clustered node project with a number of nodes. They do a fair bit of console output. I also want to be able to do beautiful coloured output.
My problem: I'm getting jumbled, race-condition-y console output ONLY WHEN USING COLOURS.
I've been boiling things down to isolate my issue, and my current setup is for every node in the cluster to have its own unique string. This is the only string the node will output to console.
let chars = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let getMyUniqueString = () => {
return chars[Math.floor(Math.random() * chars.length)].repeat(100);
};
I run a bunch of nodes which are using this function to determine their unique strings, and I see something like the following:
Isn't that beautiful! No matter how long and how furiously all those nodes output, this console output never gets jumbled.
Now, I try with unique strings which contain just a tiny bit of colour:
let chars = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let getMyUniqueString = () => {
let redEscSeq = '\x1b[41m';
let clearEscSeq = '\x1b[0m';
let aRedBoxOfText = redEscSeq + ' ' + clearEscSeq;
let repeatedChars = chars[Math.floor(Math.random() * chars.length)].repeat(100);
return aRedBoxOfText + repeatedChars;
};
And look how sad some of my results look!
The ONLY way data is being sent to the terminal, across all nodes, is through the console.log function.
Why is console.log smart enough to keep the output from many nodes unjumbled when there is no colour, but not smart enough to do it when even a bit of colour is included??
Thanks for any help!
(Just for reference, the following image is the kind of unjumbled output I'd expect to see consistently in the coloured case; it's just a red box (two spaces with red background colour) prefixing each line:)
EDIT: While this problem exists in the native windows "cmd.exe" console, in the powershell console, and in ConEmu (a nice 3rd party windows terminal shown in the screenshots), it does NOT exist in the Cygwin terminal! In Cygwin there is never any jumbling, even with tons of colours and async output. Is there anything I can do to encourage this Cygwin behaviour in other consoles??
It is a race condition, and it's unlikely you can do anything about it, maybe except reporting a bug to library used by nodejs.
While windows API itself does in fact support printing multi-colored string in a single API call, as shown here: https://learn.microsoft.com/en-us/windows/console/writeconsoleoutput, where every character contains its color information. But it also doesn't support ANSI escape codes. And this is not what's actually used by javascript.
Nodejs engine uses a library called libuv to write strings to terminal, which is crossplatform and internally translates ANSI escape codes to do the right thing. But if you look closely at the source of libuv for handling ANSI escape codes, you will see that it does a complete buffer flush after every escape code, meaning at some poiint it has to become multiple windows API calls to print one line of text.
Under normal circumstances this is obviously not an issue, but if you have multiple threads doing the writing, it means that parts of those lines may become jumbled... just like what you see here.
So the answer here is that there is no solution. Or you accept using cygwin as a solution.

simplessh library hangs when executing a command

I'm trying to use simplessh library to run a sequence of commands over SSH (actually, to learn some Haskell). It seems to be going OK, but it hangs on the second runSimpleSSH in this code:
module Main where
import Network.SSH.Client.SimpleSSH
main :: IO ()
main = do
s <- runSimpleSSH $ openSession' "localhost" 22 Nothing
case s of
Left e -> print e
Right s -> do
r <- runSimpleSSH $ execCommand s "ls" -- hangs here
case r of
Left e -> print e
Right (Result { resultOut=resultOut, resultErr=resultErr, resultExit=resultExit }) -> print resultExit
Is there something wrong with my Haskell code, or am I using the library wrong? I'm sure someone can tell based on the types exposed by the library.
PS: I'm actually using a patched version of the library which allows for no known_hosts, but the rest seems unchanged.
Never used this library but looking at the documentation for openSession:
Open a SSH session. The next step is to authenticate.
Also from execCommand description:
One should be authenticated before sending commands on a Session.
I think your code breaks the convention by calling execCommand before successfully authenticating. Not sure this is the problem but looks like you need to fix that anyway.

How to use SWRL rules on Protegé 4.3 using Pellet

I've just started doing work on ontologies with Protegé and I'm trying to understand how to use SWRL rules. I'm afraid I don't get the concept or how to correctly treat them, as I'm not able to produce any output. I'll explain a bit more a simple case I created to test this:
I've created three individuals, called A, B and C. Each one with a test property, that has a boolean range. On the property assertions tab of each one I've initialized their values, so they are test(A,true), test(B,true) and test(C,true). To test how rules work, I created a rule like this: test(A,true), test(B,true) -> test(C,false). The way I understand it is that, if A and B's test property is true, C's one would turn false. To do so, I start the reasoner (Pellet) but nothing happens. I mean, it says the reasoner is active and no "inconsistent ontology" messages appear, but C's test value doesn't change. I'm sure this must be a really simple confusion but I can't seem to find it anywhere nor check if the rule has been activated.
Thank you in advance.
The inference doesnt work like that, you cannot retract test(C, true) if you've asserted it. Your ontology probably includes both test(C, true) and test(C, false) which is completely legal unless you've specified otherwise; in which case then you'd see the inconsistency.

Yesod javascript formatting

I am working on debugging some javascript code that is generated in Yesod. Yesod generates javascript files with each function on one line which makes it impossible to set break points within the function. Is there a way to change this behavior so that the javascript preserves formatting for debugging?
I am currently using yesod 0.9, but I bet his will work in other versions as well.
Look in your Foundation.hs for:
addStaticContent = addStaticContentExternal minifym base64md5 Settings.staticDir
(StaticR . flip StaticRoute [])
and change it to:
addStaticContent = addStaticContentExternal (\bs -> Right bs) base64md5 Settings.staticDir
(StaticR . flip StaticRoute [])
I changed minifym -> (\bs -> Right bs) which just wraps the in coming content, javascript in our case, and returned. Or dave4420 points out below just replace minifym with (\bs -> Right bs) point free style equivalent Right.
This should make your javascript preserve its format.
The addStaticContent function in your Foundation file treats .js files as a special case, which lets you enable or disable minification by passing a different minification function as the first argument (Right leaving the file contents untouched).
Additionally, if you use Google Chrome for Javascript debugging, you can use the pretty-print button to debug minified Javascript, which looks like this:
This gives you manageable Javascript syntax.
Javascript is the exception to the rule that Yesod minifies everything that gets processed by special purpose Shakespeare languages. It is in general not possible to get a non-minifed representation of HTML and CSS with the current implementation of Shakespeare.

Resources