Script

Filter
2004-07-21

Ökad säkerhet i Word

Office
Skicka inte med onödig information i dina word-dokument
För att se till så att ändringar eller personlig information inte sparas med i en wordfil:
1. Välj Alternativ > Verktyg fliken Spara
2. Ta bort bocken vid snabbspara
3. Byt flik till Säkerhet
4. Bocka för Ta bort personlig information
2004-07-08

Skapa eller installera paket - RPM

Linux
Skapa installera, Uppdatera eller ta bort paket med RPM
Installera:
$ rpm -ivh myapp-1.0-1.i586.rpm

Uppdatera:
$ rpm -Uvh myapp-1.0-1.i586.rpm

Fråga:
$ rpm -qa my*

Ta bort:
$ rpm -e myapp

För att bygga ett rpm-paket:
1. Samla allt i en tar-boll (inklusive man-page och Makefile)
Makefile kan se ut så här (beror på vilka filer som ingår):

all: myapp
# Which compiler
CC = gcc
# Where are include files kept
INCLUDE = .
# Options for development
CFLAGS = -g -Wall -ansi
# Options for release
# CFLAGS = -O -Wall -ansi
# Local Libraries
MYLIB = mylib.a
myapp: main.o $(MYLIB)
	$(CC) -o myapp main.o $(MYLIB)
$(MYLIB): $(MYLIB)(2.o) $(MYLIB)(3.o)
main.o: main.c a.h
2.o: 2.c a.h b.h
3.o: 3.c b.h c.h
clean:
	-rm main.o 2.o 3.o $(MYLIB)
dist: myapp-1.0.tar.gz
myapp-1.0.tar.gz: myapp myapp.1
	-rm -rf myapp-1.0
	mkdir myapp-1.0
	cp *.c *.h *.1 Makefile myapp-1.0
	tar zcvf $@ myapp-1.0
	-rm -rf myapp-1.0

Man-sidan (myapp.1) kan se ut så här:

.TH myapp 1
.SH NAME
myapp \- A simple demonstration application that does very little.
.SH SYNOPSIS
.B myapp
[\-option...]
.SH DESCRIPTION
.PP
\fImyapp\fP is a complete application that does nothing useful.
.br
It was written for demonstration purposes.
.SH OPTIONS
.PP
It doesn't have any, but let's pretend, to make this template complete.
.TP
.BI \-option
If there was an option, it would not be -option.
.SH RESOURCES
.PP
myapp uses almost no resources.
.SH DIAGNOSTICS
The program shouldn't output anything, so if you find it doing so there's probably something wrong. The return value is zero.
.SH SEE ALSO
The only program we know of with this little functionality is the hello world application.
.SH COPYRIGHT
Copyright (c) 2004 Rolf Fredriksson
.br
http://www.rosiro.net
.br
All rights reserved.
.SH BUGS
There probably are some, but we don know what they are yet.
.SH AUTHOR
Rolf Fredriksson


2. Kopiera tarbollen till /usr/src/RPM/SOURCE
3. Skapa en spec-fil (t ex myapp.spec), kan se ut så här:

#
# spec file for package myapp (Version 1.0)
#

Vendor:           Rosiro
Distribution:     Any
Name:	            myapp
Version:          1.0
Release:          1
Packager:         rolf.fredriksson@malmo.com
Copyright:        2004 by Rosiro
Group:            Applications/Media

Provides:         bliss
Requires:         mysql >= 3.23

Buildroot:        %{_tmppath}/%{name}-%{version}-root
Source:           %{name}-%{version}.tar.gz

Summary:          Demonstration application

%description
myapp Demonstration Application
A trivial application used to demonstrate development tools.
This version pretends it requires MySQL 3.23.
Authors: Rolf Fredriksson

%prep
%setup -q

%build
make

%install
mkdir -p $RPM_BUILD_ROOT%{_bindir}
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
install -m755 myapp $RPM_BUILD_ROOT%{_bindir}/myapp
install -m755 myapp.1 $RPM_BUILD_ROOT%{_mandir}/man1/myapp.1

%clean
rm -rf $RPM_BUILD_ROOT

#%post
#mail root -s "myapp installed - please register" </dev/null

%files
%{_bindir}/myapp
%{_mandir}/man1/myapp.1.bz2

5. Kör rpmbuild -ba myapp.spec
6. Hämta filerna från /usr/src/RPM/RPMS/i586 och
/usr/src/RPM/SRPMS
2004-07-07

Komprimering

Linux
Arkivera och / eller komprimera i Linux med gzip och tar
// Skippa gzip och gunzip - använd tar i stället! 

// Zippa en mapp:
tar zcvf mapp.tgz minMapp

// Flera filer kan läggas till, men det är bättre att lägga dem i en mapp (som ovan)...
tar zcvf minafiler.tgz fil1 fil2 fil3 mapp1

// Zippa upp en fil:
tar xzvf mapp.tgz
2004-07-05

Databasmotorer i MySql

Mysql
Kort förklaring...
Choose your engine
The number of database engines available to you depends on how your installation of MySQL was compiled.
To add a new engine, MySQL must be recompiled. The concept of compiling an application just to add a
feature may seem odd to Windows developers, but in the UNIX world, it's the norm. By default, MySQL
supports three database engines: ISAM, MyISAM, and HEAP. Two other types, InnoDB and Berkley (BDB),
are often available as well.

ISAM
ISAM is a well-defined, time-tested method of managing data tables, designed with the idea that a
database will be queried far more often than it will be updated. As a result, ISAM performs very
fast read operations and is very easy on memory and storage resources. The two main downsides of
ISAM are that it doesn't support transactions and isn't fault-tolerant: If your hard drive crashes,
the data files will not be recoverable. If you're using ISAM in a mission-critical application, you’ll
want to have a provision for constantly backing up all your live data, something MySQL supports through
its capable replication features.

MyISAM
MyISAM is MySQL's extended ISAM format and default database engine. In addition to providing a number
of indexing and field management functions not available in ISAM, MyISAM uses a table-locking mechanism
to optimize multiple simultaneous reads and writes. The trade-off is that you need to run
the OPTIMIZE TABLE command from time to time to recover space wasted by the update algorithms.
MyISAM also has a few useful extensions such as the MyISAMChk utility to repair database files
and the MyISAMPack utility for recovering wasted space.

MyISAM, with its emphasis on speedy read operations, is probably the major reason MySQL is so popular
for Web development, where the vast majority of the data operations you’ll be carrying out are read
operations. As a result, most hosting and Internet Presence Provider (IPP) companies will allow the
use of only the MyISAM format.

HEAP
HEAP allows for temporary tables that reside only in memory. Residing in memory makes HEAP faster than
ISAM or MyISAM, but the data it manages is volatile and will be lost if it's not saved prior to shutdown.
HEAP also doesn’t waste as much space when rows are deleted. HEAP tables are very useful in situations
where you might use a nested SELECT statement to select and manipulate data. Just remember to destroy
the table after you’re done with it. Let me repeat that: Don’t forget to destroy the table after you’re done with it.

InnoDB and Berkley DB
The InnoDB and Berkley DB (BDB) database engines are direct products of the technology that makes MySQL
so flexible, the MySQL++ API. Almost every challenge you're likely to face when using MySQL stems directly
from the fact that the ISAM and MyISAM database engines aren't transactional and lack foreign-key support.
Although much slower than the ISAM and MyISAM engines, InnoDB and BDB include the transactional and
foreign-key support missing from the former two choices. As such, if your design requires either or
both of these features, you’re actually compelled to use one of these two choices.

You can use the SHOW TABLE command (which is another MySQL extension to the ANSI standard) to determine
which engine is managing a particular table. SHOW TABLE returns a result set with multiple columns that
you can query to get all kinds of information: The name of the database engine is in the Type field.
The following sample code illustrates the use of SHOW TABLE:
 
SHOW TABLE STATUS FROM tblInnoDB

Flipping the switch
The switch that makes all this flexibility possible is an extension MySQL provides to ANSI SQL,
the TYPE parameter. MySQL allows you to specify database engines at the table level, so they are
sometimes referred to as table formats. The following sample code shows how to create tables that
use the MyISAM, ISAM, and HEAP engines, respectively. Notice that the code to create each table
is the same, with the exception of the trailing TYPE parameter, which specifies the database engine.
 
CREATE TABLE tblMyISAM (
       id INT NOT NULL AUTO_INCREMENT,
       PRIMARY KEY (id),
       value_a TINYINT
) TYPE=MyISAM
CREATE TABLE tblISAM (
       id INT NOT NULL AUTO_INCREMENT,
       PRIMARY KEY (id),
       value_a TINYINT
) TYPE=ISAM
CREATE TABLE tblHeap (
       id INT NOT NULL AUTO_INCREMENT,
       PRIMARY KEY (id),
       value_a TINYINT
) TYPE=Heap
 

You can also use the ALTER TABLE command to move an existing table from one engine to another.
The following code shows the use of ALTER TABLE to move a MyISAM table to InnoDB's engine:
 
ALTER TABLE tblMyISAM CHANGE TYPE=InnoDB
 
MySQL makes this happen with three steps. First, an exact copy of the table is created. Next,
any incoming data changes are queued, while the copy is moved to the other engine. Finally,
any queued data changes are committed to the new table, and the original one is deleted.

More choices means better performance
Considering the additional complications of recompiling and tracking which engines are used
for particular tables, why would you want to use any of the nondefault database engines?
The answer is simple: to tune the database to meet your needs.

Sure, MyISAM is fast, but if your logical design requires transactions, you’re free to use
one of the transaction-enabled engines. Further, since MySQL allows you to apply database
engines on the table level, you can take the performance hit on only the tables that require
transactions and leave the nontransactional tables to be managed by the more lightweight MyISAM engine.
With MySQL, flexibility is the key.

Sanders Kaufman, Jr.   April 7, 2003
2004-07-05

Administrera användare i MySql

Mysql
Några korta tips...
Kolla vilka användare:
Gå in i mysql i databasen mysql som mysqluser root och kolla vilka användare som finns med:
> select user, host, password from user;

1. Se till att det bara finns en användare: root@localhost till att börja med. Sätt ett lösenord också. Nu är databasen stängd.
> delete from user where user = '' and host = 'localhost';
> set password for root@localhost = password('nytt');

2. Lägg till användare efter behov. Man kan lägga till en anonym användare som ska ha rättigheter till alla publika databaser på webben:
> grant select, insert, update, delete on gastbok.* to iuser@localhost identified by 'password';

3. Ta bort rättigheter med:
> revoke all on forum.* from iuser@localhost;

4. Remote användare kan behövas...
> grant select on databas.* to iuser@'%.rosiro.net' identified by 'password';
Denna kod gör att alla på domänen kan komma in

Om du använder MySQLCC: Var vaksam på att uppdatera ändringarna. Ibland hänger inte den grafiska displayen med.

> flush privileges;
🙂