guess what 0x564c is? - linux-kernel

when i read linux kernel source, i found one line says:
#define NCP_SUPER_MAGIC 0x564c /* Guess, what 0x564c is :-) */
(564c)16 = (22092)10 = (53114)8 = (101011001001100)2
Wolfram|Alpha tells us that 22092 = 2^2 * 3 * 7 * 263 = 43 * 2^9 + 76
ok , so do any body have any ideas of this riddle?
btw, this code appears in the file of %linux-kernel-source%/include/linux/magic.h

It happens to be the hex representation of the initials of Volker Lendecke, who wrote the ncpfs support for the Linux kernel (only a kernel module at first, iirc). But basically, he's the one responsible. :-)
edit: In response to Ted's comment, it's used as the superblock magic number in Netware 5. I hope this satisfies your curiosity.

I wonder if it's someone's birthday...
5/6/4c = 5/6/76?

NCP stands for NetWare Core Protocol, from Novell.
ncpfs is an open-source NCP client implementation for Linux.

Related

Parameters for dlib::find_min_bobyqa

I'm working on the C++ version of Matt Zucker's Page dewarping. So far everything works fine, but I have a problem with optimization. In line 748 of Github repo Matt uses optimize function from Scipy. My C++ equivalent is find_min_bobyqa from dlib.net. The code is:
auto f = [&](const column_vector& ppts) { return objective( dstpoints, ppts, keypoint_index); };
dlib::find_min_bobyqa(f,
params,
2 * params.nr() + 1, // npt - number of interpolation points: x.size() + 2 <= npt && npt <= (x.size()+1)*(x.size()+2)/2
dlib::uniform_matrix<double>(params.nr(), 1, -2), // lower bound constraint
dlib::uniform_matrix<double>(params.nr(), 1, 2), // upper bound constraint
1, // initial trust region radius
1e-5, // stopping trust region radius
4000 // max number of objective function evaluations
);
In my concrete example params is a dlib::column_vector with double values and length = 189. Every element of params is less than 2.0 and greater than -2.0. Function objective() returns double value and "alone" it works properly because I get the same value as in the Python version. But after running fin_min_bobyqa function I usually get the message:
Terminate called after throwing an instance of 'dlib:bobyqa_failure', return from BOBYQA because the objective function has been called max_f_evals times.
I set max_f_evals to quite big value to see if it optimizes at all, but it doesn't. I did some tweaking with parameters but without good results. How should I set the parameters of find_min_bobyqa to get the right solution?
I am very interested in this issue as well. Zucker's work, with very minor tweaks, is ideal for straightening sheet music images, and I was looking for ways to implement it in a mobile platform when I came across your question.
My research so far suggests that BOBYQA is not the equivalent of Powell's method in scipy. BOBYQA is constrained, and the one in scipy is not.
See these links for more information, and a possible way to compile the right supporting library - I would try UOBYQA or NEWUOA.
https://github.com/jacobwilliams/PowellOpt
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#rdd2e1855725e-3
(See the Notes section)
EDIT: see C version here:
https://github.com/emmt/Algorithms/tree/master/newuoa
I wanted to post this as a comment, but I don't have enough points for that.
I am very interested in your progress. If you're willing, please keep me posted.
I finally solved this problem. I used PRAXIS library, because it doesn't need derivative information and is fast.
I modified the code a little to my needs and now it is faster around few seconds than original version written in Python.

What does Get do in VB6?

I'm trying to modify a program someone wrote in VB6 in the sem-distant past, and have come across the line below, and many similar ones. My question is, syntactically, what does this "Get" line look like it does or might do?
Get #3, StartByte + Offset, StudentScrBytes
Within the program, it's ALWAYS followed by 3 comma-separated items, and with one exception, the first item is a number preceded by #. The second looks to always resolve to a number, and the third a single variable.
I'm fairly sure I've figured out the numbers preceded by # are a file reference - the first time Get appears, instead of #3 or #10 or #whatever, it has a variable "TempFile" instead, initialized as FreeFile().
TempFile = FreeFile()
Open "c:\folerName.dir" For Binary Shared As TempFile
The only stuff I've been able to find on Get in VB6, seems to relate to OOP and getters/setters. Maybe I'm wrong, but I really don't think that's what's going on here, and all I have are vague guesses as to what is.
Here's the function the line was taken from. Both arguments are integers.
Function StudentScr$(Record, Contest)
Dim StudentScrBytes As String * 4
StartByte = (Record - 1) * LengthOfStudentRecord
If Contest = 1 Then Offset = 77
If Contest = 2 Then Offset = 85
If Contest = 3 Then Offset = 94
If Contest = 4 Then Offset = 102
If Contest = 5 Then Offset = 110
If Contest = 6 Then Offset = 118
If Contest = 7 Then Offset = 126
If Contest = 8 Then Offset = 134
Get #3, StartByte + Offset, StudentScrBytes
StudentScr$ = StudentScrBytes
End Function
I would think Get would get something from the specified file, except I can't tell how (or if) a file is even specified at all.
Have a look at the original MS VB6 documentation:
https://msdn.microsoft.com/en-us/library/aa243376(v=vs.60).aspx
You may also be interested in its counterpart Put:
https://msdn.microsoft.com/en-us/library/aa266212(v=vs.60).aspx
Hint: when searching for legacy VB statements, include "vs.60" for Visual Studio 6.0 in your Google search, and restrict your search to the MS site. MS hast this term in the official link, so you can not miss it. This search:
vb6 vs.60 get put site:microsoft.com
does bring up both Get and Put as the two first Google answers on my machine.

does anyone have a libxpm example?

This is the dumbest thing but I have tried and tried and I cannot use libxpm.
I have found some snippets of code but very little and what i have found has been very old code that I cannot compile.
My understanding so far is that I need to:
connect to x windows server (done)
create a window (done)
use libxpm to create a pixmap from data (not done)
copy the pixmap to the window (not done)
If you happen to have a small example lying around or know where to send me that would be great. If you happen to know how to use xcb and libxpm that would be even better. xcb seems to use an integer for it's connection while xlib uses a display struct, I haven't found any examples at all that deal with xcb and libxpm and the connection issue is a deadend for me.
Thanks for reading
This may help. If I use ImageMagick's convert, I can convert a JPEG to an XPM and that may help you see how they are supposed to look.
convert image.jpg image.xpm
And we can look at it like this:
more image.xpm
/* XPM */
static char *background[] = {
/* columns rows colors chars-per-pixel */
"906 603 181 2 ",
" c #040403",
". c #080704",
"X c #070803",
"o c #090906",
"O c #060608",
...
...
The libXpm sources include a simple “show xpm” command, but it still uses Xlib & Xt, not xcb:
https://cgit.freedesktop.org/xorg/lib/libXpm/tree/sxpm/sxpm.c

PSD specifications help

I'm writing a program (in Python for now) for reading PSD files. I'm using this specification: http://www.fileformat.info/format/psd/egff.htm
Here it says
BYTE Name[]; /* Even-length Pascal-format string, 2 bytes or longer
*/
Um, 2 bytes or longer? How am I supposed to find out how ling it is? I don't know what "Pascal-format string" means either.
Thanks in advance.
EDIT: Heres a direct link to the official PSD specification (pdf): http://forums.adobe.com/servlet/JiveServlet/download/2923119-45984/Photoshop%20File%20Formats.pdf;jsessionid=21F2DBA32AB9E56882065663C10A1EBF.node0
Look in page 9, under "Image Resource Blocks"
Please help.
"Pascal-format string" could mean string that have length encoded on first position IIRC.

Ruby - read bytes from a file, convert to integer

I'm trying to read unsigned integers from a file (stored as consecutive byte) and convert them to Integers. I've tried this:
file = File.new(filename,"r")
num = file.read(2).unpack("S") #read an unsigned short
puts num #value will be less than expected
What am I doing wrong here?
You're not reading enough bytes. As you say in the comment to tadman's answer, you get 202 instead of 3405691582
Notice that the first 2 bytes of 0xCAFEBABE is 0xCA = 202
If you really want all 8 bytes in a single number, then you need to read more than the unsigned short
try
num = file.read(8).unpack("L_")
The underscore is assuming that the native long is going to be 8 bytes, which definitely is not guaranteed.
How about looking in The Pickaxe? (Ruby 1.9, p. 44)
File.open("testfile")
do |file|
file.each_byte {|ch| print "#{ch.chr}:#{ch} " }
end
each_byte iterates over a file byte by byte.
There are a couple of libraries that help with parsing binary data in Ruby, by letting you declare the data format in a simple high-level declarative DSL and then figure out all the packing, unpacking, bit-twiddling, shifting and endian-conversions by themselves.
I have never used one of these, but here's two examples. (There are more, but I don't know them):
BitStruct
BinData
Ok, I got it to work:
num = file.read(8).unpack("N")
Thanks for all of your help.
What format are the numbers stored in the file? Is it in hex? Your code looks correct to me.
When dealing with binary data you need to be sure you're opening the file in binary mode if you're on Windows. This goes for both reading and writing.
open(filename, "rb") do |file|
num = file.read(2).unpack("S")
puts num
end
There may also be issues with "endian" encoding depending on the source platform. For instance, PowerPC-based machines, which include old Mac systems, IBM Power servers, PS3 clusters, or Sun Sparc servers.
Can you post an example of how it's "less"? Usually there's an obvious pattern to the data.
For example, if you want 0x1234 but you get 0x3412 it's an endian problem.

Resources