I want to create a custom Cups banner page and have so far come up with nothing when searching the net for how to do this.
In /usr/share/cups/banners there are "high-level" definitions of banners that in turn refer to PDF files found in /usr/share/cups/data .
Additionally in the data folder there are ODT files which I assume are used for generating the PDF files. But is that done by using the bult-in PDF generator in for instance LibreOffice or how do I do that?
How do I in the ODT template specify what variable to insert where?
Is it possible to specify that a separate tray (with colored paper) is used for printing the banner and then the printer continues with the job using whatever tray the job specified?
We have our own banner page. It is in postscript and contains some fields that are filled in when printing. The fields are in {}. Here is the postscript file that you could use as a starting point. It is a modified version of some early postscript banner page of CUPS.
%!PS-Adobe-3.0
%%BoundingBox: 0 0 612 792
%%Pages: 1
%%LanguageLevel: 1
%%DocumentData: Clean7Bit
%%DocumentSuppliedResources: procset bannerprint/1.0
%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
%%Creator: Michael Sweet, Easy Software Products
%%CreationDate: May 10, 2000
%%ModifiedBy: Roy Costa IBM International Technical Support Organization
%%ModificationDate: March 01, 2004
%%Title: ITSO Custom cover page
%%EndComments
%%BeginProlog
%%BeginResource procset bannerprint 1.1 0
%
% PostScript banner page for the Common UNIX Printing System ("CUPS").
%
% Copyright 1993-2002 Easy Software Products
%
% These coded instructions, statements, and computer programs are the
% property of Easy Software Products and are protected by Federal
% copyright law. Distribution and use rights are outlined in the file
% "LICENSE.txt" which should have been included with this file. If this
% file is missing or damaged please contact Easy Software Products
% at:
%
% Attn: CUPS Licensing Information
% Easy Software Products
% 44141 Airport View Drive, Suite 204
% Hollywood, Maryland 20636-3111 USA
%
% Voice: (301) 373-9603
% EMail: cups-info#cups.org
% WWW: http://www.cups.org
%
/CUPSLOGO {% Draw CPPM logo
% height CUPSLOGO
% Start with a big C...
/Helvetica findfont 1 index 2 div scalefont setfont
0 setgray
0 0 moveto
(C) show
% Then "UNIX Printing System" much smaller...
/Helvetica-Bold findfont 1 index 9 div scalefont setfont
0.25 mul
dup 1.4 mul dup 0.4 mul moveto
(P.P.M.) show
} bind def
/ESPLOGO {% Draw the ESP logo
% height ESPLOGO
% Compute the size of the logo...
0 0
2 index 1.5 mul 3 index
% Do the "metallic" fill from 10% black to 40% black...
1 -0.001 0 {
dup % loopval
-0.15 mul% loopval * -0.15
28 Printing with Linux on IBM Eserver zSeries Using CUPS and Samba
0.9 add% 0.9 - loopval * 0.15
setgray% set gray shade
0 % x
1 index neg% loopval
1 add% 1 - loopval
3 index% height
mul % height * (1 - loopval)
moveto% starting point
dup % loopval
3 index% width
mul % loopval * width
2 index% height
lineto% Next point
0 % x
2 index% height
lineto% Next point
closepath
fill
dup % loopval
0.15 mul% loopval * 0.15
0.6 add% 0.6 + loopval * 0.15
setgray
dup % loopval
neg 1 add% 1 - loopval
3 index% width
mul % (1 - loopval) * width
0 % y
moveto% Starting point
2 index% width
exch% loopval
2 index% height
mul % loopval * height
lineto% Next point
1 index% width
0 % y
lineto% Next point
closepath
fill
} for
0 setgray rectstroke
/Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
dup 40 div
dup 4 mul 1 index 25 mul moveto (E) show
dup 10 mul 1 index 15 mul moveto (S) show
dup 16 mul 1 index 5 mul moveto (P) show
/Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
dup 14 mul 1 index 29 mul moveto (asy) show
dup 20 mul 1 index 19 mul moveto (oftware) show
dup 26 mul 1 index 9 mul moveto (roducts) show
pop
} bind def
%%EndResource
%%EndProlog
%%Page: 1 1
gsave
% Determine the imageable area and device resolution...
initclip newpath clippath pathbbox% Get bounding rectangle
72 div /pageTop exch def% Get top margin in inches
72 div /pageRight exch def% Get right margin in inches
72 div /pageBottom exch def% Get bottom margin in inches
72 div /pageLeft exch def% Get left margin in inches
/pageWidth pageRight pageLeft sub def% pageWidth = pageRight - pageLeft
/pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
/boxWidth % width of text box
pageWidth pageHeight lt
{ pageWidth 54 mul }
{ pageHeight 42 mul }
ifelse def
newpath % Clear bounding path
% Create fonts...
/largeFont /Helvetica findfont % largeFont = Helvetica
pageHeight 5 mul scalefont def % size = pageHeight * 3 (nominally 33)
/mediumFont /Helvetica findfont% mediumFont = Helvetica
pageHeight 1.5 mul scalefont def% size = pageHeight * 1.5 (nominally 16.5)
/bigFont /Helvetica findfont % bigFont = Helvetica
pageHeight 2 mul scalefont def % size = pageHeight * 3 (nominally 33)
% Offset page to account for lower-left margin...
pageLeft 72 mul
pageBottom 72 mul
translate
% Job information box...
largeFont setfont
pageWidth 4 mul % x = pageWidth * 1/2 * 72
pageHeight 58 mul % y = pageHeight * 1/2 * 72
pageHeight 5 mul add % y -= 1 line
2 copy % Copy X & Y
moveto
({job-originating-user-name}) show 1
bigFont setfont % Big sized font
pageWidth 4 mul % x = pageWidth * 1/2 * 72
pageHeight 58 mul % y = pageHeight * 1/2 * 72
pageHeight -5 mul add % y += 1 line
2 copy % Copy X & Y
moveto
({job-name}) show 2
pageWidth 4 mul % x = pageWidth * 1/2 * 72
pageHeight 58 mul % y = pageHeight * 1/2 * 72
pageHeight -10 mul add % y += 2 lines
2 copy % Copy X & Y
moveto
({printer-name}-{job-id}) show 3
pageWidth 4 mul % x = pageWidth * 1/2 * 72
pageHeight 58 mul % y = pageHeight * 1/2 * 72
pageHeight -15 mul add % y += 2 lines
2 copy % Copy X & Y
moveto
({time-at-creation}) show 4
% Then the CUPS logo....
gsave
pageWidth 4 mul
pageWidth 6 mul
translate
pageWidth 9 mul CUPSLOGO
grestore
% And the ESP logo....
%gsave
%pageWidth 59 mul
%pageWidth 6 mul
%translate
%pageWidth 6 mul ESPLOGO
%grestore
% Show the page...
grestore
showpage
%
% End of "$Id: standard,v 1.8 2002/01/31 14:19:37 mike Exp $".
%
%%EOF
Related
Generate the function generateExponents k l, which for given k and l generates a stream of all unique possible numbers x^k*y^l in increasing order. For example generateExponents 2 3 = [1,4,8,9,16,25,27...]
For obvious reasons this doesn't work:
generateExponents k l = sort [x^k*y^l | x <- [1..], y <- [1..]]
Then I tried this, which doesn't work either:
generateExponents k l = [n | n <- [1 ..], n `elem` products n]
where
xs n = takeWhile (\x -> x ^ k <= n) [1 ..]
ys n = takeWhile (\y -> y ^ l <= n) [1 ..]
products n = liftA2 (*) (xs n) (ys n)
What am I doing wrong?
Your algorithm is pretty slow -- it checks every number, and for every number it searches for an appropriate factorization! You can do better by producing an infinite table of answers, and then collapsing the table appropriately. For example, for x^2*y^3, the table looks like:
x 1 2 3 4 5
y
1 1 4 9 16 25
2 8 32 72 128 200
3 27 108 243 432 675
4 64 256 576 1024 1600
5 125 500 1125 2000 3125
Note two nice features of this table: each row is sorted, and the rows themselves are sorted. This means we can merge them efficiently by simply taking the top-left value, then re-inserting the tail of the first row in its new sorted position. For example, the table above, after emitting 1, would look like:
4 9 16 25 36
8 32 72 128 200
27 108 243 432 675
64 256 576 1024 1600
125 500 1125 2000 3125
Then, after emitting the top-left value 4:
8 32 72 128 200
9 16 25 36 49
27 108 243 432 675
64 256 576 1024 1600
125 500 1125 2000 3125
Note how the top row has now become the second row to keep the doubly-sorted property.
This is an efficient way to construct all the right numbers in the right order. Then, the only remaining trick needed is to deduplicate, and for that you can deploy the standard trick map head . group, since duplicates are guaranteed to be next to each other. Here's the full code:
import Data.List
generateExponents' k l = map head . group . go $ [[x^k*y^l | x <- [1..]] | y <- [1..]] where
go ((x:xs):xss) = x:go (insert xs xss)
It's much, much faster. Compare:
> sum . take 400 $ generateExponents 2 3
5994260
(8.26 secs, 23,596,249,112 bytes)
> sum . take 400 $ generateExponents' 2 3
5994260
(0.01 secs, 1,172,864 bytes)
> sum . take 1000000 {- a million -} $ generateExponents' 2 3
72001360441854395
(6.99 secs, 13,460,753,616 bytes)
I think you just forgot to map the actual function over the xs and ys:
generateExponents k l = [n | n <- [1 ..], n `elem` products n]
where
xs n = takeWhile (<= n) $ map (^ k) [1 ..]
ys n = takeWhile (<= n) $ map (^ l) [1 ..]
products n = liftA2 (*) (xs n) (ys n)
I want to feature scale a matrix (X) with 2 columns. I am using mean normalization, and I wrote the following lines in Octave:
X_norm = X
mu = mean(X);
sigma = std(X);
X_norm(:,1) = (X_norm(:,1) .- mu(:,1)) ./ sigma(:,1);
X_norm(:,2) = (X_norm(:,2) .- mu(:,2)) ./ sigma(:,2);
Can you please let me know a cleaner way to vectorize these calculation?
I checked my code by comparing with the result from zscore(X) and they matched - i.e. a sum(X_norm - zscore(X)) returned me 0 0.
I am constrained to not use zscore(), and hence the question.
Sample data as follows:
2104 3
1600 3
2400 3
1416 2
3000 4
1985 4
1534 3
1427 3
1380 3
1494 3
1940 4
2000 3
1890 3
4478 5
1268 3
2300 4
1320 2
1236 3
2609 4
3031 4
1767 3
1888 2
1604 3
1962 4
3890 3
1100 3
1458 3
2526 3
2200 3
2637 3
You could simply do:
X_norm = (X .- mean(X,1)) ./ std(X,0,1);
During cross validation faced zero division issue.
This worked for me.
mu = mean(X);
X_norm = X - mu;
sigma = std(X);
% Skip zero div
sigmaZeroIdx = sigma == 0;
sigma(1,sigmaZeroIdx) = 1;
X_norm = X_norm ./ sigma;
I think you could apply a for loop for N size of features.
X_norm = X;
mu = zeros(1, size(X, 2));
sigma = zeros(1, size(X, 2));
for iter = 1:num_iters;
mu(1,iter) = mean(X_norm(:,iter));
X_norm(:,iter) = X_norm(:,iter) .- mu(1,iter);
sigma(1,iter) = std(X_norm(:,iter));
X_norm(:,iter) = X_norm(:,iter) ./ mu(1,iter);
end
When I run below octave code the command window displays :
>> first
x =
10
20
30
40
50
60
70
80
90
100
y =
14
17
18
14
15
14
13
12
11
4
m = 10
x =
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 90
1 100
-- less -- (f)orward, (b)ack, (q)uit
I'm required to continually press (f) to complete program and view plot : plot(x(:,2), x*theta, '-');
Octave code :
x = [10
20
30
40
50
60
70
80
90
100]
y = [14
17
18
14
15
14
13
12
11
4]
m = length(y)
x = [ones(m , 1) , x]
theta = zeros(2, 1);
iterations = 10;
alpha = 0.000007;
for iter = 1:iterations
theta = theta - ((1/m) * ((x * theta) - y)' * x)' * alpha;
#theta
end
#plot(x, y, 'o');
#ylabel('Response Time')
#xlabel('Time since 0')
plot(x(:,2), x*theta, '-');
How to prevent user interaction with command window so that program runs to completion and displays prompt and not requiring
user interaction ?
To prevent your variables from printing altogether, simply add a semicolon to the end of each variable assignment:
m = length(y) %// **will** print to the console
m = length(y); %// will *not* print to the console
To print your variables to the console, but avoid Octave pausing the output when it gets to the bottom of the screen, add more off to the beginning of your script to turn off paging.
https://www.gnu.org/software/octave/doc/interpreter/Paging-Screen-Output.html
Type more on to switch it back on.
Can anyone please help me convert number (for example) 143,625 to binary? I've been searching through net for quite a long time but didn't find anything with good explanation.
Thanks in advance!
The integer part can be done by dividing by 2 repeatedly and keeping track of the remainder:
143 / 2 = 71 remainder 1
71 / 2 = 35 remainder 1
35 / 2 = 17 remainder 1
17 / 2 = 8 remainder 1
8 / 2 = 4 remainder 0
4 / 2 = 2 remainder 0
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1
So the integer part is 10001111
For the fractional part, multiply it by 2 repeatedly and look at the integer part of the result:
.625 x 2 = 1.25 - we need the integer part, which is 1 - so far we have 0.1, we then disregard the 1 and look at 0.25
0.25 x 2 = 0.5 - so far we have 0.10, we look at 0.5
0.5 x 2 = 1.0 - we have 0.101, no decimal part so we're good.
The whole number is the integer part + the decimal part, so 10001111.101
I got an object (called tempEnemy) which is flying around and shooting.
The problem is that I can't keep the value tempEnemy.rotateTo positive, i.e.
it shall be between 0 and 359 degrees. Currently rotateTo ranges from:
rotateTo < 0 (bug) && rotateTo > 0 && rotateTo > 359 (bug).
tempEnemy.dX = tempEnemy.destX - tempEnemy.x;
tempEnemy.dY = tempEnemy.destY - tempEnemy.y;
//I added 180 because my tempEnemy object was looking and shooting to the wrong direction
tempEnemy.rotateTo = (toDegrees(getRadians(tempEnemy.dX, tempEnemy.dY))) + 180;
if (tempEnemy.rotateTo > tempEnemy.frame + 180) tempEnemy.rotateTo -= 360;
if (tempEnemy.rotateTo < tempEnemy.frame - 180) tempEnemy.rotateTo += 360;
tempEnemy.incFrame = int((tempEnemy.rotateTo - tempEnemy.frame) / tempEnemy.rotateSpeed);
You can always use the modulo operator (%) to keep a value positive. The module calculates the rest of a division.
E.g. (example works with integers there for a division always has a left over.)
19 % 5 = 4
Because in the number 19 5 only fits 3 times (3 * 5 = 15,, 4 * 5 = 20,, 20 is too high) the left over is 4 (19 - 15). That is the modulo.
Extra examples:
7 % 3 = 1
15 % 4 = 3
21 % 9 = 3
The output of a modulo operation is never higher then the right hand operator - 1 There for it is perfect for your problem.
If your object is rotated 1234 degrees,, then operate it with a modulo 360 to get the respective number between 0 and 360 for it.
1234 % 360 = 154
Other more easier examples:
720 % 360 = 0
360 % 360 = 0
540 % 360 = 180
-180 % 360 = 180
-720 % 360 = 0
-540 % 360 = 180
Sounds like a classic angle averaging issue. Here's a formula that works for averaging angles
private function averageNums($a:Number, $b:Number):Number {
return = (Math.atan2( Math.sin($a) + Math.sin($b) , Math.cos($a) + Math.cos($b) ));
}