Server Bug Fix: packages will not load [closed]

Original Source Link

I have a package at /Users/me/Desktop/Mathematica/MyPackages/SamplePackage.m. It looks like this:

BeginPackage["SamplePackage`"]

bruh::usage = "bruh[ x] computes a simple function."
bruhpriv::usage = "bruhpriv[x] gives 5."

bruh[x_] := Module[{y}, y = x^2;
  y + 1]

Begin["`Private`"]
bruhpriv[x_] := 5
End[]
EndPackage[]

Obviously I have no use for this, I am just trying to make a freaking package load. Anyways, if I open the file SamplePackage.m in Mathematica and run it then open a new notebook, I can access both bruh and bruhpriv by their short and long names. Further, SamplePackage’ is in the list of

$Packages

and SamplePackage’ is also in the

$ContextPath

bruh[4] gives 17 like it should, etc. However, if I do anything but run the file SamplePackage.m it won’t work. I use AppendTo[$Path,the folder I want] and if I do <<SamplePackage.m it runs with no error message. If I do Get["SamplePackage.m"] it runs with no error message. I know it is finding the file because if I remove the AppendTo line I get the file no found error, as expected.

So after I do <<SamplePackage.m it does not matter what I do I cannot use bruh[x] or bruhpriv[x]. Typing them in just echoes back the input. Further, SamplePackage’ is not in

$Packages

or

$Context Path

The only way to get the functions is to open the file and run the lines. What am I doing wrong?

EDIT: IMAGE IN RESPONSE TO MURRAY
enter image description here

One way:

   AppendTo[$Path, "~/Desktop/Mathematica/MyPackages"]
   Get["SamplePackage.m"]

   bruh[3]
(* 10 *)

Nicer way:

  1. Create a new folder SamplePackage inside
    /Desktop/Mathematica/MyPackages.
  2. Move SamplePackage.m into that new folder.
  3. In /Desktop/Mathematica/MyPackages/SamplePackage create a new subfolder Kernel.
  4. In that new subfolder Kernel, put the following little package init.m whose contents consist of just the single cell: Get["SamplePackage`SamplePackage`"]

Now again append Get["SamplePackage`SamplePackage`"] to $Path and just load the package by:

<< SamplePackage`

Nicest way

Do the same thing as for “Nicer Way” except put the whole folder SamplePackage into the Applications subfolder of $UserBaseDirectory (which under macOS, for example, would be ~/Library/Mathematica/Applications).

This way, you no longer have to use AppendTo[$Path,...]. Now you simple use:

<< SamplePackage`

Tagged : /

Making Game: What are “build-essential” & “build-dep”?

Original Source Link

I am researching how to install Ruby 1.9.1 in Xubuntu 10.04 and I came across the command build-essential and build-dep multiple times. Sometimes it is followed by packages and sometimes it is both preceded and post-ceded by packages.

The 2 examples I am looking at are:

sudo apt-get install build-essential
zlib1g zlib1g-dev zlibc libruby1.9
libxml2 libxml2-dev libxslt-dev

sudo apt-get build-dep ruby1.9

and

sudo apt-get install ruby irb ri rdoc
ruby1.8-dev libzlib-ruby libyaml-ruby
libreadline-ruby libncurses-ruby
libcurses-ruby libruby libruby-extras
libfcgi-ruby1.8 build-essential
libopenssl-ruby libdbm-ruby
libdbi-ruby libdbd-sqlite3-ruby
sqlite3 libsqlite3-dev libsqlite3-ruby
libxml-ruby libxml2-dev

The build-essential package is a reference for all the packages needed to compile a Debian package. It generally includes the GCC/g++ compilers and libraries and some other utilities.

Check out the documentation here.

The command sudo apt-get build-dep packagename means “As root, install all dependencies for ‘packagename’ so that I can build it”. So build-dep is an apt-get command just like install, remove, update, etc.

build-essential is a package which contains references to numerous packages needed for building software in general.

build-essential has one magical property: it does not need to be listed as a build dependency under the Build-Depends control field (debian-packages) of source packages as documented at https://www.debian.org/doc/debian-policy/ch-source.html#s-pkg-relations

You can get a list of the build-essential packages at:

cat /usr/share/doc/build-essential/list

You can also determine if a package is part of build-essential with:

apt-cache show gcc

which says:

Build-Essential: yes

“build-essential” contains tools (like the gcc compiler, make tool, etc) for compiling/building software from source. So you start with (usually C) source files and create executables from them.

If you are just trying to get Ruby installed, I would highly recommend just using RVM (Ruby Version Manager):

Follow the instructions under “Github Repository (recommended)”

Note that you will need the Git version control software installed first. Use apt-get install git-core if you don’t have that yet.

Tagged : / /

Making Game: What are “build-essential” & “build-dep”?

Original Source Link

I am researching how to install Ruby 1.9.1 in Xubuntu 10.04 and I came across the command build-essential and build-dep multiple times. Sometimes it is followed by packages and sometimes it is both preceded and post-ceded by packages.

The 2 examples I am looking at are:

sudo apt-get install build-essential
zlib1g zlib1g-dev zlibc libruby1.9
libxml2 libxml2-dev libxslt-dev

sudo apt-get build-dep ruby1.9

and

sudo apt-get install ruby irb ri rdoc
ruby1.8-dev libzlib-ruby libyaml-ruby
libreadline-ruby libncurses-ruby
libcurses-ruby libruby libruby-extras
libfcgi-ruby1.8 build-essential
libopenssl-ruby libdbm-ruby
libdbi-ruby libdbd-sqlite3-ruby
sqlite3 libsqlite3-dev libsqlite3-ruby
libxml-ruby libxml2-dev

The build-essential package is a reference for all the packages needed to compile a Debian package. It generally includes the GCC/g++ compilers and libraries and some other utilities.

Check out the documentation here.

The command sudo apt-get build-dep packagename means “As root, install all dependencies for ‘packagename’ so that I can build it”. So build-dep is an apt-get command just like install, remove, update, etc.

build-essential is a package which contains references to numerous packages needed for building software in general.

build-essential has one magical property: it does not need to be listed as a build dependency under the Build-Depends control field (debian-packages) of source packages as documented at https://www.debian.org/doc/debian-policy/ch-source.html#s-pkg-relations

You can get a list of the build-essential packages at:

cat /usr/share/doc/build-essential/list

You can also determine if a package is part of build-essential with:

apt-cache show gcc

which says:

Build-Essential: yes

“build-essential” contains tools (like the gcc compiler, make tool, etc) for compiling/building software from source. So you start with (usually C) source files and create executables from them.

If you are just trying to get Ruby installed, I would highly recommend just using RVM (Ruby Version Manager):

Follow the instructions under “Github Repository (recommended)”

Note that you will need the Git version control software installed first. Use apt-get install git-core if you don’t have that yet.

Tagged : / /

Server Bug Fix: Unimport wolfram language package

Original Source Link

In Wolfram Language, Import["file.wl"] can import external wolfram package, Is it reversible?

Can I unimport some packages? In other means Unset all the Function, Variable which is Set when Import?

The correct way to load a package is Needs or Get, not Import.

No, loading is not reversible. The only way to restore the pre-package-loading state robustly is to restart the kernel with Quit.

Alternatively, you may remove the package’s context from the $ContextPath. This will effectively hide the package’s symbols. However, this does not unload the package. The package’s symbols will still be usable, but they must be referred to with the full context.

In other means Unset all the Function, Variable which is Set when Import?

Note that loading a package may do a lot more than create definitions. Clearing definitions is not a safe way to “unload” it.

If a package only consists of definitions, does not load subpackages and does not attach the Locked attribute to its symbols, then it is possible to remove its definitions by

unLoad[context_String /; StringEndsQ[context, "`"]] := (
  Unprotect; (Unprotect[#]; Remove[#]) & /@ {context <> "*", 
    context <> "*`*"}; $ContextPath = 
   DeleteCases[$ContextPath, context];
  )

This can be tested by, e.g.,

 Needs["ComputerArithmetic`"];
 unLoad["ComputerArithmetic`"];

Now Names["ComputerArithmetic`*"] gives an empty list

Tagged :

Linux HowTo: Creating a single file executable from a directory in Windows?

Original Source Link

There’s an answer there, but it’s two years old, and provides no information on how to do it.

Situation: I have a folder with an executable file, some required dlls and some images.
I want to package all this into a single executable file. If executed, it will run the executable file.

I’ve found this superuser post. However, it doesn’t seem to offer a solution.

If you’re familiar with Python, there’s an application called PyInstaller. It creates single-file executables from python sourcecode.

I’m not sure about the exact inner-workings of it, but it generally does something like this:

  • Wrap the directory with executable into a new executable, ex app.exe
  • the new executable executes a program, which unpacks the hidden directory into a temporary folder, a folder called _MEIxxxxx, x’s being numbers. For example: C:UsersMeAppDataLocalTemp_MEI188722
  • execute the program from that folder.

From what I’ve read, they use hackery dark-magic to make this work. I’m wondering if there is a program that does this kind of dark-magic for non-python files.

Windows doesn’t allow an application to be launched from inside a container (like a zip file) in native way. That’s why PyInstaller unpacks to a temporary directory for running the actual application.

Compressors like ZIP and 7Zip offer you the ability to create a self-extracting executable. Which is the regular compressed file plus the executable code needed for decompressing. Packed into a single file. 7zip offers the option to create self-extracting archives for installers. Maybe you can use this option to run a standard program instead of an installer anyway: http://7zip.bugaco.com/7zip/MANUAL/switches/sfx.htm

You can configure it to run any file you want after extracting. I’m not sure if you are going to be able to remove the prompt.

nsis http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System would be the best option I have seen. I have made several wrappers for work apps that we don’t want users poking around the files used to repair their pc etc. I just built a virus scanner front end this week that auto downloads msert/mcafee stinger/mcafee rootkit using the corp proxy and then runs all 3 apps for the tech’s.

you could do what your asking with a standard template/example, in the main section set the out dir [ $OUTDIR %temp%_MEI188722 ] and add a [ file yourapp.exe ] line for each file in the original directory that the program needs. next use a execwait line to run the application in question. a command for sleep 20ms and then delete %temp%_MEI188722 so that the files get removed after they are not being used.

Setting the installer to silent mode would keep any standard installer dialog boxes from showing up and your app would just load after a moment. or you could create custom dialog pages if you needed the user to select any options first or wanted the app to return a message if it had some kind of error. The tutorials and community are quite active and help full so once you get used to how nsis does things it should be straight forward. http://hmne.sourceforge.net/ this is a handy program to allow you to more easily edit the script file to allow you to make the exe.

Tagged : /

Making Game: Creating a single file executable from a directory in Windows?

Original Source Link

There’s an answer there, but it’s two years old, and provides no information on how to do it.

Situation: I have a folder with an executable file, some required dlls and some images.
I want to package all this into a single executable file. If executed, it will run the executable file.

I’ve found this superuser post. However, it doesn’t seem to offer a solution.

If you’re familiar with Python, there’s an application called PyInstaller. It creates single-file executables from python sourcecode.

I’m not sure about the exact inner-workings of it, but it generally does something like this:

  • Wrap the directory with executable into a new executable, ex app.exe
  • the new executable executes a program, which unpacks the hidden directory into a temporary folder, a folder called _MEIxxxxx, x’s being numbers. For example: C:UsersMeAppDataLocalTemp_MEI188722
  • execute the program from that folder.

From what I’ve read, they use hackery dark-magic to make this work. I’m wondering if there is a program that does this kind of dark-magic for non-python files.

Windows doesn’t allow an application to be launched from inside a container (like a zip file) in native way. That’s why PyInstaller unpacks to a temporary directory for running the actual application.

Compressors like ZIP and 7Zip offer you the ability to create a self-extracting executable. Which is the regular compressed file plus the executable code needed for decompressing. Packed into a single file. 7zip offers the option to create self-extracting archives for installers. Maybe you can use this option to run a standard program instead of an installer anyway: http://7zip.bugaco.com/7zip/MANUAL/switches/sfx.htm

You can configure it to run any file you want after extracting. I’m not sure if you are going to be able to remove the prompt.

nsis http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System would be the best option I have seen. I have made several wrappers for work apps that we don’t want users poking around the files used to repair their pc etc. I just built a virus scanner front end this week that auto downloads msert/mcafee stinger/mcafee rootkit using the corp proxy and then runs all 3 apps for the tech’s.

you could do what your asking with a standard template/example, in the main section set the out dir [ $OUTDIR %temp%_MEI188722 ] and add a [ file yourapp.exe ] line for each file in the original directory that the program needs. next use a execwait line to run the application in question. a command for sleep 20ms and then delete %temp%_MEI188722 so that the files get removed after they are not being used.

Setting the installer to silent mode would keep any standard installer dialog boxes from showing up and your app would just load after a moment. or you could create custom dialog pages if you needed the user to select any options first or wanted the app to return a message if it had some kind of error. The tutorials and community are quite active and help full so once you get used to how nsis does things it should be straight forward. http://hmne.sourceforge.net/ this is a handy program to allow you to more easily edit the script file to allow you to make the exe.

Tagged : /

Linux HowTo: Transferring AppX Package from Working Computer to Another

Original Source Link

I have a computer with the version of the Photos app which has the ability to caption videos. I tried to update this app on the user’s computer, but it wouldn’t update or reinstall through the store. I tried removing it with get-appxpackage | remove-appxpackage. That removed it, but still not able to update using the store.

I am now resorting to attempt transferring it from a computer which has the version to the user’s computer.

I run the following to dump the manifest:

$manifest = Get-AppxPackageManifest -Package "Microsoft.Windows.Photos_2020.19111.24110.0_x64__8wekyb3d8bbwe"
$manifest.innerXML > <path>AppxManifest.xml

On the target:

Add-AppxPackage -register <path> -DisableDevelopmentMode

I get the message “Appx manifest invalid … cannot switch the encoding type.

This is not that simple, as you realized, the OS has a couple of security measures to ensure the integrity of the apps installed, I will not go into details as this is not the purpose of this question.

The only solution is to get your hands on the full appx/msix package. You can download it using Fiddler.

Tagged : / /

Making Game: Transferring AppX Package from Working Computer to Another

Original Source Link

I have a computer with the version of the Photos app which has the ability to caption videos. I tried to update this app on the user’s computer, but it wouldn’t update or reinstall through the store. I tried removing it with get-appxpackage | remove-appxpackage. That removed it, but still not able to update using the store.

I am now resorting to attempt transferring it from a computer which has the version to the user’s computer.

I run the following to dump the manifest:

$manifest = Get-AppxPackageManifest -Package "Microsoft.Windows.Photos_2020.19111.24110.0_x64__8wekyb3d8bbwe"
$manifest.innerXML > <path>AppxManifest.xml

On the target:

Add-AppxPackage -register <path> -DisableDevelopmentMode

I get the message “Appx manifest invalid … cannot switch the encoding type.

This is not that simple, as you realized, the OS has a couple of security measures to ensure the integrity of the apps installed, I will not go into details as this is not the purpose of this question.

The only solution is to get your hands on the full appx/msix package. You can download it using Fiddler.

Tagged : / /

Making Game: Could somebody please help me remove or purge the content from “impacket”

Original Source Link

Goal: To remove or purge the package “impacket.

Problem: It doesn’t find the package, yet, ls tells me it exist.

Could somebody please help me remove the content from “impacket” so that I can re-install it myself. I am quite new to working with kali and would like to install “impacket” myself as, from what I understand, the default version that kali provides you does not work.

I’ve tried to installed it using methods from older kali versions, but none of them worked, and there is not a lot of documentation about how to do it in kali 2020.1

I’m running in Kali 2020.1 and have pip3 installed.

Terminal output:

[email protected]:/opt# apt purge *impacket*
Reading package lists... Done
Building dependency tree

Reading state information... Done
E: Unable to locate package impacket
[email protected]:/opt# ls
impacket
[email protected]:/opt#

enter image description here

Tagged : / / /

Server Bug Fix: What is the correct to have package A use package B in its private section without making B visible to the user?

Original Source Link

V 12.1 on windows.


I am loading pkg2, which in its Private section loads pkg1 in order to call one of its function.

After using pkg2, I found that pkg1 is now visible and can be called without loading it.

I thought the whole idea of loading a package from the private section of another package, is to keep it private and not to leak it to the top user level. Otherwise, why load it from private section in first place?

I am using the layout based on this answer load-a-mathematica-package-from-within-a-package

Here is MWE. First I have the two packages in same folder the main notebook for now to make it easier to test

enter image description here

Here is pkg2.m. This is the one I want to use,

BeginPackage["pkg2`"];
[email protected]@Names["pkg2`*"];
[email protected]@Names["pkg2`*"];

test::usage

Begin["`Private`"];
Needs["pkg1`"];

test[]:=Module[{},    
    Print["Inside test[] in pkg2"];
    pkg1`foo[]    
]
End[]; (* `Private` *)
[email protected]@Names["pkg2`*"];
EndPackage[]

I used Needs in the above. Get also works. It seems Needs found pkg1.m since it is in same folder as pkg2.m automatically without having to give full path. Notice that the caller sets the current directory to where the packages are, and I think this is why it worked without the full path. Mathematica seems to search current folder first.

And here is pkg1.m

BeginPackage["pkg1`"];
[email protected]@Names["pkg1`*"];
[email protected]@Names["pkg1`*"];

foo::usage

Begin["`Private`"];

foo[]:=Module[{},

Print["in pkg1  foo OK"]

]
End[]; (* `Private` *)
[email protected]@Names["pkg1`*"];
EndPackage[]

And here is main.nb, which loads pkg2.m. And once this package is loaded, then pkg1 becomes visible to the user as well, which is not what I want

enter image description here

SetDirectory[NotebookDirectory[]]
Get["pkg2.m"]
?? pkg1`*

Question is : What is the correct to have package A use package B in its private section without making B visible to the user?

I use the following pattern. Package B will not be made visible to the user when A is loaded, but it will be usable internally by A.

BeginPackage["A`"]
Needs["B`"]

foo::usage = "foo[] does things";

Begin["`Private`"]

foo[x_] := x^2

End[]
EndPackage[]

This contrasts with the following which makes both A and B visible when only A is loaded:

BeginPackage["A`", {"B`"}]

foo::usage = "foo[] does things";

Begin["`Private`"]

foo[x_] := x^2

End[]
EndPackage[]

Both of these will of course load package B. If B is not loaded, it cannot possibly be used by package A. The difference is in whether B is made accessible to the user when the user requests only A.


You ask why the following returns things,

?B`*

or “Why is B visible”?

The answer is that B is not actually visible. B` will not be on the context path ($ContextPath). If there is a function B`fun provided by package B, you can only call it as B`fun[], but not as fun[].

?B`fun will work but ?fun will not work.

“Visibility” means whether functions in a package can be called without typing out the full context. Package B must be loaded to be usable by A. This means that B`fun must exist. The way Mathematica ensures that B does not interfere with anything is to not have the context B` on the context path, and therefore not allow access to B’s symbols without writing out their context. However, all symbols in Mathematica are accessible is providing their full context. Nothing can be fully hidden.


Based on your comment:

But the names of that second package creep up to use space (even though if the user does not know the other package name, they will not know how to call them).

I assume you are looking not to load B until absolutely necessary. Here’s a solution to that.

Assume that package B provides B`fun, but this function is only required by A`something. Then we can write package A as follows:

BeginPackage["A`"]

foo::usage = "foo[]";
something::usage = "something[]";

Begin["`Private`"]

foo[x_] := x^2

something[] := 
  (Block[{$ContextPath}, Needs["B`"]];
   B`fun[])

End[]
EndPackage[]

Now Needs["A`"] will not immediately load B. B will only be loaded when something[] is called for the first time. I used Block[{$ContextPath}, ...] to ensure that B won’t be made visible to the user when they call something[]. I also needed to explicitly spell out the context of B`fun[] in the definition of something, as B` would not be loaded or on the context path at the time when the definition of something is parsed.

Tagged : /